Enable DepthRenderer on two cameras (or on camera switch with multiple cameras)

Dears and @sebavan who gave me the solution with this depthRenderer to enable PP without breaking the 3D GUI layer (or the entire assembly of 2D GUI, FS GUI and 3D GUI). Thanks a lot, it works like a charm when I set it to my camera.

However, the issue I’m having and have been fiddling with for an hour is that, for some reason (probably because of my lack of understanding of the full logic) I’m quite unable to have this renderer work on camera switch.

I think I cannot have the renderer set to a list of cameras. And I cannot use the activeCamera(s) because it takes the later, which is my camera for the FS GUI only.

From the PG below, containing ‘camera’, ‘camera2’ and the ‘bgcamera’ for the FS GUI, my question is:

  • How do I set the renderer to use the active (scene) camera on camera switch ?

You can switch camera using KB num “1” and “2”.

The renderer (your renderer @Sebavan) starts from line 243.
My apologies for the ugly PG but I hope it will suffice to help me fix this.

Thanks in advance,

A depth renderer is tied to a camera, although this is not obvious when you use the default scene.enableDepthRenderer() call: if you do not pass a camera (the first parameter of the function), it uses the currently active camera (scene.activeCamera) to create the depth renderer.

So, if you have another camera, you have to call scene.enableDepthRenderer(otherCamera) to create a depth renderer for it.

1 Like

Thank you. I kind of tried that but it didn’t work. May be because of the effect wrapper being called on scene.onAfterRenderCameraObservable? Or because the variable of ‘depthRenderer’ (line 276 in PG) is not being updated? That’s actually the part I have been ‘fiddling’ with. I must be doing something wrong…

Edit: Like at some point I was trying something like this (below). Now that I do it in PG, it seems to work (the fancy thing). I’m gonna try again in my scene but it was not working. Though, would you say that this is the way or a way to do it?

Created an ‘activecam’ variable for the camera.
Changing the value of ‘activecam’ on camera switch.
Set the wrapper and renderer to use ‘activecam’
Called scene.enableDepthRenderer(activecam) on camera switch.

Edit1: OMG. I’m so stupid. :face_with_hand_over_mouth: With all my tests, I ended up inverting the cameras in my scene. So, yes the above does work. Not sure it’s the best way to do it though but it works. Just let me know if there’s a better way. Else, I can do with what I have. Thanks a lot and have a great day :sunglasses:

Yes, you must call scene.enableDepthRenderer() with the correct camera as the first parameter, there is no way around this. Note that if a depth renderer has already been created for a camera, it will be reused, we won’t create a new one. So there is no risk to call enableDepthRenderer several times with the same camera parameter.