Prevent defaultRenderingPipeline from changing scene.autoClear

I need to have scene autoClear set to true because I have no background in my scene but something was always putting the value back to false.
Checking BabylonJS code I found that there is the defaultRenderingPipeline which is able to change it: Babylon.js/defaultRenderingPipeline.ts at master · BabylonJS/Babylon.js · GitHub

So I was wondering if there was a way to avoid that?

In my use case I realized the autoClear value was changing after I used addCamera or removeCamera functions from defaultRenderingPipeline.
So I just made sure the value of autoClear back to true after using one of these functions.

But maybe there is a way to avoid that in defaultRenderingPipeline class?
It seems to be coming from the _buildPipeline function which need to change scene autoClear value. Could we save the current state of scene autoClear at the begining of this function in order to put it back at the end?

This issue is a bit annoying. I still have the autoClear value changing and I don’t always know why. I found the _buildPipeline function which changes it but it seems there is other things doing that too. I ended up adding a registerbeforerender call in order to make sure autoClear always has the value I need.

I am wondering if that could work better?
In a way, I don’t see the point of having an option like autoClear that changes afterwards no matter the value we need. And on the other hand, I suppose you also change the value for a real reason.

Just sharing my thoughts but I feel there is an obvious issue with the fact that I have to use registerbeforerender call to make sure the value doesn’t change.

I could only find the default rendering pipeline and WebXRExperienceHelper updating the scene.autoClear value.

I guess the default rendering pipeline does it for some good reason and should not produce artifacts: could you provide a PG where this behaviour is a problem?

Hi @Evgeni_Popov,

I don’t use the WebXRExperienceHelper so it must only come from defaultRenderingPipeline.

So I should check every time the _buildPipeline function is called which is actually everywhere in defaultRendering Pipeline class :sweat_smile:
Still a bit annoying but doable.

Out of curiosity, why the pipeline need autoClear = true ?

I don’t know why the code is messing with the scene.autoClear property as it seems to me the clearing is handled at the post process level: the first post process clears the texture and the next ones don’t.

Maybe @sebavan will know more.

Yup it is because we are heavily optimizing each passes to prevent extra clear which costs performance wise. There is basically no need to clear the canvas because of post processes always copying to it full screen in the end. This happens everytime the pipeline rebuild itself.

I can easily add an observable if it is easier for you ???

As you wish @sebavan!

I will eventually make the equivalent of one observable in my code to keep that simple and working. If it can also help others, it will be smart to indeed add an observable on babylonJS side.

So from what you are saying, I am losing a lot of performance gain when setting autoClear to false right? My use case is that I need to show a 3D object without any background and this isn’t really working when autoClear = true unfortunately.

Cheerz

no problem, in your case clear will help: Add rendering pipeline built observable by sebavan · Pull Request #9195 · BabylonJS/Babylon.js · GitHub

You ll have it in the next nightly.

Perfect and thanks for the observable :wink: