RenderTarget on demand rendering

I am trying to get this to work without changing the engine render loop. Is there a way to render a scene - once - to a rendertarget outside the normal rendering?

I want to use this rendertarget output as the input to another rendertarget.

Ideally a scene.render() that I can call from anywhere to render that scene - in the case of this playground it would be rttscene.render()

You can manually render the RTT as part of the scene’s render loop. Something like this - Draw plane to render target and show it on material | Babylon.js Playground (babylonjs.com). Is that the effect you are looking for? (You can also render the other scene, if you are looking for a more complex scenario - Draw plane to render target and show it on material | Babylon.js Playground (babylonjs.com))

1 Like

The thing is I need to use the result of the rendertarget as an input to another rendertarget. Is it not possible to render outside the render loop?

If I daisy chain these up and run the chain inside the render loop will that work? eg; render the first target, and then use that as an input to a shader and then render the next render target, and so on?

you can decide when to render, but you need to be sure the resources needed to render are already available (or “ready”). In your case RTT one needs to wait for the resources to render correctly, and then RTT2 needs to wait for RTT1 to render in order to render correctly.

Thanks - that worked!

1 Like

Hi - I am finally able to get back to this project; I have it working, except when I move the plan…it does not move!

You see I set the position.x to 200 in this playground - but the plane always appears centered at 0,0,0 no mater what I set the position to. I have been tearing my hair out about this - why wouldn’t the plane move?

any ideas would be greatly appreciated.

You have to rerender the rttScene:

    scene.onBeforeRenderObservable.addOnce(() => {
        rttscene.render()
    })

1 Like

Thanks - not sure why, but 5 mins after I put up this question I changed the position using;
mesh.position = new BABYLON.Vector3(10,0,0) and it moved! Strange that changing it that way worked(?)

Nothing strange here :stuck_out_tongue:

Are you familiar with dirtty flags in programming?

This happens when you set the position as a Vector3:

    public set position(newPosition: Vector3) {
        this._position = newPosition;
        this._isDirty = true; // sets the mesh dirty!
    }

Super simply explained: dirty stuff gets rerendered.

If you set the position by changing the property x of the Vector3 object it’s not marked as dirty.

Yeah - I thought it must be something similar to that - thanks for clarifying, all working now!

1 Like