# Why does SSAO/2 wreck AA for me?

**URL:** <https://forum.babylonjs.com/t/why-does-ssao-2-wreck-aa-for-me/28665>\
**Category:** Questions\
**Tags:** pipeline, shadows\
**Created:** [March 23, 2022, 1:55am UTC](https://forum.babylonjs.com/t/why-does-ssao-2-wreck-aa-for-me/28665 "2022-03-23T01:55:30Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![brechindo](https://avatars.discourse-cdn.com/v4/letter/b/e95f7d/32.png) [@brechindo](https://forum.babylonjs.com/u/brechindo)\
**Post date:** [March 23, 2022, 1:55am UTC](https://forum.babylonjs.com/t/why-does-ssao-2-wreck-aa-for-me/28665/1 "2022-03-23T01:55:30Z")

</div>

N00b time again! What am I doing wrong?

Added SSAO2RenderingPipeline (also tried older SSAO(1)). AA gets wrecked.

Before, no rendering pipeline defined, jaggies are noticeable but not terrible:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/6/2/62745cbcf969f38e8a358593e534a64d100c2716.jpeg)

After, with SSAO, jaggies become horrible:  
`const ssao = new SSAO2RenderingPipeline( 'ssaopipe', scene, 0.75, [camera] );`

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/2/1/21b1e1999598c21d3c2f43a579498441b00e4128.jpeg)

Even flat-out copy-pasting the SSAO setup values from [Babylon.js - Screen Space Ambient Occlusion demo](https://www.babylonjs.com/demos/ssao/) (which looks lovely, BTW) changes nothing.

```auto
    var ssao = new SSAORenderingPipeline("ssaopipeline", scene, {ssaoRatio: .5, combineRatio: 1});
    ssao.fallOff = 1e-6;
    ssao.area = 1;
    ssao.radius = 4e-4;
    ssao.totalStrength = 2;
    ssao.base = 1.3;
    scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline("ssaopipeline", camera);

```

Latest Brave (but Chrome renders no differently), modern Win10 PC, latest NVidia, no WebGL1.0 excuses here.

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [March 23, 2022, 12:31pm UTC](https://forum.babylonjs.com/t/why-does-ssao-2-wreck-aa-for-me/28665/2 "2022-03-23T12:31:03Z")

</div>

Hey there! I’d wager this is a side-effect of the way the pipeline combines the images 🤔 but let’s check out with @Deltakosh and @sebavan

I can definitely notice this in other SSAO demos, like this one: [PGDemo | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#N96NXC) (you can press 2 to render without SSAO and the difference is noticeable). But you can add an anti-aliasing post process to get the unjaggies back: [PGDemo | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#N96NXC#73) 😃

---

<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:** [March 23, 2022, 1:51pm UTC](https://forum.babylonjs.com/t/why-does-ssao-2-wreck-aa-for-me/28665/3 "2022-03-23T13:51:48Z")

</div>

This is because Render target by default do not support MSAA.

I wonder if @CraigFeldspar is aware of a property to enable it in his great SSAO2 ???

---

<div class="post-metadata">

**Author:** ![brechindo](https://avatars.discourse-cdn.com/v4/letter/b/e95f7d/32.png) [@brechindo](https://forum.babylonjs.com/u/brechindo)\
**Post date:** [March 23, 2022, 4:17pm UTC](https://forum.babylonjs.com/t/why-does-ssao-2-wreck-aa-for-me/28665/4 "2022-03-23T16:17:34Z")

</div>

Thank you for the suggestion, but adding the AA post-process per that demo seems to help only a little. The jaggies from SSAO are just too brutal for some reason. (That demo runs fine on this machine though.)

![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/c/8/c8a8df57c5e6311be325b8da7358dd206c6d1e92.jpeg)

Values copied straight from the PGDemo:

```auto
    var ssao = new SSAORenderingPipeline("ssaopipeline", scene, {ssaoRatio: .5, combineRatio: 1});
    ssao.fallOff = 1e-6;
    ssao.area = 1;
    ssao.radius = 4e-4;
    ssao.totalStrength = 1;
    ssao.base = 0.5;
    scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline("ssaopipeline", camera);

    var pipeline = new DefaultRenderingPipeline(
        "defaultPipeline", // The name of the pipeline
        true, // Do you want the pipeline to use HDR texture?
        scene, // The scene instance
        [camera] // The list of cameras to be attached to
    );
    pipeline.samples = 16;
    pipeline.fxaaEnabled = true;

```

---

<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:** [March 23, 2022, 4:44pm UTC](https://forum.babylonjs.com/t/why-does-ssao-2-wreck-aa-for-me/28665/5 "2022-03-23T16:44:06Z")

</div>

Using 2 pipelines here won t help. The source needs to be multi sampled for the best effect.

You can try relying on SSAO2 (webgl2 only) and bump the MSAA number of samples: [https://playground.babylonjs.com/#N96NXC#75](https://playground.babylonjs.com/#N96NXC#75)

---

<div class="post-metadata">

**Author:** ![brechindo](https://avatars.discourse-cdn.com/v4/letter/b/e95f7d/32.png) [@brechindo](https://forum.babylonjs.com/u/brechindo)\
**Post date:** [March 23, 2022, 6:03pm UTC](https://forum.babylonjs.com/t/why-does-ssao-2-wreck-aa-for-me/28665/6 "2022-03-23T18:03:19Z")

</div>

Copied the SSAO2 setup per your link exactly, but that simply breaks Scene.LoadAssetContainer() with a repeated warning, and results in a black screen.

> 52 [.WebGL-000033DA0163FF00] GL\_INVALID\_OPERATION: Cannot generate mipmaps for a zero-size texture in a WebGL context.

```auto
    var ssao = new SSAO2RenderingPipeline("ssaopipeline", scene, {ssaoRatio: .5, combineRatio: 1}, [camera], false );
    ssao.radius = 15.5;
    ssao.totalStrength = 1.3;
    ssao.expensiveBlur = false;
    ssao.samples = 16;
    scene.prePassRenderer.samples = 16;

```

We’ve noticed the problem seems to begin with our high-contrast skybox (dense rows of ceiling-mounted shop lights) and the model’s highly-reflective horizontal surfaces, creating the high-contrast reflection that SSAO only makes worse. It may be a dodge, but we’re going to swap the skybox for something less challenging and see.

---

<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:** [March 23, 2022, 6:10pm UTC](https://forum.babylonjs.com/t/why-does-ssao-2-wreck-aa-for-me/28665/7 "2022-03-23T18:10:06Z")

</div>

This is really weird it is trying to generate mipmaps for a 0 size texture ☹ a repro in the playground would help on this one.

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [April 14, 2022, 11:42am UTC](https://forum.babylonjs.com/t/why-does-ssao-2-wreck-aa-for-me/28665/8 "2022-04-14T11:42:02Z")

</div>

Hey there @brechindo just checking in, did you manage to solve the problem? Anything you’d like us to help with?

---

<div class="post-metadata">

**Author:** ![brechindo](https://avatars.discourse-cdn.com/v4/letter/b/e95f7d/32.png) [@brechindo](https://forum.babylonjs.com/u/brechindo)\
**Post date:** [April 14, 2022, 4:03pm UTC](https://forum.babylonjs.com/t/why-does-ssao-2-wreck-aa-for-me/28665/9 "2022-04-14T16:03:53Z")

</div>

Afraid not. We were able to tone down the problem with a lower-contrast skybox, so we’re living with that result for now. May revisit this problem later when doing final product polish prior to release.

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [April 14, 2022, 4:14pm UTC](https://forum.babylonjs.com/t/why-does-ssao-2-wreck-aa-for-me/28665/10 "2022-04-14T16:14:42Z")

</div>

Feel free to reach out anytime you’d like some help 🙂

---

<div class="post-metadata">

**Author:** ![brechindo](https://avatars.discourse-cdn.com/v4/letter/b/e95f7d/32.png) [@brechindo](https://forum.babylonjs.com/u/brechindo)\
**Post date:** [June 22, 2022, 9:56pm UTC](https://forum.babylonjs.com/t/why-does-ssao-2-wreck-aa-for-me/28665/11 "2022-06-22T21:56:25Z")

</div>

Months later, this case has been cracked.

```
ssao.samples = 16;
scene.prePassRenderer!.samples = 16; // OHHH!

```

The SSAO render pipeline disabled MSAA by default.  
The SSAO samples var is not MSAA samples - that’s completely different now, and accessed via the 2nd line above through the prePassRenderer.

SSAO and MSAA are happy now. Jaggies gone.  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/3/7/37e2604746b8a831d18b3935c2190805fd2296b7.jpeg)
