# Disabling SSAO2 breaks FXAA

**URL:** <https://forum.babylonjs.com/t/disabling-ssao2-breaks-fxaa/22391>\
**Category:** Bugs\
**Created:** [July 15, 2021, 9:08am UTC](https://forum.babylonjs.com/t/disabling-ssao2-breaks-fxaa/22391 "2021-07-15T09:08:59Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kesshi](https://avatars.discourse-cdn.com/v4/letter/k/b782af/32.png) [@Kesshi](https://forum.babylonjs.com/u/Kesshi)\
**Post date:** [July 15, 2021, 9:08am UTC](https://forum.babylonjs.com/t/disabling-ssao2-breaks-fxaa/22391/1 "2021-07-15T09:08:59Z")

</div>

PG: [Babylon.js Playground](https://playground.babylonjs.com/#QFXII0)  
If you press 2 to disable SSAO2 you will see a strange effect if you move the camera.  
This happens only with babylon.js 5.0 (not with 4.2) and only if FXAA is enabled.

---

<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:** [July 15, 2021, 10:05am UTC](https://forum.babylonjs.com/t/disabling-ssao2-breaks-fxaa/22391/2 "2021-07-15T10:05:17Z")

</div>

It seems there’s no framebuffer clearing when disabling the effect.

Pinging @CraigFeldspar as it is linked to the pre-pass renderer (when forcing the geometry buffer by setting the 5th parameter of the `SSAO2RenderingPipeline` constructor to `true` it does work).

---

<div class="post-metadata">

**Author:** ![CraigFeldspar](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/craigfeldspar/32/45631_2.png) [@CraigFeldspar](https://forum.babylonjs.com/u/CraigFeldspar)\
**Post date:** [July 15, 2021, 11:19am UTC](https://forum.babylonjs.com/t/disabling-ssao2-breaks-fxaa/22391/3 "2021-07-15T11:19:52Z")

</div>

Opened a PR for that issue [adding autoclear to PP when unlinking prepassRT by CraigFeldspar · Pull Request #10676 · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/pull/10676). It was indeed the autoclearing of the postprocess that got disabled by the prepass, and not re-enabled when disabling the prepass.

Waiting for the PR to be merged, you can fix your playground by adding :

```auto
     tFXAA.autoClear = true;

```

Just like in this PG :  
[https://playground.babylonjs.com/#QFXII0#2](https://playground.babylonjs.com/#QFXII0#2)

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [July 15, 2021, 2:38pm UTC](https://forum.babylonjs.com/t/disabling-ssao2-breaks-fxaa/22391/4 "2021-07-15T14:38:41Z")

</div>

You rock !!! I ll make a nightly ASAP.

---

<div class="post-metadata">

**Author:** ![Kesshi](https://avatars.discourse-cdn.com/v4/letter/k/b782af/32.png) [@Kesshi](https://forum.babylonjs.com/u/Kesshi)\
**Post date:** [July 30, 2021, 1:30pm UTC](https://forum.babylonjs.com/t/disabling-ssao2-breaks-fxaa/22391/5 "2021-07-30T13:30:07Z")

</div>

The Fix works but i noticed another problem. You can see it in this PG if you press 2 to disable SSAO2: [https://playground.babylonjs.com/#QFXII0#3](https://playground.babylonjs.com/#QFXII0#3)

After disabling SSAO the drawing order is messed up. Just like if depth testing is disabled.  
Again this happens only if FXAA is enabled.  
It seems thats its currently important to create the FXAA instance before the SSAO instance. If you create it after SSAO you will get this problem. Is this a bug?

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [July 30, 2021, 2:12pm UTC](https://forum.babylonjs.com/t/disabling-ssao2-breaks-fxaa/22391/6 "2021-07-30T14:12:16Z")

</div>

It sounds normal that order is quite important as the creation order will be the run order.

---

<div class="post-metadata">

**Author:** ![Kesshi](https://avatars.discourse-cdn.com/v4/letter/k/b782af/32.png) [@Kesshi](https://forum.babylonjs.com/u/Kesshi)\
**Post date:** [July 30, 2021, 3:13pm UTC](https://forum.babylonjs.com/t/disabling-ssao2-breaks-fxaa/22391/7 "2021-07-30T15:13:11Z")

</div>

The problem i have is that there is no direct way to enable or disable a postprocess. I have to detach it from the camera and if i attach it later again the order has changed. I have several postprocesses that i want to enable and disable dynamically very frequently.

---

<div class="post-metadata">

**Author:** ![Kesshi](https://avatars.discourse-cdn.com/v4/letter/k/b782af/32.png) [@Kesshi](https://forum.babylonjs.com/u/Kesshi)\
**Post date:** [July 30, 2021, 4:09pm UTC](https://forum.babylonjs.com/t/disabling-ssao2-breaks-fxaa/22391/8 "2021-07-30T16:09:40Z")

</div>

I just saw that my playground works with version 4.2. Only version 5.0 has this problem.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [July 30, 2021, 6:39pm UTC](https://forum.babylonjs.com/t/disabling-ssao2-breaks-fxaa/22391/9 "2021-07-30T18:39:57Z")

</div>

@CraigFeldspar might have an idea?

---

<div class="post-metadata">

**Author:** ![Kesshi](https://avatars.discourse-cdn.com/v4/letter/k/b782af/32.png) [@Kesshi](https://forum.babylonjs.com/u/Kesshi)\
**Post date:** [August 2, 2021, 6:09am UTC](https://forum.babylonjs.com/t/disabling-ssao2-breaks-fxaa/22391/10 "2021-08-02T06:09:56Z")

</div>

One more thing: If you dispose the SSAO2 postprocess instead of detaching it you will get the same problem. Disposing something should not have such side effects i would say.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [August 2, 2021, 1:42pm UTC](https://forum.babylonjs.com/t/disabling-ssao2-breaks-fxaa/22391/11 "2021-08-02T13:42:11Z")

</div>

@Kesshi nope, it should definitely not 🙂 @CraigFeldspar will have a look soon nw.

---

<div class="post-metadata">

**Author:** ![CraigFeldspar](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/craigfeldspar/32/45631_2.png) [@CraigFeldspar](https://forum.babylonjs.com/u/CraigFeldspar)\
**Post date:** [August 4, 2021, 9:45am UTC](https://forum.babylonjs.com/t/disabling-ssao2-breaks-fxaa/22391/12 "2021-08-04T09:45:57Z")

</div>

I found the problem, we have a condition when generating DepthBuffers for post processes which is shown on that capture :

 ![Capture](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/b/a/ba7f471a634f8a41d27ee72bbbefe98ddb9d20e9.png)

Turns out all of these null postprocesses are messing with us.  
@sebavan do you remember why we are setting the postprocess reference to `null` when disposing/detaching in the camera postProcess list instead of just performing `splice` ? I’m thinking about cleaning all of these `null` but maybe there is an underlying reason (keeping the order when removing/adding ?)

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [August 4, 2021, 2:44pm UTC](https://forum.babylonjs.com/t/disabling-ssao2-breaks-fxaa/22391/13 "2021-08-04T14:44:08Z")

</div>

No reason, feel free to drop them 🙂

---

<div class="post-metadata">

**Author:** ![Kesshi](https://avatars.discourse-cdn.com/v4/letter/k/b782af/32.png) [@Kesshi](https://forum.babylonjs.com/u/Kesshi)\
**Post date:** [August 17, 2021, 6:53am UTC](https://forum.babylonjs.com/t/disabling-ssao2-breaks-fxaa/22391/14 "2021-08-17T06:53:16Z")

</div>

@CraigFeldspar Some news about this issue? ( sorry for being impatient 🙂 )

---

<div class="post-metadata">

**Author:** ![CraigFeldspar](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/craigfeldspar/32/45631_2.png) [@CraigFeldspar](https://forum.babylonjs.com/u/CraigFeldspar)\
**Post date:** [August 17, 2021, 9:26am UTC](https://forum.babylonjs.com/t/disabling-ssao2-breaks-fxaa/22391/15 "2021-08-17T09:26:51Z")

</div>

@Kesshi holidays went through 🙂 but I’m back now, having a look this afternoon, PR should come shortly after

---

<div class="post-metadata">

**Author:** ![CraigFeldspar](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/craigfeldspar/32/45631_2.png) [@CraigFeldspar](https://forum.babylonjs.com/u/CraigFeldspar)\
**Post date:** [August 18, 2021, 8:13am UTC](https://forum.babylonjs.com/t/disabling-ssao2-breaks-fxaa/22391/16 "2021-08-18T08:13:21Z")

</div>

PR is here [https://github.com/BabylonJS/Babylon.js/pull/10887](https://github.com/BabylonJS/Babylon.js/pull/10887), should be merged soon and you should be good to go with the next alpha build

---

<div class="post-metadata">

**Author:** ![PolygonalSun](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/polygonalsun/32/2704_2.png) [@PolygonalSun](https://forum.babylonjs.com/u/PolygonalSun)\
**Post date:** [August 18, 2021, 5:18pm UTC](https://forum.babylonjs.com/t/disabling-ssao2-breaks-fxaa/22391/17 "2021-08-18T17:18:03Z")

</div>

The PR looks like it’s merged.
