Follow

How can I remove the fade out on the shadows?

Symptoms

  • Unity does not offer a public API to remove the fade out on the shadows.

Cause

The public API does not offer any method for removing the fade out on the shadows, however with C# and our built-in shaders it is possible to overwrite the shadows fade out.

Resolution

Try adding following script onto your camera:

void OnPreRender ()
{
    originalScreenSpaceShadowShader = GraphicsSettings.GetCustomShader(UnityEngine.Rendering.BuiltinShaderType.ScreenSpaceShadows);
    GraphicsSettings.SetCustomShader(UnityEngine.Rendering.BuiltinShaderType.ScreenSpaceShadows, myScreenSpaceShadowShader);
}

void OnPostRender()
{ 
GraphicsSettings.SetCustomShader(UnityEngine.Rendering.BuiltinShaderType.ScreenSpaceShadows, originalScreenSpaceShadowShader); }

Regarding the screenspace shadow shader itself (Internal-ScreenSpaceShadows.shader), comment this line:

shadow += GET_SHADOW_FADE(wpos, vpos.z);

Please note that there are a few more actions to take after the above. For example: in deferred, the directional light attenuates by itself at shadow distance. In forward, at shadow distance, everything turns black. You need to have this functionality in mind before doing these changes.

Another option could be to increase the camera distance, and the fade out will appear in a far away distance from the view.

More Information 

Additional information can be found here

This article applies to Unity version 5.4

Was this article helpful?
1 out of 1 found this helpful
Have more questions? Submit a request

2 Comments

  • 1
    Avatar
    Ptarp

    This is awesome, thanks for adding this ability.  It seems to work great in my limited testing. That shadow seam (two cameras) has bugged us for years!

    Edited by Ptarp
  • 0
    Avatar
    Michael Cossu

    Hi. As expected, it doesnt seem to work anymore on Unity 5.6. (Yea I know it's for 5.4)
    I tried both new and old built-in shaders, the old is just broken with 5.6 and the new doesnt handle shadow fade-out itself.

    It tried to cut like 99% of the code of the new shader and I can guarantee you that the shadow isnt affected by this shader .. It handles things like shadow position on screen and shadows cascades blending.

    I dont know where I should look at if I want this to be fixed, since it's really hard to find topics about this very precise issue.

    Edited by Michael Cossu
Please sign in to leave a comment.