RenderTargetTexture using multiple scenes at once

I am trying to use Babylon.js to have two different scenes at once, using RenderTargetTexture using the camera of one scene, to use it as material of a plane on another scene. Does anybody have a working example, or could possibly create one?

Hello and welcome!

A working example:

Switch to the second scene and the sphere will use the render target from the first scene. The code involved in creating the rtt and setting it as a texture:

    const rtt = new BABYLON.RenderTargetTexture('rtt', 2048)
    firstScene.customRenderTargets.push(rtt)
    rtt.renderList.push(firstSceneObject)

    sphere1.material.emissiveTexture = rtt // sphere1 is on the second scene

First scene:

Second:

2 Likes

Thanks! This example is great! I got it to work in my own project with a few changes. I was wondering if it would be possible to have an example like this working if the scenes were contained in separate HTML canvases as well. Is something like that possible and are there any examples out there?

I know that there is a lot in the docs but I recommend you to go trough all the sections to get familiar what are the possibilites of the framework. Later you can get back to a specific section and learn how exactly the implementation looks like in detail.

Another good idea is to use the search functionality of the forum. You will get answers on nearly all your issues you coud face while you are slowly mastering the framework.

:slight_smile:

So here you go for now:

https://doc.babylonjs.com/features/featuresDeepDive/scene/multiCanvas

https://doc.babylonjs.com/features/featuresDeepDive/scene/multiScenes

https://doc.babylonjs.com/features/featuresDeepDive/postProcesses/renderTargetTextureMultiPass

I’ll be sure to look at the documentation. Thanks for the advice and the links to relevant topics.

1 Like