I need to modify Deferred shading algorithms - UnityDeferredLibrary.cginc, basically I want to add screen space shadow texture to it.
The problem is it generates from the directional light, so
#if defined (SPOT)
float3 tolight = _LightPos.xyz - wpos;
half3 lightDir = normalize (tolight);
float4 uvCookie = mul (unity_WorldToLight, float4(wpos,1));
// negative bias because http://aras-p.info/blog/2010/01/07/screenspace-vs-mip-mapping/
float atten = tex2Dbias (_LightTexture0, float4(uvCookie.xy / uvCookie.w, 0, -8)).w;
atten *= uvCookie.w < 0;
float att = dot(tolight, tolight) * _LightPos.w;
atten *= tex2D (_LightTextureB0, att.rr).r;
atten *= UnityDeferredComputeShadow (wpos, fadeDist, uv);
// directional light case
#elif defined (DIRECTIONAL) || defined (DIRECTIONAL_COOKIE)
half3 lightDir = -_LightDir.xyz;
float atten = 1.0;
atten *= UnityDeferredComputeShadow (wpos, fadeDist, uv);
atten = NGSS_FRUSTUM_SHADOWS_ENABLED > 0.0 ? min(atten, saturate(tex2D(NGSS_FrustumShadowsTexture, uv).r + NGSS_FRUSTUM_SHADOWS_OPACITY)) : atten;
So the problem is it applies to all directional Lights in deferred shading. SO If I have 2 DLs - it applies on top of both.
In Forward shading I usually mask it with Keyword UNITY_PASS_FORWARDADD which the second Dir Light belongs.
But It’s cannot be used in deferred shading looks like. I’m doing it in the wrong place? Where to put the shadow texture to mask only Main Directional Light?