# Postprocess on renderTarget clearing problem

**URL:** <https://forum.babylonjs.com/t/postprocess-on-rendertarget-clearing-problem/7964>\
**Category:** Questions\
**Tags:** material\
**Created:** [January 10, 2020, 5:13pm UTC](https://forum.babylonjs.com/t/postprocess-on-rendertarget-clearing-problem/7964 "2020-01-10T17:13:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Corentin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/corentin/32/4861_2.png) [@Corentin](https://forum.babylonjs.com/u/Corentin)\
**Post date:** [January 10, 2020, 5:13pm UTC](https://forum.babylonjs.com/t/postprocess-on-rendertarget-clearing-problem/7964/1 "2020-01-10T17:13:15Z")

</div>

Hello,

Basically, I’m using this “hack” : [RenderTarget autoClear](https://forum.babylonjs.com/t/rendertarget-autoclear/6117/2)  
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.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [January 10, 2020, 8:15pm UTC](https://forum.babylonjs.com/t/postprocess-on-rendertarget-clearing-problem/7964/2 "2020-01-10T20:15:31Z")

</div>

Can you maybe repro your use case in the Playground?

---

<div class="post-metadata">

**Author:** ![Corentin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/corentin/32/4861_2.png) [@Corentin](https://forum.babylonjs.com/u/Corentin)\
**Post date:** [January 13, 2020, 5:49pm UTC](https://forum.babylonjs.com/t/postprocess-on-rendertarget-clearing-problem/7964/3 "2020-01-13T17:49:41Z")

</div>

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) :  
[https://www.babylonjs-playground.com/#CJWDJR#11](https://www.babylonjs-playground.com/#CJWDJR#11)

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.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [January 13, 2020, 7:19pm UTC](https://forum.babylonjs.com/t/postprocess-on-rendertarget-clearing-problem/7964/4 "2020-01-13T19:19:53Z")

</div>

Everything seems ok to me.

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

```javascript
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);`

[https://www.babylonjs-playground.com/#CJWDJR#12](https://www.babylonjs-playground.com/#CJWDJR#12)

---

<div class="post-metadata">

**Author:** ![Corentin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/corentin/32/4861_2.png) [@Corentin](https://forum.babylonjs.com/u/Corentin)\
**Post date:** [January 13, 2020, 7:36pm UTC](https://forum.babylonjs.com/t/postprocess-on-rendertarget-clearing-problem/7964/5 "2020-01-13T19:36:47Z")

</div>

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 :

 ![chrome_6Ei1asye4V](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/1/1e427e6e20918d6a856e9cedcf284e59b5b79709.png)  
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 :  
 ![chrome_j6ocnIFFak](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/c/c32cd2579417e93848128243ff407a999bae69e3.jpeg)  
Which is weird because it seems to have cleared the RT because The alpha goes to white. There is some kind of persistence.

---

<div class="post-metadata">

**Author:** ![Corentin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/corentin/32/4861_2.png) [@Corentin](https://forum.babylonjs.com/u/Corentin)\
**Post date:** [January 13, 2020, 7:40pm UTC](https://forum.babylonjs.com/t/postprocess-on-rendertarget-clearing-problem/7964/6 "2020-01-13T19:40:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [January 13, 2020, 7:40pm UTC](https://forum.babylonjs.com/t/postprocess-on-rendertarget-clearing-problem/7964/7 "2020-01-13T19:40:36Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [January 13, 2020, 7:41pm UTC](https://forum.babylonjs.com/t/postprocess-on-rendertarget-clearing-problem/7964/8 "2020-01-13T19:41:07Z")

</div>

Good catch!

---

<div class="post-metadata">

**Author:** ![Corentin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/corentin/32/4861_2.png) [@Corentin](https://forum.babylonjs.com/u/Corentin)\
**Post date:** [January 13, 2020, 7:41pm UTC](https://forum.babylonjs.com/t/postprocess-on-rendertarget-clearing-problem/7964/9 "2020-01-13T19:41:47Z")

</div>

I made the repro here : [https://www.babylonjs-playground.com/#CJWDJR#13](https://www.babylonjs-playground.com/#CJWDJR#13)  
Just in case. Thank you anyway 🙂
