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:
    278
    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:
    2,797
    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.
     
  3. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,442
    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

    Joined:
    Jun 12, 2013
    Posts:
    4,004
    Some options that normally improve shadow quality are... reduce "Shadow Distance", enable "Shadow Cascades" and increase "Shadow Resolution".
     
  5. Innovine

    Innovine

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

    Peter77

    Joined:
    Jun 12, 2013
    Posts:
    4,004
    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:
    278
    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:
    7,115
    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
    cecarlsen and KarolisO like this.
  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)