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
