From a5ac8d1093e0d54b7e2563eb3ea120e0e792481f Mon Sep 17 00:00:00 2001 From: yum Date: Tue, 24 Mar 2026 19:14:44 -0700 Subject: Try to avoid NaN in dominant direction calculation --- ssfd.cginc | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'ssfd.cginc') diff --git a/ssfd.cginc b/ssfd.cginc index cc7d304..5d385c6 100644 --- a/ssfd.cginc +++ b/ssfd.cginc @@ -54,5 +54,17 @@ float ssfd(float2 uv, float scale, float max_fwidth, float2 uv_offset, texture3D } #endif // _SSFD +void apply_ssfd(v2f i, float2 uv, LightData l, float3 normal, inout float3 albedo) { +#if defined(_SSFD) + float ssfd_mask = ssfd(uv, _SSFD_Scale, _SSFD_Max_Fwidth, 0, _SSFD_Noise); + float ssfd_mask_fw = fwidth(ssfd_mask); + // TODO I think anti aliasing is probably broken + float light_amount = 1.0 - (dot(l.indirect.diffuse_dominant_dir, normal) * 0.5 + 0.5); + float ssfd_threshold = saturate(light_amount + _SSFD_Threshold); + ssfd_mask = smoothstep(ssfd_threshold - ssfd_mask_fw * 0.5, ssfd_threshold + ssfd_mask_fw * 0.5, ssfd_mask); + albedo += ssfd_mask * _SSFD_Tint.rgb; +#endif +} + #endif // __SSFD_INC -- cgit v1.2.3