Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Shadows "Peter Panning"

Discussion in 'Global Illumination' started by Nosada, Jul 14, 2019.

Thread Status:
Not open for further replies.
  1. Nosada

    Nosada

    Joined:
    Aug 6, 2013
    Posts:
    61
    Ok, I got an issue that I wonder if anyone has a solution for. The shadows for my objects are off position from where they should be, which you can see in the accompanying picture. The object is touching the surface upon which it is placed. I did some searching for solutions to this problem, and it was suggested to adjust the shadow bias, which I did. I adjusted the normal bias and all of the settings I could think to adjust and it did not resolve the shadow problem. It seems this is a somewhat known problem with Unity. I tried setting the shadow bias to a negative number in the script and that did not work either, it just made the shadows look weird. Someone on another forum mentioned that they found something on the asset store to fix this, but they didn't link to it. I found something on the store that might be what he was referring to, but I'd prefer to resolve this issue without using store bought assets really. Anyone have any insight on this?
     
  2. Nosada

    Nosada

    Joined:
    Aug 6, 2013
    Posts:
    61
    I can't believe nobody has any solutions for this; it seems to be a common problem.
     
  3. kristijonas_unity

    kristijonas_unity

    Unity Technologies

    Joined:
    Feb 8, 2018
    Posts:
    510
    Our current shadow rendering algorithm in built-in RP is somewhat limited. Both HDRP and Universal RP feature much more advanced shadow rendering techniques, and we would highly recommend giving those render pipelines a try if you can.

    However, if switching render pipelines is not an option in your case, then please modify the entire UnityApplyLinearShadowBias() function with the following code:
    Code (CSharp):
    1. float4 UnityApplyLinearShadowBias(float4 clipPos)
    2.  
    3. {
    4.     // For point lights that support depth cube map, the bias is applied in the fragment shader sampling the shadow map.
    5.     // This is because the legacy behaviour for point light shadow map cannot be implemented by offseting the vertex position
    6.     // in the vertex shader generating the shadow map.
    7. #if !(defined(SHADOWS_CUBE) && defined(SHADOWS_CUBE_IN_DEPTH_TEX))
    8.     #if defined(UNITY_REVERSED_Z)
    9.         // We use max/min instead of clamp to ensure proper handling of the rare case
    10.         // where both numerator and denominator are zero and the fraction becomes NaN.
    11.         //clipPos.z += max(-1, min(unity_LightShadowBias.x / clipPos.w, 0));
    12.         clipPos.z += max(-1, min(unity_LightShadowBias.x / max( clipPos.w,1.0 ), 0));
    13.     #else
    14.         clipPos.z += saturate(unity_LightShadowBias.x/max( clipPos.w,1.0 ));
    15.     #endif
    16. #endif
    Please note that this workaround only works on desktop platforms, and we cannot guarantee functionality on other platforms/devices.
     
    Stardog, Nosada and Peter77 like this.
  4. Nosada

    Nosada

    Joined:
    Aug 6, 2013
    Posts:
    61
    Thanks. I just got done trying HDRP and I still have the same shadow problems. I would try your other suggestion, however I'm afraid I don't know where to find the UnityApplyLinearShadowBias() function.
     
  5. Nosada

    Nosada

    Joined:
    Aug 6, 2013
    Posts:
    61
    Does anyone know how to access the UnityApplyLinearShadowBias() function? I tried to search for a way but I can't find anything helpful to me.
     
  6. kristijonas_unity

    kristijonas_unity

    Unity Technologies

    Joined:
    Feb 8, 2018
    Posts:
    510
    You would either need to modify the standard shader, or create your own custom shader and add that function yourself.
     
  7. Nosada

    Nosada

    Joined:
    Aug 6, 2013
    Posts:
    61
    I'm not very knowledgeable on shaders; I don't know how to modify the standard shader and I don't know how to create my own shader. Can you recommend a tutorial or guide on how to do this?
     
  8. kristijonas_unity

    kristijonas_unity

    Unity Technologies

    Joined:
    Feb 8, 2018
    Posts:
    510
    Catlike Coding website has a large array of excellent tutorials on rendering in Unity. This one in particular - https://catlikecoding.com/unity/tutorials/rendering/part-7/ - should contain the information you need.
     
    Nosada likes this.
  9. Tudor

    Tudor

    Joined:
    Sep 27, 2012
    Posts:
    128
    >Shadows are peter panning
    >Unity: "try our new HDRP it's advanced AF"
    >Tried, still same problem

    You'd think this is a must have feature to fix before you can release a product with shadows. Especially considering it's kinda hard to see why it's a problem for Unity both when you're implementing your own shadows and when you look at other solutions.

    At least give us a cheap tradeoff offset slider in the quality settings.

    unity's peter panning.png
     
    Nosada likes this.
  10. Nosada

    Nosada

    Joined:
    Aug 6, 2013
    Posts:
    61
    You have this problem too? Thank goodness it's not just me.
     
  11. uy3d

    uy3d

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    168
    HDRP has changed how shadow biasing works going from v6.x to 7.x. Please ask in the HDRP specific forum about how to address these artifacts with the currently available parameters. As for builtin, doing a quick test with three boxes using similar scales and settings provides proper results, but this is very scene dependent and you haven't attached the light parameters and quality settings, so it's difficult to compare.
     
  12. Nosada

    Nosada

    Joined:
    Aug 6, 2013
    Posts:
    61
    HDRP didn't solve my issue. Here is a video of me creating a brand new project and demonstrating the problem. Please watch and then explain to me why this happens in a new, clean project with standard assets?
     
  13. uy3d

    uy3d

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    168
    that leak around the edge is caused by the bias parameter (NOT the normal bias param) on the light. Lowering this bias parameter will bring shadow closer to the corner, but a value that's too low will produce self-shadowing artifacts. Increasing the shadowmap resolution also combats this problem. HDRP used to have a flag called edge-leak fixup for such corner cases, but that functionality has been removed again starting with versions 7.x.
     
  14. Nosada

    Nosada

    Joined:
    Aug 6, 2013
    Posts:
    61
    I already tried adjusting the biases in my original project and it kind of seems like you're not paying attention since I mentioned that in my original post here! I even wrote a code to change the biases myself to make sure. None of that worked! Adjusting the biases does not fix this problem. I spent a lot of time trying to figure this out. I tried many things to fix it and nothing worked. It seems that Unity simply does not process shadows correctly.
     
    Last edited: Dec 20, 2019
    BigRookGames likes this.
  15. Nosada

    Nosada

    Joined:
    Aug 6, 2013
    Posts:
    61
    Ok so after all this time there are only 2 solutions I've found. 1. Create a narrative reason why the shadows in your game are messed up, like I did. 2. Just don't use realtime lighting in Unity because apparently it isn't really capable of it. So in the future I just won't use shadows in Unity, which is obviously frustrating but the fault is with Unity and I cannot fix it.
     
    Last edited: Dec 31, 2019
Thread Status:
Not open for further replies.
unityunity