Search Unity

Shadow Fadeoff approaching far clip plane

Discussion in 'General Graphics' started by HarvesteR, Sep 23, 2015.

  1. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    262
    Yes I was restarting Unity and even the laptop after the changes but nothing worked.
    Finally we changed the shaders from Diffuse to Vertex and this problem disappeared.
    Now we are trying either code the Diffuse shader to behave with shadows like the vertex one
    or code the Vertex one to look like the diffuse since the appearance is different.
    I can't understand how so many people read this post and nobody knew shaders were part of the problem. :confused:
     
  2. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    262
    anybody ? still fighting with this :(
     
  3. m3ndi3

    m3ndi3

    Joined:
    Mar 6, 2012
    Posts:
    18
    I am on 2019.2 and I was having this problem of shadows weirdly clipping when I rotated or zoomed in or out on my camera. I tried everything from increasing the shadow distance, to removing cascading, to trying to bake shadows. The problem really looked like a camera problem because it was reacting to some sort of invisible clipping plane I couldn't control. My coworker found a fix that was stupidly simple and maybe it will help you guys like it helped me. In your camera there is a setting for "Gate Fit". Mine was set to Horizontal, and when I changed it to Vertical, my shadow clipping problem was fixed!
    upload_2020-1-28_14-31-47.png
     
  4. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    262
    Actually we made it work editing the UnityShadowLibrary.cginc file, the problem In my case was I was not editing the correct file, since Im using unity hub there are different folders for different versions and I was not editing the one in use.
    Anyway, thanks for the info
     
  5. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,751
    Recently had this issue, after following up the include files, i found out the fade calculation is done inside UnityGI_Base function inside UnityGlobalIllumination.cginc file.

    In this function there is this check:

    Code (CSharp):
    1.     #if defined(HANDLE_SHADOWS_BLENDING_IN_GI)
    2.         half bakedAtten = UnitySampleBakedOcclusion(data.lightmapUV.xy, data.worldPos);
    3.         float zDist = dot(_WorldSpaceCameraPos - data.worldPos, UNITY_MATRIX_V[2].xyz);
    4.         float fadeDist = UnityComputeShadowFadeDistance(data.worldPos, zDist);
    5.         data.atten = UnityMixRealtimeAndBakedShadows(data.atten, bakedAtten, UnityComputeShadowFade(fadeDist));
    6.     #endif
    So, theorically, you should edit the lighting functions globalillumination functions. But practically, you should have your own lighting function(not to break the cginc files) and before calculating the gi, you should add this line:
    #undef HANDLE_SHADOWS_BLENDING_IN_GI

    Again theorically, this will get the data.atten unedited. And you will have other insignificant misbehaviour with lighting.

    In order to make this work per camera, You should have 2 variations, and switch them between camera renders.

    This is what i use with my TOZ Planet Renderer to render vast distances.

    Hope this helps.
     
unityunity