summaryrefslogtreecommitdiffstats
path: root/tooner_lighting.cginc
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2025-02-02 16:20:12 -0800
committeryum <yum.food.vr@gmail.com>2025-02-02 16:20:17 -0800
commit5f819329a161d54076d025d6f61656f262094c07 (patch)
treeacba27050736f2296206fb0dc52f4cd2e9bb29bb /tooner_lighting.cginc
parent03406b0983e123bb3203a96bfd2f017e58e3e90d (diff)
Finish reproducing SSFD tech
Fix gen_sdf so it normalizes all SDFs
Diffstat (limited to 'tooner_lighting.cginc')
-rw-r--r--tooner_lighting.cginc14
1 files changed, 11 insertions, 3 deletions
diff --git a/tooner_lighting.cginc b/tooner_lighting.cginc
index b1bbab0..fde3339 100644
--- a/tooner_lighting.cginc
+++ b/tooner_lighting.cginc
@@ -1004,6 +1004,7 @@ float ssfd(float2 uv, float scale, float max_fwidth, texture3D noise)
// largest amount of stretching, so we use it to determine when to
// subdivide.
float duv_fw = singular_values.y;
+ duv_fw *= scale;
// Suppose Max_Fwidth is 1.
// duv_fw is 16. That means UV is changing a lot per pixel. That means we want to shrink the scale of the UV.
@@ -1016,7 +1017,6 @@ float ssfd(float2 uv, float scale, float max_fwidth, texture3D noise)
float fractal_remainder = fractal_level - fractal_level_floor;
duv /= pow(2, fractal_level_floor);
- duv *= scale;
#if 1
// Four layers -> coarsest at 0.125, finest at 0.875.
@@ -1122,8 +1122,16 @@ float4 effect(inout v2f i, out float depth)
#endif // _FRAME_COUNTER
#if defined(_SURFACE_STABLE_FRACTAL_DITHERING)
- float ssfd_raw = ssfd(i.uv0, _Surface_Stable_Fractal_Dithering_Scale, _Surface_Stable_Fractal_Dithering_Max_Fwidth, _Surface_Stable_Fractal_Dithering_Noise);
- albedo.rgb = ssfd_raw > 0.5 ? 1 : 0;
+ {
+ float3 light_dir = getDirectLightDirection(i);
+ float3 light_color = getDirectLightColor();
+ float shadow_attenuation = getShadowAttenuation(i);
+ float ndotl = saturate(dot(i.normal, light_dir) * shadow_attenuation);
+ float light_intensity = ndotl * length(light_color);
+ float ssfd_raw = ssfd(i.uv0, _Surface_Stable_Fractal_Dithering_Scale / light_intensity, _Surface_Stable_Fractal_Dithering_Max_Fwidth, _Surface_Stable_Fractal_Dithering_Noise);
+ float ssfd_cutoff = _Surface_Stable_Fractal_Dithering_Cutoff;
+ albedo.rgb = lerp(0, 1, ssfd_raw > 1 - light_intensity);
+ }
#endif
#if defined(_GIMMICK_GERSTNER_WATER)