Home Reference Source
import {SSAOEffect} from 'postprocessing'
public class | source

SSAOEffect

Extends:

three~EventDispatcherEffect → SSAOEffect

Indirect Implements:

A Screen Space Ambient Occlusion effect.

Based on "Scalable Ambient Obscurance" by Morgan McGuire et al. and "Depth-aware upsampling experiments" by Eleni Maria Stea: https://research.nvidia.com/publication/scalable-ambient-obscurance https://eleni.mutantstargoat.com/hikiko/on-depth-aware-upsampling

The view position calculation is based on a shader by Norbert Nopper: https://github.com/McNopper/OpenGL/blob/master/Example28/shader/ssao.frag.glsl

Constructor Summary

Public Constructor
public

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

Constructs a new SSAO effect.

Member Summary

Public Members
public get

color: Color

The color of the ambient occlusion.

public set
public get

Indicates whether depth-aware upsampling is enabled.

public set
public get
this get was deprecated.

Indicates whether distance-based radius scaling is enabled.

public set
public get

The intensity.

public set
public get

The luminance influence factor.

public set
public set
public get

normalBuffer: Texture

Sets the normal buffer.

public set
public get
this get was deprecated. Use ssaoMaterial.radius instead.

The occlusion sampling radius.

public set
public get
this get was deprecated. Use ssaoMaterial.rings instead.

The amount of spiral turns in the occlusion sampling pattern.

public set
public get
this get was deprecated. Use ssaoMaterial.samples instead.

The amount of occlusion samples per pixel.

public set
public get

The SSAO material.

Method Summary

Public Methods
public

getColor(): Color

this method was deprecated. Use color instead.

Returns the color of the ambient occlusion.

public
this method was deprecated. Use resolution instead.

Returns the resolution settings.

public
this method was deprecated. Use ssaoMaterial instead.

Returns the SSAO material.

public

initialize(renderer: WebGLRenderer, alpha: Boolean, frameBufferType: Number)

Performs initialization tasks.

public
this method was deprecated. Use depthAwareUpsampling instead.

Indicates whether depth-aware upsampling is enabled.

public

setColor(value: Color)

this method was deprecated. Use color instead.

Sets the color of the ambient occlusion.

public
this method was deprecated. Use depthAwareUpsampling instead.

Enables or disables depth-aware upsampling.

public

setDepthTexture(depthTexture: Texture, depthPacking: DepthPackingStrategies)

Sets the depth texture.

public

setDistanceCutoff(threshold: Number, falloff: Number)

this method was deprecated. Use ssaoMaterial instead.

Sets the occlusion distance cutoff.

public

setProximityCutoff(threshold: Number, falloff: Number)

this method was deprecated. Use ssaoMaterial instead.

Sets the occlusion proximity cutoff.

public

setSize(width: Number, height: Number)

Sets the size.

public

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

Updates this effect.

Inherited Summary

From class Effect
public get

inputColorSpace: ColorSpace

this get is experimental.

The input color space.

public set

mainCamera: Camera

Sets the main camera.

public set

mainScene: Scene

Sets the main scene.

public get

outputColorSpace: ColorSpace

this get is experimental.

The output color space.

protected set

inputColorSpace: ColorSpace

this set is experimental.
protected set

outputColorSpace: ColorSpace

this set is experimental.
public

The blend mode of this effect.

public

Preprocessor macro definitions.

public

WebGL extensions that are required by this effect.

public

The name of this effect.

public

uniforms: Map<String, Uniform>

Shader uniforms.

protected

renderer: WebGLRenderer

this member was deprecated.

The renderer.

public

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

public

Returns the effect attributes.

public
this method was deprecated. Use blendMode instead.

Returns the blend mode.

public
this method was deprecated. Use defines instead.

Returns the preprocessor macro definitions.

public
this method was deprecated. Use extensions instead.

Returns the WebGL extensions that are required by this effect.

public

Returns the fragment shader.

public
this method was deprecated. Use name instead.

