Home Reference Source
import {SSAOEffect} from 'postprocessing/src/effects/SSAOEffect.js'
public class | source

SSAOEffect

Extends:

Effect → SSAOEffect

Indirect Implements:

A Screen Space Ambient Occlusion (SSAO) effect.

SSAO is a method to approximate ambient occlusion in screen space.

For high quality visuals use two SSAO effect instances in a row with different radii, one for rough AO and one for fine details.

This implementation uses a discrete spiral sampling pattern: https://jsfiddle.net/a16ff1p7

Constructor Summary

Public Constructor
public

constructor(camera: Camera, normalBuffer: Texture, options: Object)

Constructs a new SSAO effect.

Member Summary

Public Members
public get

The occlusion sampling radius.

public set

Sets the occlusion sampling radius.

public get

The amount of rings in the occlusion sampling spiral pattern.

public set

Sets the amount of rings in the occlusion sampling spiral pattern.

public get

The amount of occlusion samples per pixel.

public set

Sets the amount of occlusion samples per pixel.

Private Members
private

camera: Camera

The main camera.

private

The current sampling radius.

private

resolution: Vector2

The current resolution.

Method Summary

Public Methods
public

setDistanceCutoff(threshold: Number, falloff: Number)

Sets the occlusion distance cutoff.

public

setProximityCutoff(threshold: Number, falloff: Number)

Sets the occlusion proximity cutoff.

public

setSize(width: Number, height: Number)

Updates the camera projection matrix uniforms.

Private Methods
private

Updates the angle step constant.

private

Updates the radius step uniform.

Inherited Summary

From class Effect
public

[key]: *

public

The effect attributes.

public

The blend mode of this effect.

public

Preprocessor macro definitions.

public

The fragment shader.

public

The name of this effect.

public

uniforms: Map<String, Uniform>

Shader uniforms.

public

The vertex shader.

public

Performs a shallow search for properties that define a dispose method and deletes them.

public

initialize(renderer: WebGLRenderer, alpha: Boolean)

Performs initialization tasks.

public

setDepthTexture(depthTexture: Texture, depthPacking: Number)

Sets the depth texture.

public

setSize(width: Number, height: Number)

Updates the size of this effect.

public

update(renderer: WebGLRenderer, inputBuffer: WebGLRenderTarget, delta: Number)

Updates the effect by performing supporting operations.

Public Constructors

public constructor(camera: Camera, normalBuffer: Texture, options: Object) source

Constructs a new SSAO effect.

Override:

Effect#constructor

Params:

NameTypeAttributeDescription
camera Camera

The main camera.

normalBuffer Texture

A texture that contains the scene normals. See NormalPass.

options Object
  • optional

The options.

options.blendFunction BlendFunction
  • optional
  • default: BlendFunction.MULTIPLY

The blend function of this effect.

options.samples Number
  • optional
  • default: 11

The amount of samples per pixel. Should not be a multiple of the ring count.

options.rings Number
  • optional
  • default: 4

The amount of rings in the occlusion sampling pattern.

options.distanceThreshold Number
  • optional
  • default: 0.65

A global distance threshold at which the occlusion effect starts to fade out. Range [0.0, 1.0].

options.distanceFalloff Number
  • optional
  • default: 0.1

The distance falloff. Influences the smoothness of the overall occlusion cutoff. Range [0.0, 1.0].

options.rangeThreshold Number
  • optional
  • default: 0.0015

A local occlusion range threshold at which the occlusion starts to fade out. Range [0.0, 1.0].

options.rangeFalloff Number
  • optional
  • default: 0.01

The occlusion range falloff. Influences the smoothness of the proximity cutoff. Range [0.0, 1.0].

options.luminanceInfluence Number
  • optional
  • default: 0.7

Determines how much the luminance of the scene influences the ambient occlusion.

options.radius Number
  • optional
  • default: 18.25

The occlusion sampling radius.

options.scale Number
  • optional
  • default: 1.0

The scale of the ambient occlusion.

options.bias Number
  • optional
  • default: 0.5

An occlusion bias.

Public Members

public get radius: Number source

The occlusion sampling radius.

public set radius: Number source

Sets the occlusion sampling radius.

public get rings: Number source

The amount of rings in the occlusion sampling spiral pattern.

public set rings: Number source

Sets the amount of rings in the occlusion sampling spiral pattern.

You'll need to call EffectPass#recompile after changing this value.

public get samples: Number source

The amount of occlusion samples per pixel.

public set samples: Number source

Sets the amount of occlusion samples per pixel.

You'll need to call EffectPass#recompile after changing this value.

Private Members

private camera: Camera source

The main camera.

private r: Number source

The current sampling radius.

private resolution: Vector2 source

The current resolution.

Public Methods

public setDistanceCutoff(threshold: Number, falloff: Number) source

Sets the occlusion distance cutoff.

Params:

NameTypeAttributeDescription
threshold Number

The distance threshold. Range [0.0, 1.0].

falloff Number

The falloff. Range [0.0, 1.0].

public setProximityCutoff(threshold: Number, falloff: Number) source

Sets the occlusion proximity cutoff.

Params:

NameTypeAttributeDescription
threshold Number

The range threshold. Range [0.0, 1.0].

falloff Number

The falloff. Range [0.0, 1.0].

public setSize(width: Number, height: Number) source

Updates the camera projection matrix uniforms.

Override:

Effect#setSize

Params:

NameTypeAttributeDescription
width Number

The width.

height Number

The height.

Private Methods

private updateAngleStep() source

Updates the angle step constant.

private updateRadiusStep() source

Updates the radius step uniform.

Note: The radius step is a uniform because it changes with the screen size.