Search Unity

Access To ShadowMaps in custom Post Process shader (Built In Render Pipeline)

Discussion in 'Shaders' started by Feral_Pug, Jul 13, 2021.

  1. Feral_Pug

    Feral_Pug

    Joined:
    Sep 29, 2019
    Posts:
    49
    Does anyone know if you can sample the main directional light's shadow map INSTEAD of the screen space shadow map? From the AutoLight.cginc file it looks like if you have shadow cascades off and SHADOWS_SCREEN defined, calling unitySampleShadow with the transformed world position to shadow space should work. I am rebuilding the world position in the fragment shader using depth so I am not using unity's macros SHADOW_COORDS and TRANSFER_SHADOW but rather transforming the rebuilt worldPos into shadow space. Oddly enough defining UNITY_NO_SCREENSPACE_SHADOWS myself seemed to get it to sample the screenSpace shadows. Otherwise calling unitySampleShadow just returns 1. Advice greatly appreciated. I can post the code I am using if that would be helpful.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
  3. Feral_Pug

    Feral_Pug

    Joined:
    Sep 29, 2019
    Posts:
    49
    OK, this looks promising. Thanks for the link. I will post later if this works for my use or not.
     
  4. Feral_Pug

    Feral_Pug

    Joined:
    Sep 29, 2019
    Posts:
    49
  5. Saradora

    Saradora

    Joined:
    Jun 2, 2021
    Posts:
    2
    I've been doing something along those lines, but I keep getting issues when there are multiple lights in the scene, as soon as any spot light enters the camera frustum, the shader breaks because unity_WorldToShadow[0] returns the coordinates of the spot light instead of the directional light anymore..., is there anyway to get the coordinates of only the directional light?

    EDIT: managed to make it work, I rendered my shader using a commandbuffer on my directional light using LightEvent.Beforescreenmask, i tried using Aftershadowmap and still had the issue but before screen mask is actually working
     
    Last edited: Nov 6, 2022