When camera distance is far enough so that all of the scene fall outside of the shadow cascades, does Unity automatically disable shadow caster pass and collect shadow pass?
When that happens, why is a grey UnityDefault2D texture is set on _ShadowMapTexture, instead of white?
On the shader way, can we tell when this happens, so that we avoid sampling _ShadowMapTexture (like a #define keyword)?
Or can we ask Unity to use a white texture as default instead (note that _ShadowMapTexture is not be per-shader property, and should be global)?
I am porting a shader library that’s why I am asking.
If its bounds are outside of the shadow cascade frustums, then yes, its shadow caster pass will be culled from the cascaded shadow map. Unity doesn’t have a “collect shadow pass”, that’s a legacy Unity 4.0 thing (though it’s sort of back in the SRPs). Instead Unity reuses the shadow caster pass to render into the _CameraDepthTexture. If an object is opaque and has a shadow caster pass, it’ll be rendered into the depth texture regardless of if it’s in range to be shadowed, or even if it has shadow receiving turned off, since the _CameraDepthTexture is more than just the shadow receiver.
My guess? Because someone set it to that while testing and it never got set back since it’s never seen when things are working correctly.
The SHADOWS_SCREEN keyword is part of the #pragma multi_compile_fwdbase and is only on when screen space shadows are. It should be disabled when outside of the cascaded shadow range.
@bgolus one more question: how does shader on mobile know that shadow cascade is not supported?
Somehow my shadow rendering is wrong only on android, and I notice the shadow cascade is not supported on mobile. I think either I can’t use shadow coordinate from ComputeScreenPos, or I need to sample the _ShadowMapTexture differently. I have trouble figuring out which one…
I know it has to do with UNITY_NO_SCREENSPACE_SHADOWS but just looking at AutoLight.cginc, I don’t see where I have done wrong in vertex or frag step…
I think my problem comes down to this: the _ShadowMapTexture is screen-space on PC, but is light-space on Android. I don’t know how that actually speed up rendering on Android.
To be honest, I hope there is a solution to force _ShadowMapTexture to screen-space for Android platform, is there a way?
Otherwise we have to port the same code from Internal-ScreenSpaceShadows to the library to match PC shadow, it’s quite annoying!
I have fixed it, so yeah we need to pass the shadow coordinate for light-space, and use both SHADOWS_SCREEN and UNITY_NO_SCREENSPACE_SHADOWS to distinguish PC/Console from Android.