shadowMaxZ is ignored when changing CSM depth renderer

Hey there,

I am setting up a cascaded shadow generator on my scene and I want to change the camera. I found this topic that demonstrated how to make this happen:

I am having some issues when one of the camera has a large maxZ (the shadows are no longer being rendered correctly for that camera):

It looks like the maxZ of the camera overrides the shadowMaxZ.

However, in a simpler setup with a single camera, the problem goes away (shadowMaxZ is used for the CSM):

Any idea what’s going on here?

cc @Evgeni_Popov

1 Like

Changing the camera used by a depth renderer is not really supported, because a depth renderer is strongly linked to a camera (internally, we keep an association between a camera and its depth renderer).

In your case, you can set depthRenderer._camera = camera to make it work, but we don’t promise it won’t break in newer releases of Babylon:

Thanks for your answer! Would something like the PG below work better?

There is no API to get the depth renderer linked to the current camera as far as I know :thinking:

The problem is that both depth renderers generate their map each frame, even the depth renderer of the camera which is not active. You should do as in https://www.babylonjs-playground.com/#1ST43U#444 and disable the depth renderer for the non active camera.

I see, in the end my code is not that much more compact than the original PG :laughing: Thanks for taking the time to explain :slight_smile:

Note that it’s straightforward to do it with a frame graph:

However, rebuilding the graph each time the camera changes can be a bit taxing because the shadow generator (among other objects) will be disposed/recreated each time.

It’s more performant to just update the camera for the tasks that use it:

The frame graph: https://nrge.babylonjs.com/#LUA8JA#5

2 Likes

All hail the magnificent frame graph!

1 Like

Frame graph is going to be epic! Will it release officially with Babylon 9 :eyes: ?

Absolutely!

1 Like

Can’t agree more!

1 Like