- Home /
Can shaders access directional light shadow maps?
For point and spot lights, we can get access to the shadow map in shaders using the built-in variable _ShadowMapTexture
. However, for directional lights it appears the cascaded shadow map is already converted to a screen-space shadow mask by the time the shader sees it (based on a reading of AutoLight.cginc
).
Is there a way to get access to the actual shadow map, and the information (world-to-clip matrices etc.) about the cascades?
I'm working on porting a shader to Unity that uses the shadow map to estimate the thickness of an object, for a subsurface-scattering effect; so I need to be able to read raw depth values from the shadow map.
Answer by NReed · Feb 28, 2014 at 01:27 AM
After poking at this some more, I found that you can get access to the directional light shadow maps by writing a custom shadow collector pass. Looking at the definition of SHADOW_COLLECTOR_FRAGMENT
in UnityCG.cginc
, you can see the various parameters and textures that are available in this pass.
It may be possible (though I haven't tried, since I switched to a different approach for my original problem) to calculate some extra information in the shadow collector pass and store it in an unused channel of the screen-space shadow texture, or (in D3D11) perhaps store it in a random access texture, to be retrieved in the lighting pass.
Hey NReed how did you do this?
I'm trying to sample the shadow collector in post. UnityCG.cginc defines the macro SA$$anonymous$$PLE_SHADOW_COLLECTOR_SHADOW but when I use it in my shader I get
undefined variable "SA$$anonymous$$PLE_SHADOW_COLLECTOR_SHADOW"
Your answer
Follow this Question
Related Questions
Realtime Shadow Glitch [Unity Indie: Directional Light] 2 Answers
Shadow Support in Custom Shader 0 Answers
Edge outline & 2D shadow Shader for planar mesh 0 Answers
How to make shader outline without inner shadow? 0 Answers
Make this shader receive and cast shadow? Can anyone help me thanks! 0 Answers