API

Using the SSAO Rendering Pipeline

BABYLON.SSAORenderingPipeline is a rendering pipeline (chained post-processes) that computes the ambient occlusion of a given scene from screen space. You can find an example in our playground:

SSAO Rendering Pipeline Example

The post-processes chain is defined by:

  • Original scene color post-process: saves the original scene color
  • SSAO post-process
  • Horizontal blur post-process
  • Vertical blur post-process
  • Combine post-process: blends the Vertical blur post-process output with the original scene color

Using it is pretty straightforward:

import { SSAORenderingPipeline } from "@babylonjs/core/PostProcesses/RenderPipeline/Pipelines/ssaoRenderingPipeline";
const ssao = new SSAORenderingPipeline("ssaopipeline", scene, 0.75);

The third argument is the ratio used by the SSAO, Horizontal blur, and Vertical blur post-processes. You can also set an array of cameras as the fourth argument. The constructor will then automatically attach the rendering pipeline to the given cameras:

import { SSAORenderingPipeline } from "@babylonjs/core/PostProcesses/RenderPipeline/Pipelines/ssaoRenderingPipeline";
const ssao = new SSAORenderingPipeline('ssaopipeline', scene, 0.75, [camera1 etc.]);

If you want to attach the rendering pipeline manually, use the scene rendering pipeline manager:

import { SSAORenderingPipeline } from "@babylonjs/core/PostProcesses/RenderPipeline/Pipelines/ssaoRenderingPipeline";
const ssao = new SSAORenderingPipeline("ssaopipeline", scene, 0.75);
scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline("ssaopipeline", cameras);

Warning: To improve performance, you should compute the SSAO/blurH/blurV with a ratio lower than 1.0.

If you want to detach and destroy the rendering pipeline, you can just call the dispose() method.

ssao.dispose();

You can see the SSAO post-process output by detaching the combine post-process like this:

scene.postProcessRenderPipelineManager.disableEffectInPipeline("ssaopipeline", ssao.SSAOCombineRenderEffect, cameras);

Note: SSAO uses the depth map renderer and activates it by default. You can disable the depth map renderer by passing true as the argument to the dispose() method.

For more customization, you can specify the SSAO and Combine post-process ratios like this:

import { SSAORenderingPipeline } from "@babylonjs/core/PostProcesses/RenderPipeline/Pipelines/ssaoRenderingPipeline";
const ssao = new SSAORenderingPipeline('ssaopipeline', scene, { ssaoRatio: 0.5, combineRatio: 1.0 }, [camera1 etc.]);