Usage of camera.customRenderTargets when using utilityLayer

PG: https://playground.babylonjs.com/#PIZ1GK#2011.
I just recognized that camera.customRenderTargets will render twice when using utilityLayer, but it seems there is little situation that customRenderTargets are needed when rendering utilityLayerScene. Maybe something like scene.customRenderTargetsEnabled should be added?

If it is just expected, when should I use camera.customRenderTargets and scene.customRenderTargets?

Use scene.customRenderTargets for camera independant rendered renderTarget like a noise texture for instance.

And camera.customRenderTargets for anything that depends on the camera data

So it is expected that utilityLayer will render the depth map for ssr again?

About SSR it is tricky as it is definitely camera dependant but the utility layer would not need it.

cc @Evgeni_Popov to see if this is fixed in framegraph and if you have any idea how to optimize on current rendering

So I think utility layer can use a new camera cloned from origin scene, as it seems there is no situation that utility layer needs a texture from camera.customRenderTargets.

1 Like

There won’t be this problem with frame graphs because we don’t use scene.customRenderTargets / camera.customRenderTargets anymore: all render passes are defined inside the graph.

2 Likes