Postprocess on renderTarget clearing problem


Basically, I’m using this “hack” : RenderTarget autoClear
to never clear my renderTarget so I can accumulate of top of it.

This renderTarget can be cleared with an input action the user.
To clear the renderTarget manually, I’m clearing the onClearObservable, render the renderTarget, then put back the empty function onClearObservable.

Recently, I added a postprocess on this renderTarget. It’s working well, however I cannot clear anymore, the postprocess seems not to be cleared.

Is it a bug ? I haven’t found a workaround.

Can you maybe repro your use case in the Playground?

Hi !
Very hard to repro but I think I got it, it needs alpha to see the problem (i’m having alpha in my project) :

So, the top renderTarget is the one with the postprocess. The bottom one is without. Both of them are not clearing out. If you click on the clear renderTarget button, it will manually clear both RT. But you can notice that the top one is not cleared properly, but it still better than my local which don’t clear at all.

Everything seems ok to me.

When you hit the “Clear button” and let the system clear the render target, it does:

engine.clear(this.clearColor || scene.clearColor, true, true, true);

as you did not define a color for the RTT, it gets the clear color from the scene: 0.2, 0.2, 0.3, 1.0

Then your custom shader add 0.5 to the red component, so it makes the whole thing appears redish.

I think what you want is: renderTarget.clearColor = new BABYLON.Color4(0, 0, 0, 0);

Indeed thanks. Good to know each RT has its own clear color.

However this is not resolving the situation I have in local, so it’s coming from something else. I don’t successfully repro it. So on my local, I’m not rendering the scene, i’m only rendering the RT when I need an update. Will this could be any problem ?

Just let me show you what is happening, I can draw on the renderTarget like so :

I have a button that clear the renderTarget. If I’m pressing it, without the postprocess, it clears to transparent (browser background is white). I can then draw again without any problem.
If I add the postprocess and clear, it does not remove the draw. Then, if I draw again on top, it looks like this :

Which is weird because it seems to have cleared the RT because The alpha goes to white. There is some kind of persistence.

I just find why. My renderTarget shader has this property in the fragment shader :
if(dest.a == 0.0){ discard; }

I’m afraid it will be difficult to tell without a repro…

Can you share a github if a PG is not possible?

Good catch!

1 Like

I made the repro here :
Just in case. Thank you anyway :slight_smile:

1 Like