Max shadow distance separate for directional light and other lights

Context: doing open world game, that can have lots of spot lights, but also has nature.

So I am experimenting with lighting now, URP 14, Forward+, and I noticed shadow casters are huge performance bottleneck.

I tried adjusting this setting to much lower (like 25), and performance improved a lot.

Of course, this setting is for ALL light sources, which is a bummer. I wish the shadows from trees to be visible on ground, yet 250 distance for candle lights (which have radius like 5 units), well it doesn’t make sense they would have 250 units for shadows.

Is there any possible way to somehow set the max distance for lights not to be 250?

I think I partially answered myself, there is custom setting per light settable via script:

Light.layerShadowCullDistances

I shall experiment with that.

I believe this does not work, I tested it…, spot light is throwing shadow beyond the culling limit I set.

Spot light only reacts to the global setting (picture in main thread I posed).

Any other way to set culling distance for spot light?

I think this option is only for the built in render pipeline…

Thanks for reply.

So does anyone know, is there any way to control max shadow distance / culling dist locally per light or per layer / group?

Have you tried decreasing the range of the additional lights? If the light’s range bound doesn’t intersect camera view frustum (you cannot see it in view), it will not draw shadows.

Yes, that is not the issue, range is like 10, and it works to cull the lights (and hence shadows).

Original issue is this:

Focus is on URP setting “Shadows: max distance = 250”, which is obviously huge, but needed for large trees.

So I tried spawning lots of point lights (like 7), and then compare performance when adjusting this ‘maxDistance’ parameter to less, like 25 (similar to range of point lights), and performance gain is quite a lot (like 5%).

So I am suspecting somehow URP is using distance of 250 (frustum culling?) to render all point lights shadow casters (each requiring 6 depth renders).

So unless I am missing something fundamentally, shouldn’t shadow casters render distance be capped to as much as it needs to be? Maybe that updated in newer URP versions?

I tested this again in URP, and most of the time objects are culled properly for shadow rendering.

Capsule is rendered to shadowmap (visible in Frame Debugger):
9587044--1357969--Shadow_1.jpg

Capsule is not rendered to shadowmap (invisible in Frame Debugger):
9587044--1357972--Shadow_2.jpg

For spot lights, the culling is not that precise at the 4 corners of the shadowmap.
9587044--1357984--Shadow.jpg

The max shadow distance behaves like the camera far plane, but for shadows.
9587044--1357981--MaxDistance.jpg

1 Like

Thank you for your time, seems I will have to redo the tests again just to make sure, with help of frame debugger.

1 Like

Ok, I tried test similar to yours, instead I just counted the meshes being rendered in Frame Debbuger; played with the Max Distance and Light radius.

It seems that number of draws get lower as the Light radius gets lower, so that part seems to be working fine.

Need more testing why the performance drops then, and will report back.

Ok, after more testing, I discovered I still had Sun light enabled somewhere (seems like it was inverted or something, it was not visible.

After disabling it, I see that ‘Max Distance’ parameter wasn’t main culprit of the point light performance.

As for separate ‘Max Distance’ parameter, I will just code up my own lights distance script for spot light shadows and disable the shadows, if lights are far away from player.