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

SOLVED in: (SOLVED) (2019.4.2f1/2020.2.5f1, URP/SG 7.4.1) Shadows look different in build than in editor


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.

void MainLight_half(float3 WorldPos, out half3 Direction, out half3 Color, out half DistanceAtten, out half ShadowAtten)
{
#if SHADERGRAPH_PREVIEW
    Direction = half3(0.5,0.5,0);
    Color = 1;
    DistanceAtten = 1;
    ShadowAtten = 1;
#else
    half4 shadowCoord = TransformWorldToShadowCoord(WorldPos);
    Light mainLight = GetMainLight(shadowCoord);
    Direction = mainLight.direction;
    Color = mainLight.color;
    DistanceAtten = mainLight.distanceAttenuation;
 
    //ShadowAtten = mainLight.shadowAttenuation;
 
    // too blocky?
    ShadowSamplingData shadowSamplingData = GetMainLightShadowSamplingData();
    half shadowStrength = GetMainLightShadowStrength();
    ShadowAtten = SampleShadowmap(shadowCoord, TEXTURE2D_ARGS(_MainLightShadowmapTexture,
            sampler_MainLightShadowmapTexture),
            shadowSamplingData, shadowStrength, false);
#endif
}

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

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

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)

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

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.

Solution at