Search Unity

Question Using directional light depth maps inside a custom shader.

Discussion in 'General Graphics' started by Cactus_on_Fire, Aug 13, 2022.

  1. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Hello.

    Is there a way to access the depth map that directional lights create for the shadows and transform them to the scene depth accordingly? They look like this in the frame debugger.

    upload_2022-8-13_15-55-52.png
     
  2. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    666
    Not sure what you mean with "transform them to the scene depth accordingly".

    Don't know if it is possible but here are some thoughts:
    - You can look at Internal-ScreenSpaceShadows to see how to evaluate the cascaded shadow map
    - There is a shader property called "_ShadowMapTexture", but Unity probably sets it to whatever shadow map is currently used in the light pass. It might be difficult to get hold of it. You can use tricks like making a copy of it in the right render pass, but even that might not be doable.
    - Forward shaders just evaluate the screen-space shadows for directional lights but this only works for opaque. I couldn't find out how this works for transparent objects from a quick look at it. You could make a copy of the shader, add #pragma enable d3d11_debug_symbols and step through the shader in RenderDoc to see how it works.
    - Have you checked the forums? Wouldn't be surprised if somebody has asked this before.
     
  3. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Hey, thanks for the reply.

    What I meant is that I would need access to those depthmaps created by the directional lights as well as their position/rotation transform data so that I could use them to fake shadows. But it seems to be exceeding the capabilities of the shader as it needs additional scripts to call the shadowmaps. I just went with the solution where I made a custom depthmap that copies the transform of the directional lights.