Search Unity

Gap in shadow

Discussion in 'General Graphics' started by compyler, Feb 24, 2021.

  1. compyler

    compyler

    Joined:
    Mar 30, 2020
    Posts:
    102
    Hello!

    I have an artifact with my realtime hard shadows that I can't explain. Here is a screenshot:

    I have one mesh with 2 water pools (basically just 2 rectangles extruded into the ground). On the left side of the scene I have a directional light with hard shadows.
    As you can see the shadow of the right pool looks fine. But the shadow on the left pool has a gap on the left side. When I rotate the directional light slightly (to look more downwards), the gap disappears.

    I want to understand this bug. Can anyone explain me why there is this gap in the shadow? And is there any other fix than changing the light direction?
     
  2. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    Not 100% sure, but it could be connected to the bias set in your light source. Play around with Depth and normal bias:
    upload_2021-2-25_8-49-16.png
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Look at the scene from the direction the light is facing. My guess is you can see the bottom of the pool from that angle due to not having any geometry beyond that wall in the background. If you can see it, so too can the light.

    Unity's shadows by default only use the front faces of objects. You can try turning on double sided shadows on the ground's mesh renderer component, but there'll still be a small gap between the pool wall and the pool floor due to biasing (what @Johannski was getting at). So it's better to have a bit more geometry than you "need", i.e.: make sure everything is capped, for shadows. You can also use a mesh renderer set to Shadows Only if you don't want to have anything visible to the camera beyond the wall.
     
    Bovine likes this.
  4. compyler

    compyler

    Joined:
    Mar 30, 2020
    Posts:
    102
    @Johannski I tried to play around with the shadow settings, but could not solve the problem

    @bgolus Damn, your description was on point! Indeed that was the problem! I fixed it by adding another quad point in the other direction. Thanks!