Search Unity

Poor quality shadows on tiny objects

Discussion in 'General Graphics' started by Innovine, Feb 18, 2018.

  1. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    What can I do to improve the shadows in my game? I have a cockpit, with a lot of small detail up close to the camera, and a spotlight a few meters away. The shadows look dreadful, and they shimmer and flicker as the light/cockpit move around... I've changed the shadow quality to Very High but it doesn't seem to have improved things much...



    Above is a 5cm diameter tube in the cockpit., lit by a spotlight a few meters away.
    Below are some small buttons on the cockpit panel, lit by a point light about 50cm (half a unity unit) away.



    I tried scaling everything up by x10, and when I increased the range of the lights by x10 the result was identical.
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    The problem is the depth buffer resolution.
    If you have a gigant distance to cover you will have a poor resolution for small stuff.
    A good way to to fix it is to separate it into two different cameras, one for the cockpit and one for the rest of the world.
    Fist you draw the world camera (camera does not render the cockpit).
    Then the cockpit camera has a small draw distance and only renders the layer that the cockpit is on.
    Make sure to set the Cockpit camera to clear depth only.
     
    VS-Games likes this.
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    There are several assets (some free) which specialise in screen space shadows or contact shadows, these work with a directional light but have the resolution you require close up. These solutions work with Unity's existing shadows.

    If it will have to work with point and spot, I can suggest you bake the shadows for it or look into your cascade setup.
     
  4. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,619
    Some options that normally improve shadow quality are... reduce "Shadow Distance", enable "Shadow Cascades" and increase "Shadow Resolution".
     
    Hezekiel112 likes this.
  5. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    Yep, distance is minimal, cascades at 4. Where is the resolution option, is that the same as the Quality?
     
  6. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,619
    In Unity 2017.3 it can be found under "Edit > Project Settings > Quality Settings". The option is called "Shadow Resolution", next to all the other shadow related settings.

    PS: You can also tweak cascade ranges, to add more resolution to near shadows.
     
  7. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    But what sets the depth? Is it the camera far distance? I've tried setting the camera far distance and the shadow distance to 5, and there is no difference that I can see. I got rid of my VR camera rig. I have one standard camera, far distance set to 5, and my light is located 4 units away, and there's nothing else in the world apart from the cockpit, and the shadows are really dreadful :/

    https://i.imgur.com/gfX1XmY.gifv
     
    Last edited: Feb 19, 2018
  8. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Shadows for spot lights, directional lights, and point lights all work differently. In the quality settings you can clamp the max resolution, as well as set it on a per light basis.

    Point light shadows in Unity are of especially low quality. Even at high resolution they're going to not look great. Limiting the light's range to the smallest possible will help some, but the stair step effect is unavoidable.

    Spot lights will generally have slightly better shadows than point lights, but only so far. Just like point lights keeping the range to a minimum will help significantly, as will setting the near plane as high as possible. But, again, the stair step effect is unavoidable.

    Lastly is directional lights. The main directional light gets special treatment on desktop and consoles and will have the highest quality shadows of those built in to Unity. The camera's far plane or max shadow distance, along with the cascade ratios, allow for the highest possible shadow resolution as near and far objects get separate shadow maps. The other thing that will help is reducing the area that there are any shadow casting or receiving objects in the scene. Cascades will help with the shadow map's image resolution, but they can still have problems with depth resolution. The depth is determined by the range of objects in the scene that can receive and cast shadows.

    The short version is Unity's shadows are really bad at handling this specific use case. You might have better luck with something like the Next Gen Soft Shadows asset. Especially using the screen space raytraced contact shadows.
     
    Last edited: Feb 20, 2018
  9. Ysgramor

    Ysgramor

    Joined:
    Jan 23, 2014
    Posts:
    69
    try to reduce shadow cascade distance for first and second cascade (maybe 1 unit each) just experiment with it (when distance each cascade farther then the shadow resolution strecthed)
     
  10. radiowaves

    radiowaves

    Joined:
    Jan 20, 2017
    Posts:
    13
    I also have this problem. My game only has smaller objects (20cm maximum), camera is close. But shadow quality is just so poor. Nothing mentioned above helps.
     
  11. Roman_Keivan

    Roman_Keivan

    Joined:
    May 31, 2019
    Posts:
    22
    In Unity 2020.3 Go to > Project Setting > Quality > Shade Projection and Change to > Close Fit method upload_2021-7-19_23-17-1.png
     
    hyrumk and estani-berlin like this.