URP 7.1.8. _WorldSpaceCamerPos not always set in shadowcaster pass?

hey there,

i have a shader that fades out alpha according to the distance between camera and object which works fine in most of the cases. it fades out in all passes. however, if the camera does not move but only rotate shadows start to flicker.
i managed to track it down to _WolrdSpaceCameraPos: if i fix the camera position and manually add its position to the shadow caster pass shadows are stable.

float3 worldInstancePos = UNITY_MATRIX_M._m03_m13_m23;
float3 diff = (_WorldSpaceCameraPos - worldInstancePos);
float dist = dot(diff, diff);
fade = saturate( (_DistanceFade.x - dist) * _DistanceFade.y );

can anybody confirm this?
tested on mac os using metal and opengl.

Hi, this is a bug. could you open a bug report for this?

i will :slight_smile:

crazy, shadow flickering only occurs if i use a unity terrain which has added some trees (simple lod groups: just a capsule and a cylinder). as soon as i deactivate “draw details” on the terrain shadows look fine.
the grass btw. is placed as single game objects.
passing a custom _CameraPositionInWorldSpace to the shadow caster pass also fixes the problem.

https://www.youtube.com/watch?v=sfte09hYqcY

i filed the bug report:
Case 1215610

1 Like