summaryrefslogtreecommitdiffstats
path: root/lighting.cginc
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2026-02-24 23:05:10 -0800
committeryum <yum.food.vr@gmail.com>2026-02-24 23:05:10 -0800
commitbdbec0916d058b6356a1bf54021dfbf6021dc16a (patch)
tree263576a8a62f544392cd9114ff610c365c6d3c6d /lighting.cginc
parent80d511162ca90e29fd26c9a5893cde7aa9c23332 (diff)
Add shadows
Diffstat (limited to 'lighting.cginc')
-rwxr-xr-xlighting.cginc32
1 files changed, 28 insertions, 4 deletions
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);