Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted 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:
    110
    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:
    9,385
    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.
     
unityunity