Returns the name of this effect.

public

getUniforms(): Map<String, Uniform>

this method was deprecated. Use uniforms instead.

Returns the uniforms of this effect.

public

Returns the vertex shader.

public

initialize(renderer: WebGLRenderer, alpha: Boolean, frameBufferType: Number)

Performs initialization tasks.

public

setDepthTexture(depthTexture: Texture, depthPacking: DepthPackingStrategies)

Sets the depth texture.

public

setRenderer(renderer: WebGLRenderer)

this method was deprecated.

Sets the renderer.

public

setSize(width: Number, height: Number)

Updates the size of this effect.

public

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

Updates this effect by performing supporting operations.

protected

Sets the effect attributes.

protected

Informs the associated EffectPass that this effect requires a shader recompilation.

protected

setFragmentShader(fragmentShader: String)

Sets the fragment shader.

protected

setVertexShader(vertexShader: String)

Sets the vertex shader.

Public Constructors

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

Constructs a new SSAO effect.

Override:

Effect#constructor

Params:

NameTypeAttributeDescription
camera Camera
  • optional

The main camera.

normalBuffer Texture
  • optional

A texture that contains the scene normals.

options Object
  • optional

The options.

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

The blend function of this effect.

options.distanceScaling Boolean
  • optional
  • default: true

Deprecated.

options.depthAwareUpsampling Boolean
  • optional
  • default: true

Enables or disables depth-aware upsampling. Has no effect if WebGL 2 is not supported.

options.normalDepthBuffer Texture
  • optional
  • default: null

Deprecated.

options.samples Number
  • optional
  • default: 9

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

options.rings Number
  • optional
  • default: 7

The amount of spiral turns in the occlusion sampling pattern. Should be a prime number.

options.worldDistanceThreshold Number
  • optional

The world distance threshold at which the occlusion effect starts to fade out.

options.worldDistanceFalloff Number
  • optional

The world distance falloff. Influences the smoothness of the occlusion cutoff.

options.worldProximityThreshold Number
  • optional

The world proximity threshold at which the occlusion starts to fade out.

options.worldProximityFalloff Number
  • optional

The world proximity falloff. Influences the smoothness of the proximity cutoff.

options.distanceThreshold Number
  • optional
  • default: 0.97

Deprecated.

options.distanceFalloff Number
  • optional
  • default: 0.03

Deprecated.

options.rangeThreshold Number
  • optional
  • default: 0.0005

Deprecated.

options.rangeFalloff Number
  • optional
  • default: 0.001

Deprecated.

options.minRadiusScale Number
  • optional
  • default: 0.1

The minimum radius scale.

options.luminanceInfluence Number
  • optional
  • default: 0.7

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

options.radius Number
  • optional
  • default: 0.1825

The occlusion sampling radius, expressed as a scale relative to the resolution. Range [1e-6, 1.0].

options.intensity Number
  • optional
  • default: 1.0

The intensity of the ambient occlusion.

options.bias Number
  • optional
  • default: 0.025

An occlusion bias. Eliminates artifacts caused by depth discontinuities.

options.fade Number
  • optional
  • default: 0.01

Influences the smoothness of the shadows. A lower value results in higher contrast.

options.color Color
  • optional
  • default: null

The color of the ambient occlusion.

options.resolutionScale Number
  • optional
  • default: 1.0

The resolution scale.

options.resolutionX Number
  • optional
  • default: Resolution.AUTO_SIZE

The horizontal resolution.

options.resolutionY Number
  • optional
  • default: Resolution.AUTO_SIZE

The vertical resolution.

options.width Number
  • optional
  • default: Resolution.AUTO_SIZE

Deprecated. Use resolutionX instead.

options.height Number
  • optional
  • default: Resolution.AUTO_SIZE

Deprecated. Use resolutionY instead.

TODO:

  • Move normalBuffer to options.

Public Members

public get color: Color source

The color of the ambient occlusion. Set to null to disable.

