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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Weird shadows in Universal Render Pipeline

Discussion in 'Universal Render Pipeline' started by Sebik_, Feb 26, 2023.

  1. Sebik_

    Sebik_

    Joined:
    Oct 29, 2020
    Posts:
    2
    I am using Unity 2021.3.9f1 and URP 12.1.7 and I am getting weird shadows with hard edges and spikes even though I have soft shadows enabled. There is only Realtime Lighting in my scene. I am using Toon Shaders, but the same thing happens with default URP Lit materials. Reducing the max shadow distance seem to make the spikes a little smaller, but not go away. It looks even weirder with hard shadows. I have the same problem in different scenes and lighting settings too. You might not be able to see it as clear in the Video due to YouTube compression.



    upload_2023-2-26_19-33-42.png
     
  2. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,519
    It's because your light is moving or rotating. This means that the shadow map is having to be constantly re-aligned, resulting in the artifacts that you're seeing.

    Rather than continuous, tiny movement every frame, this kind of thing can be made less noticable by updating your light position at periodic intervals. As this is presumably your sun the movement from one frame to the next hopefully isn't noticable, so skipping a bunch shouldn't be an issue. I've not tried it, but in theory you could even figure out the period where the "spikes" would line up, and use that as your update interval to lose the sideways sawtooth effect.

    And yes, I've played big budget games where I've been able to stand still and notice that the sun shadow is taking small steps every few moments rather than continually updating. You could try customising the shadow filtering to make it even less noticable after that.
     
    Sebik_ likes this.
  3. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,337
    Those are shadowmap artifacts. You can't really get rid of those completely.

    Shadowmap projector renders the scene onto a grid, and uses that grid to check which pixels are shadowed. Because the grid has finite resolution, at some point jagged artifacts like that could appear.

    In the past, another technique was quite popular - Shadow Volumes. They were used in Doom 3. They're no longer being used today. That technique wouldn't produce jagged shadow, but would flicker if the shadow is almost parallel to the wl, plus you couldn't blur shadow volume shadows.
     
    Sebik_ likes this.
  4. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    959
    As others have pointed out - it's a limitation of the shadow map method. Other engines using shadow maps have the same problem.

    Unreal Engine 5 offers a different shadow method which they call virtual shadow maps. I don't know if it would help with your scenario but it might be worth investigating.

    Speaking of shadow volumes - there is an asset on the asset store if you're interested.
    https://assetstore.unity.com/packages/vfx/shaders/sharp-shadows-toolkit-152791

    I haven't tried it but might be a good match for your project.

    Do note that shadow volumes are more expensive due to having to draw a lot of more fragments into stencil buffer.
     
    Sebik_ likes this.
  5. Sebik_

    Sebik_

    Joined:
    Oct 29, 2020
    Posts:
    2
    Thanks for the great replies. I'll look into it again as soon as possible. This problem is completely new to me and I hadn't had it in any of my projects before.
     
    SunnySunshine likes this.
  6. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    9,801
    You can't "turn off" shadows in URP being ugly. This has been a known problem with it since it first came out.
     
    MadeFromPolygons likes this.