RenderTarget autoClear

Hi ! I’m creating a drawing application with Babylon.
I’ve created a scene that has autoClear = false in order to draw. I need to copy this scene as a RenderTarget which is working fine. But, the renderTarget does get cleared losing the initial purpose. I couldn’t find a property autoClear or something similar on the RenderTargetTexture docs. How can I achieve this ?

Hi Corentin,

First of all, welcome to Babylon!

It doesn’t look like there’s a feature built in specifically for doing exactly that. However, judging by this if statement, it looks like adding an observer to the render target texture’s onClear observable will cause the texture to not be cleared.

I tested this by going to the “Custom Render Targets” example Playground and adding the following code on a new line at 62:

renderTarget.onClearObservable.add(()=>{});

I think this might work for your purpose. One caveat, though: this prevents the clearing of the depth buffer, too, so you’ll have to be mindful of that if the depth buffer will affect your future drawing.

1 Like

Hi ! Thanks, it’s working smoothly :slight_smile: !