HOW shadowmap work

I want to know how did ZED unity SDK capture the shadowmap texture to ZED_Forward_Lighting.shader,so I reference the ZEDRenderingPlane.cs,and found those in line 1134:
if (light.commandBufferCount == 0)
CommandBuffer lightBuffer = new CommandBuffer(); = “ZED_Copy_ShadowMap”;
lightBuffer.SetGlobalTexture("_DirectionalShadowMap", BuiltinRenderTextureType.CurrentActive);

                            light.AddCommandBuffer(LightEvent.AfterScreenspaceMask, lightBuffer);

and the question is how does these code work ,is there anybody can explain for me?


This piece of code :

CommandBuffer lightBuffer = new CommandBuffer(); = “ZED_Copy_ShadowMap”;lightBuffer.SetGlobalTexture("_DirectionalShadowMap", BuiltinRenderTextureType.CurrentActive);

is creating a CommandBuffer that will set the GlobalTexture called “_DirectionalShadowMap” with the current render texture (current = when it’s executed).


light.AddCommandBuffer(LightEvent.AfterScreenspaceMask, lightBuffer); }

with that line, you plan the CommandBuffer you just created to execute right at the LightEvent “AfterScreenspaceMask” which generates the shadows of the Directional lights.
As it is said in the documentation ( :
This light event will execute command buffers when the screenspace mask is computed, and the active render target is still the screenspace mask.

Which means, at this point in time, the current render texture (BuiltinRenderTextureType.CurrentActive) is the shadow map we want.
And then, this texture is used in the shader to compute the shadows from the directional lights.

I hope I answered your question.

Best regards,
Benjamin Vallon

Stereolabs Support