SSAO Occlusion mask

Hi all, sorry no PG example yet but wanted to get some psudocode going for a technique im exploring for rendering SSAO with a mask. This topic has been touched on in several other areas without a clear solution so figured id open up a discussion.

I am using SSAO2 and it looks great but I want to mask out certain parts of the model from not being affected by SSAO2 such as transparent areas. Yes i could flag them to not render to depth but that solution isnt very robust for my use case. (we’re trying to render transparent stuff and dont want SSAO to affect that)

So thinking of this from a compositing perspective, what I want is to flag certain objects as “accepting AO” and those objects render in a pass and serves as the “alpha” to the AO texture. Then the AO texture is composited with the scene with the given alpha. Im still new ish to multi-pass rendering in BJS so I guess my question is whats the steps to do this? Do I need to set up a custom post process to render the mask, and then feed that texture into the SSAO shader. How do I pass the alpha into the SSAO shader? Seems to me I may need to extend the SSAO shader, if so is using a material plugin the best way to do this?

1 Like

@sebavan, @Evgeni_Popov thoughts?

My problem is similar to this!

I have a glow + bloom, but when I add SSAO, it kind of ruins the glowing object.

The DefaultRenderingPipeline (glow and bloom) is added after the SSAO.

Glow has an exclusion list, but this would not solve my problem because I do want SSAO on this mesh, except the glowing parts. Also transparent parts of some meshes, same problem!

If you see my outline shader, it is excluded with the glow layer texture!

like this:

effect.setTexture("glowSampler", this.defaultpipeline.glowLayer.mainTexture)

One way of doing this is to force the use of the geometry buffer renderer, and add to it only those meshes that are to undergo SSAO :

interesting! Are there any caveats to gbr renderer? Also im getting an error…
scene.enableGeometryBufferRenderer is not a function

Does not seem to be defined either:

What am I missing?

we’re using ES6 imports… are there any side effects to be aware of?


You have to import "@babylon/core/Rendering/geometryBufferRendererSceneComponent" to make the geometry buffer renderer available through the scene.

The main caveat is that it is using its own vertex shader, so if you modify the vertices in a custom way in your vertex shader (morph, skeletal animations are supported), these changes won’t show up in the buffers generated by the geometry buffer renderer.