Enabling SSAO

Beginner Getting started

In About render passes you have learnt how render passes work in BBMOD and how important they are for various effects. In this tutorial we will have a look at how to enable screen-space ambient occlusion (SSAO) using the default renderer and the DepthOnly render pass.

Contents

Enabling G-buffer

Since BBMOD needs to run on so many platforms, its default rendering pipeline is a simple forward renderer. Forward rendering means that the scene is shaded during rasterization of vertex data in a single pass. You might have also heard about deferred rendering, where the vertex (depth, velocity, ...) and material data (base color, normal, metallic, roughness, ...) is first output into a collection of surfaces (usually 4, but every engine can use its own version based on its needs) in one pass and then the scene is shaded in screen-space in another pass. This collection of surfaces is commonly referred to as "geometry buffers" or just "G-buffers". Some rendering techniques, like SSAO, do require the G-buffer and so you will first need to enable it. The default renderer has a really thin G-buffer - only a single surface with just the scene depth. To enable it, simply set its EnableGBuffer property to true:

renderer = new BBMOD_DefaultRenderer();
renderer.EnableGBuffer = true;

Please note that when you do this, almost the entire scene is rendered twice - first in the DepthOnly render pass and then in the Forward render pass - doubling the number of draw calls! Therefore using the G-buffer and effects that rely on it is not recommended for platforms like mobile or browsers, where the performance hit could be too hard! Compiling your game with YYC is recommended for better performance.

Tip: You can use GM's built-in variables os_type and os_browser to check on which platform is your game running and use that to disable certain effects.

Configuring materials

When the G-buffer is enabled, for each opaque material, you need to configure which shader the material uses during the DepthOnly render pass. This can be done using the set_shader method. Since what the DepthOnly render pass generates is a depth buffer, you need to use a shader that outputs depth. You can use shader BBMOD_SHADER_DEFAULT_DEPTH for this purpose.

material = BBMOD_MATERIAL_DEFAULT.clone();
material.set_shader(BBMOD_ERenderPass.DepthOnly, BBMOD_SHADER_DEFAULT_DEPTH);

Enabling SSAO

Finally, you can enable SSAO by setting the default renderer's EnableSSAO property to true:

renderer.EnableSSAO = true;

There are also other properties, like for example SSAORadius and SSAOPower, using which you can configure the range and the strength of the effect:

renderer.SSAORadius = 32;
renderer.SSAOPower = 2;

Also, by default the SSAO is rendered in full resolution for maximum quality. For better performance, you could render the SSAO at half resolution by setting the SSAOScale property to 1/2:

renderer.SSAOScale = 0.5;

Please have a look at the default renderer's documentation for a full list of properties related to SSAO.

Could not find what you were looking for?

We are still working on more tutorials. If you need additional help with BBMOD, please have a look at the documentation or join our Discord community. Thank you for your patience.

Support the development

Support us in developing BBMOD, get priority assistance and more of our amazing tools as a reward!

Become Patron

Don't miss out on a thing!

Create an account, subscribe to newsletter and get notified on new releases, tutorials and special offers.

Register Log in