Search Unity

Bug (SOLVED) Shadows showing the shadowmap, only in Build (2019.4.2f1 & 2020.2.5f1)

Discussion in 'Universal Render Pipeline' started by melos_han_tani, Feb 21, 2021.

  1. melos_han_tani

    melos_han_tani

    Joined:
    Jan 11, 2018
    Posts:
    79
    SOLVED in: https://forum.unity.com/threads/201...ok-different-in-build-than-in-editor.1061924/

    ---

    Edit - on a whim I decided to try upgrading to 2020.2.5f1 - nothing changes.

    Hi all, I use custom lighting for all my shaders in this game. I'm trying to figure out why when I make a build, I get these weird shadows appearing (see 2nd image).

    They appear in multiple scenes, and always tend to look like big squares with tiny gaps in between them. As far as I can tell there's nothing in my game that would cast those shadows, and they always seem to be towards the near, world-forward of my camera. As in if I run around elsewhere in the level they often still show, meaning it's not something projecting from the environment.

    I don't have light baking or multiple lights in my scene, only one directional.

    If I had to guess, they kind of look like what a shadowmap for the scene might look on based on the single directional light...? But I'm not sure.

    This is the correct shadows (Editor)



    Incorrect shadows (BUILD)



    My guess is something weird is happening with the shadows in my cel shader, but I don't get why it would ONLY happen in the build. Here's the code I'm using to output shadow attenuation in my cel shaders. The problem could be anywhere, but I literally have no idea to look because it is completely beyond me why this would happen only in a build.

    Code (CSharp):
    1.  
    2.  
    3. void MainLight_half(float3 WorldPos, out half3 Direction, out half3 Color, out half DistanceAtten, out half ShadowAtten)
    4. {
    5. #if SHADERGRAPH_PREVIEW
    6.     Direction = half3(0.5,0.5,0);
    7.     Color = 1;
    8.     DistanceAtten = 1;
    9.     ShadowAtten = 1;
    10. #else
    11.     half4 shadowCoord = TransformWorldToShadowCoord(WorldPos);
    12.     Light mainLight = GetMainLight(shadowCoord);
    13.     Direction = mainLight.direction;
    14.     Color = mainLight.color;
    15.     DistanceAtten = mainLight.distanceAttenuation;
    16.  
    17.     //ShadowAtten = mainLight.shadowAttenuation;
    18.  
    19.     // too blocky?
    20.     ShadowSamplingData shadowSamplingData = GetMainLightShadowSamplingData();
    21.     half shadowStrength = GetMainLightShadowStrength();
    22.     ShadowAtten = SampleShadowmap(shadowCoord, TEXTURE2D_ARGS(_MainLightShadowmapTexture,
    23.             sampler_MainLightShadowmapTexture),
    24.             shadowSamplingData, shadowStrength, false);
    25. #endif
    26. }
    27.  
    Here's another example of the incorrect shadows in another area. It sort of looks like a shadowmap of the level projected incorrectly?





    And here's my URP Asset parameters



    Forward Renderer

     
    Last edited: Feb 23, 2021
  2. melos_han_tani

    melos_han_tani

    Joined:
    Jan 11, 2018
    Posts:
    79
    Worth mentioning I don't use light baking or whatever.

    Also, there are a few errors in the Shadergraph Shader, but they've never caused ill effects in the editor






    There's a few keywords I enable on the shader graph too. Although the only ones I specified manually are _MAIN_LIGHT_SHADOWS_CASCADE and _SHADOWS_SOFT



     
  3. melos_han_tani

    melos_han_tani

    Joined:
    Jan 11, 2018
    Posts:
    79
    Okay, so I've figured something interesting out:

    It seems like correct shadows show up in the first shadow cascade. Here's an example when I have the first cascade set to 13.3% and distance of 200 (so it's cutting off around 26 units or so). I also tried this at the default (first cascade 6.6%) and it seemed to have the weird cutoff at the expected distance (13 units or so)

    upload_2021-2-22_16-36-44.png

    Moreover, I changed my Shadow Attenuation getting code to this:

    upload_2021-2-22_16-37-48.png

    And it seemed to have fixed the problem for one scene for a while... but now the problem is back! I don't know why the problem got fixed and then re-appeared. Truly, I am in hell.
     
  4. melos_han_tani

    melos_han_tani

    Joined:
    Jan 11, 2018
    Posts:
    79