wip: enki shader

This commit is contained in:
Alexandre Coirier
2026-05-25 08:55:53 +02:00
parent 30c292772b
commit 8e74190866
@@ -153,6 +153,74 @@ float WorldStripes()
return 0;
}
float WorldDistort(float3 PositionWS, float3 NormalWS, float Angle, float TriplanarBlend)
{
float StripesScale = 60;
// Octahedral face normals (4 faces + 3 world axes)
float3 octaFaceNormals[7] =
{
normalize(float3(1, 1, 1)),
normalize(float3(-1, 1, 1)),
normalize(float3(1, -1, 1)),
normalize(float3(-1, -1, 1)),
float3(1, 0, 0),
float3(0, 1, 0),
float3(0, 0, 1)
};
// Octahedral blending mask
float sharpness = Remap(0, 1, 1, 16, smoothstep(0, .9, TriplanarBlend));
float octaMask[7];
float hardMax = -1;
int hardIdx = 0;
for (int i = 0; i < 7; i++)
{
float d = abs(dot(NormalWS, octaFaceNormals[i]));
octaMask[i] = pow(saturate(d), sharpness);
if (d > hardMax)
{
hardMax = d;
hardIdx = i;
}
}
float maskSum = 0;
for (int i = 0; i < 7; i++)
maskSum += octaMask[i];
for (int i = 0; i < 7; i++)
octaMask[i] /= max(maskSum, 0.0001);
float hardFactor = smoothstep(.9, 1, TriplanarBlend);
for (int i = 0; i < 7; i++)
{
float hard = (i == hardIdx) ? 1.0 : 0.0;
octaMask[i] = lerp(octaMask[i], hard, hardFactor);
}
// Patern
float stripes = 0;
[unroll]
for (int i = 0; i < 7; i++)
{
float3 n = octaFaceNormals[i];
float3 up = abs(n.y) < 0.999 ? float3(0, 1, 0) : float3(1, 0, 0);
float3 tangent = normalize(cross(up, n));
float3 bitangent = normalize(cross(n, tangent));
float angle = i / 7.0 * PI;
float2 p = RotateUV(float2(dot(PositionWS, tangent), dot(PositionWS, bitangent)), 0, angle) * StripesScale;
float stripe = cos(p.x);
stripes += stripe * octaMask[i];
}
return stripes;
}
float ProjectionMask(
float3 PositionWS,
float3 CamPositionWS,
@@ -254,12 +322,7 @@ void EnkiBillal_float
float3 mainLightDir = normalize(float3(1, -1, 1)); //normalize(float3(0, 13, 8) - PositionWS); //float3(0, -1, 0);//normalize(mainLight.direction);
float lightGradient = dot(normalize(NormalWS), normalize(mainLightDir));
lightGradient = smoothstep(-.5, 1, lightGradient);
float ao = GetScreenSpaceAmbientOcclusion(ScreenUV).directAmbientOcclusion;
// Triplanar
//float3 triplanarMask = TriplanarMask(NormalWS, TriplanarBlend);
//float ao = GetScreenSpaceAmbientOcclusion(ScreenUV).directAmbientOcclusion;
// Shadow
@@ -268,7 +331,7 @@ void EnkiBillal_float
// Grain
float grain = ValueNoise3DLOD(PositionWS, scaledPositionOS, 600, 3.5);
/*float grain = ValueNoise3DLOD(PositionWS, scaledPositionOS, 600, 3.5);
float grainMin = lerp(.4, .8, shadowMask);
float grainAtten = Remap(0, 1, grainMin, 1, grain);
@@ -276,7 +339,7 @@ void EnkiBillal_float
float dirt = FBMNoise3D(scaledPositionOS, 1, 3, 2, .5);
float dirtMin = lerp(.2, .7, shadowMask);
float dirtAtten = Remap(0, 1, dirtMin, 1, dirt);
float dirtAtten = Remap(0, 1, dirtMin, 1, dirt);*/
// Stripes
@@ -326,15 +389,30 @@ void EnkiBillal_float
//float test = FBMNoise3D(PositionWS, 10, 2, 2, .5);
//float test = RidgedNoise3D(PositionWS, 10, 2, 2, .5);
float3 pWS = scaledPositionOS;
float n0 = PerlinNoise3D(pWS, 2);
float distort = WorldDistort(pWS + n0 * .2, NormalWS, 1, TriplanarBlend);
float3 p = pWS + n0 * 2 + distort * smoothstep(.5, .7, n0) * .06;
float grad = 0;
float cell = 0;
VoronoiNoise3D_float(p, 2, 1, 1, grad, cell);
float3 v = cell * .8;// * (grad + distort * .1);
v += smoothstep(.05, .02, grad) * smoothstep(.4, .7, n0) * 2;
float3 c = Color * lerp(.9, 1, v);
// Output
Output = 1;
if (Step > 0 ) Output *= Color;
if (Step > 1 ) Output *= grainAtten;
if (Step > 2 ) Output *= dirtAtten;
if (Step > 3 ) Output *= shadowAtten;
//Output = 1;
//if (Step > 0 ) Output *= Color;
//if (Step > 1 ) Output *= grainAtten;
//if (Step > 2 ) Output *= dirtAtten;
//if (Step > 3 ) Output *= shadowAtten;
//if (Step > 4 ) Output = lerp(Output, Output * .1, stripes * .8);
Output = c;
//Output = PerlinColor3D(PositionWS, 5);
//Output = smoothstep(.97, .93, ao);
}