From bdbec0916d058b6356a1bf54021dfbf6021dc16a Mon Sep 17 00:00:00 2001 From: yum Date: Tue, 24 Feb 2026 23:05:10 -0800 Subject: Add shadows --- lighting.cginc | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'lighting.cginc') diff --git a/lighting.cginc b/lighting.cginc index 51b0c8f..04cff3c 100755 --- a/lighting.cginc +++ b/lighting.cginc @@ -183,14 +183,14 @@ float3 yumSH9(float4 n, float3 worldPos, inout LightIndirect light) { return L0 + L1 + L2; } -float4 getIndirectDiffuse(v2f i, Pbr pbr, inout LightIndirect light) { +float4 getIndirectDiffuse(v2f i, Pbr pbr, inout LightData light) { float4 diffuse = 0; #if defined(FORWARD_BASE_PASS) || defined(OUTLINES_PASS) #if defined(_BENT_NORMALS) - diffuse.xyz += max(0, yumSH9(float4(pbr.bent_normal, 1.0), i.worldPos, light)); + diffuse.xyz += max(0, yumSH9(float4(pbr.bent_normal, 1.0), i.worldPos, light.indirect)); #else - diffuse.xyz += max(0, yumSH9(float4(i.normal, 1.0), i.worldPos, light)); + diffuse.xyz += max(0, yumSH9(float4(i.normal, 1.0), i.worldPos, light.indirect)); #endif #endif @@ -200,6 +200,30 @@ float4 getIndirectDiffuse(v2f i, Pbr pbr, inout LightIndirect light) { diffuse.xyz = HSVtoRGB(diffuse_hsv); #endif +#if defined(_SHADOWS) + //diffuse.xyz = lerp(diffuse.xyz, _Shadow_0_Color.rgb, _Shadow_0_Threshold); + float3x3 mat = float3x3( + light.indirect.L01r, + light.indirect.L01g, + light.indirect.L01b + ); + float3 dom_dir = normalize(mul(mat, diffuse.xyz)); + float light_amount = dot(dom_dir, pbr.normal); + float3 shadow_color = lerp( + _Shadow_0_Color.rgb, + 1, + smoothstep(_Shadow_0_Threshold - _Shadow_0_Blur, _Shadow_0_Threshold + _Shadow_0_Blur, light_amount)); + +#if defined(_SHADOW_1) + shadow_color = lerp( + _Shadow_1_Color.rgb, + shadow_color, + smoothstep(_Shadow_1_Threshold - _Shadow_1_Blur, _Shadow_1_Threshold + _Shadow_1_Blur, light_amount)); +#endif // _SHADOW_1 + + diffuse.xyz *= shadow_color; +#endif + #if defined(_AMBIENT_OCCLUSION) diffuse.xyz *= pbr.ao; #endif @@ -291,7 +315,7 @@ void GetLighting(v2f i, Pbr pbr, out LightData data) { data.indirect.LoV = saturate(indirect_LoV); data.indirect.double_LoV = saturate(2.0f * indirect_LoV * indirect_LoV - 1.0f); - data.indirect.diffuse = getIndirectDiffuse(i, pbr, data.indirect); + data.indirect.diffuse = getIndirectDiffuse(i, pbr, data); data.indirect.specular = getIndirectSpecular(i, pbr.roughness_perceptual, view_dir, -data.indirect.dir); data.common.spec_ao = getSpecularAO(i, pbr, data, reflect_dir); -- cgit v1.2.3