public set color source

public get depthAwareUpsampling: Boolean source

Indicates whether depth-aware upsampling is enabled.

public set depthAwareUpsampling source

public get distanceScaling: Boolean source

this get was deprecated.

Indicates whether distance-based radius scaling is enabled.

public set distanceScaling source

public get intensity: Number source

The intensity.

public set intensity source

public get luminanceInfluence: Boolean source

The luminance influence factor. Range: [0.0, 1.0].

public set luminanceInfluence source

public set mainCamera source

Sets the main camera.

Override:

Effect#mainCamera

public get normalBuffer: Texture source

Sets the normal buffer.

public set normalBuffer source

public get radius: Number source

this get was deprecated. Use ssaoMaterial.radius instead.

The occlusion sampling radius.

public set radius source

public get rings: Number source

this get was deprecated. Use ssaoMaterial.rings instead.

The amount of spiral turns in the occlusion sampling pattern.

public set rings source

public get samples: Number source

this get was deprecated. Use ssaoMaterial.samples instead.

The amount of occlusion samples per pixel.

public set samples source

public get ssaoMaterial: SSAOMaterial source

The SSAO material.

Public Methods

public getColor(): Color source

this method was deprecated. Use color instead.

Returns the color of the ambient occlusion.

Return:

Color

The color.

public getResolution(): Resolution source

this method was deprecated. Use resolution instead.

Returns the resolution settings.

Return:

Resolution

The resolution.

public getSSAOMaterial(): SSAOMaterial source

this method was deprecated. Use ssaoMaterial instead.

Returns the SSAO material.

Return:

SSAOMaterial

The material.

public initialize(renderer: WebGLRenderer, alpha: Boolean, frameBufferType: Number) source

Performs initialization tasks.

Override:

Effect#initialize

Params:

NameTypeAttributeDescription
renderer WebGLRenderer

The renderer.

alpha Boolean

Whether the renderer uses the alpha channel or not.

frameBufferType Number

The type of the main frame buffers.

public isDepthAwareUpsamplingEnabled(): Boolean source

this method was deprecated. Use depthAwareUpsampling instead.

Indicates whether depth-aware upsampling is enabled.

Return:

Boolean

Whether depth-aware upsampling is enabled.

public setColor(value: Color) source

this method was deprecated. Use color instead.

Sets the color of the ambient occlusion. Set to null to disable colorization.

Params:

NameTypeAttributeDescription
value Color

The color.

public setDepthAwareUpsamplingEnabled(value: Boolean) source

this method was deprecated. Use depthAwareUpsampling instead.

Enables or disables depth-aware upsampling.

Params:

NameTypeAttributeDescription
value Boolean

Whether depth-aware upsampling should be enabled.

public setDepthTexture(depthTexture: Texture, depthPacking: DepthPackingStrategies) source

Sets the depth texture.

Override:

Effect#setDepthTexture

Params:

NameTypeAttributeDescription
depthTexture Texture

A depth texture.

depthPacking DepthPackingStrategies
  • optional
  • default: BasicDepthPacking

The depth packing.

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

this method was deprecated. Use ssaoMaterial instead.

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

this method was deprecated. Use ssaoMaterial instead.

Sets the occlusion proximity cutoff.

Params:

NameTypeAttributeDescription
threshold Number

The proximity threshold. Range [0.0, 1.0].

falloff Number

The falloff. Range [0.0, 1.0].

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

Sets the size.

Override:

Effect#setSize

Params:

NameTypeAttributeDescription
width Number

The width.

height Number

The height.

public update(renderer: WebGLRenderer, inputBuffer: WebGLRenderTarget, deltaTime: Number) source

Updates this effect.

Override:

Effect#update

Params:

NameTypeAttributeDescription
renderer WebGLRenderer

The renderer.

inputBuffer WebGLRenderTarget

A frame buffer that contains the result of the previous pass.

deltaTime Number
  • optional

The time between the last frame and the current one in seconds.