Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Raymarching with unity shadow map, duplicate shadow on multiple surfaces

Discussion in 'Shaders' started by b1gry4n, Sep 30, 2020.

  1. b1gry4n

    b1gry4n

    Joined:
    Sep 11, 2013
    Posts:
    146
    I am using the following to utilize unity shadow map inside of a raymarching shader in hopes of improved performance over raymarched shadows :

    Code (CSharp):
    1. float shadow(float3 wpos)
    2. {
    3. float4 shadowCoord = TransformWorldToShadowCoord(wpos);
    4. float atten = MainLightRealtimeShadow(shadowCoord);
    5. return atten;
    6. }
    I have this working, but because the raymarching isnt calculated in the shadow map I am getting a duplicate shadow across 2 distant surfaces. I understand why this is happening, but I am curious if theres a way to solve this without having to raymarch shadows and perform more calculations. Anyone have any ideas?



     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    I mean, you're getting the "double shadow" because the area on the right should be in self shadow from the volumetric effect itself. There's not really any fix to this apart from having the clouds cast shadows, which means having them render in the shadow map.

    One thing you could do is the shadow map's volumetric effect doesn't need to be anywhere near as accurate as what you're rendering normally. I'd do a version that uses far larger steps, and with a large amount of noise (animated & blue) in the initial ray offset. Depending on how your volume data is setup, you might want to use a slightly "lower density" for your volume so it's slightly shrunk while doing the tracing. That should give you shadows from the main bulk of the volume, and the noise & large step size will give you something akin to translucency.