Use RenderTargetTexture render() to render once

I want to render to the render target texture once, not hook it up to a scene via scene.customRenderTargets. I create a render target and attach it to a material. Calling render() on the render target doesn’t update the material, only a second call seems to do it.

I don’t have a good understanding of how babylonjs renders a frame and I would appreciate what’s going on.

It can be seen here

Though that example uses layers, this is simplified example doesn’t exhibit the issue

Its because no content had rendered yet in the scene context. If you do the rrt.render() after the main render pass there are things for it to see!

In the second playground example you posted the one that does not use layers the RTT is not the output image so you would not see this behavior. The first one have a plane I believe that is covering the main output and you did not add the RTT to the custom render list so it would not auto update.

1 Like

The RenderTargetTexture.render method won’t do anything until all the materials used by the meshes in the renderList array are ready. As the material compilation is asynchronous, it can take one or more frames to be ready, so calling rtt.render right away won’t work.

You need to make sure the RTT is ready before calling render:


Thanks, that fixed it!