Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

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:
    47
    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:
    11,833
  3. Feral_Pug

    Feral_Pug

    Joined:
    Sep 29, 2019
    Posts:
    47
    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:
    47
  5. Saradora

    Saradora

    Joined:
    Jun 2, 2021
    Posts:
    1
    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