No, there’s no built-in way to access that. Part of the reason is that there can be more than one shadow map in the scene, so after scene is done, which one would you get?
So yeah, rendering it manually from light’s POV is the way to go.
I’m just posting this here , just in case someone stumbles across the same question! So I was also searching for a way to sample the screen space shadow texture with a commandbuffer and noticed, that they use this technique in the 3D GameKit from Unity! And it just seems to work straight out of the box this way! I saw many questions about this and nobody ever posted his working code, so here ya go!
Code that should be attached to the main directional light:
using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;
namespace Gamekit3D
{
[ExecuteInEditMode]
public class CopyShadowMap : MonoBehaviour
{
CommandBuffer cb = null;
void OnEnable()
{
var light = GetComponent<Light>();
if (light)
{
cb = new CommandBuffer();
cb.name = "CopyShadowMap";
cb.SetGlobalTexture("_DirectionalShadowMask", new RenderTargetIdentifier(BuiltinRenderTextureType.CurrentActive));
light.AddCommandBuffer(UnityEngine.Rendering.LightEvent.AfterScreenspaceMask, cb);
}
}
void OnDisable()
{
var light = GetComponent<Light>();
if (light)
{
light.RemoveCommandBuffer(UnityEngine.Rendering.LightEvent.AfterScreenspaceMask, cb);
}
}
}
}
Theres also this Macro written there, but I’m not sure for what it’s used: UNITY_DECLARE_SHADOWMAP(_DirectionalShadowMap);
(I just didnt used it and it still worked) UPDATE: Also thanks to @bgolus for clearing this up:
That’s for defining a shadow map texture object … which technically the screen space shadow texture is not so can be ignored. You’ve already defined it as a sampler2D, which is what it is.