Class SSAOEffect

A Screen Space Ambient Occlusion (SSAO) effect.

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 effect supports depth-aware upsampling and should be rendered at a lower resolution. The resolution should match that of the downsampled normals and depth. If you intend to render SSAO at full resolution, do not provide a downsampled normalDepthBuffer.

It's recommended to specify a relative render resolution using the resolutionScale constructor parameter to avoid undesired sampling patterns.

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

Hierarchy (view full)

Constructors

  • Constructs a new SSAO effect.

    Parameters

    • Optional camera: Camera

      The main camera.

    • Optional normalBuffer: Texture

      A texture that contains the scene normals.

    • Optional options: {
          bias?: number;
          blendFunction?: BlendFunction;
          color?: Color;
          depthAwareUpsampling?: boolean;
          distanceFalloff?: number;
          distanceScaling?: boolean;
          distanceThreshold?: number;
          fade?: number;
          height?: number;
          intensity?: number;
          luminanceInfluence?: number;
          minRadiusScale?: number;
          normalDepthBuffer?: Texture;
          radius?: number;
          rangeFalloff?: number;
          rangeThreshold?: number;
          resolutionScale?: number;
          resolutionX?: number;
          resolutionY?: number;
          rings?: number;
          samples?: number;
          width?: number;
          worldDistanceFalloff?: number;
          worldDistanceThreshold?: number;
          worldProximityFalloff?: number;
          worldProximityThreshold?: number;
      }

      The options.

      • Optional bias?: number

        An occlusion bias. Eliminates artifacts caused by depth discontinuities.

      • Optional blendFunction?: BlendFunction

        The blend function of this effect.

      • Optional color?: Color

        The color of the ambient occlusion.

      • Optional depthAwareUpsampling?: boolean

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

      • Optional distanceFalloff?: number

        Deprecated.

      • Optional distanceScaling?: boolean

        Deprecated.

      • Optional distanceThreshold?: number

        Deprecated.

      • Optional fade?: number

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

      • Optional height?: number

        Deprecated. Use resolutionY instead.

      • Optional intensity?: number

        The intensity of the ambient occlusion.

      • Optional luminanceInfluence?: number

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

      • Optional minRadiusScale?: number

        The minimum radius scale.

      • Optional normalDepthBuffer?: Texture

        Deprecated.

      • Optional radius?: number

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

      • Optional rangeFalloff?: number

        Deprecated.

      • Optional rangeThreshold?: number

        Deprecated.

      • Optional resolutionScale?: number

        The resolution scale.

      • Optional resolutionX?: number

        The horizontal resolution.

      • Optional resolutionY?: number

        The vertical resolution.

      • Optional rings?: number

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

      • Optional samples?: number

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

      • Optional width?: number

        Deprecated. Use resolutionX instead.

      • Optional worldDistanceFalloff?: number

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

      • Optional worldDistanceThreshold?: number

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

      • Optional worldProximityFalloff?: number

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

      • Optional worldProximityThreshold?: number

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

    Returns SSAOEffect

    Todo

    Move normalBuffer to options.

Properties

blendMode: BlendMode

The blend mode of this effect.

defines: Map<string, string>

Preprocessor macro definitions.

Call Effect.setChanged after changing macro definitions.

extensions: Set<WebGLExtension>

WebGL extensions that are required by this effect.

Call Effect.setChanged after adding or removing extensions.

name: string

The name of this effect.

renderer: WebGLRenderer

The renderer.

Deprecated

resolution: Resolution
uniforms: Map<string, Uniform<any>>

Shader uniforms.

Call Effect.setChanged after adding or removing uniforms.

Accessors

  • get color(): Color
  • The color of the ambient occlusion. Set to null to disable.

    Returns Color

  • set color(arg): void
  • Parameters

    • arg: Color

    Returns void

  • get depthAwareUpsampling(): boolean
  • Indicates whether depth-aware upsampling is enabled.

    Returns boolean

  • set depthAwareUpsampling(arg): void
  • Parameters

    • arg: boolean

    Returns void

  • get distanceScaling(): boolean
  • Indicates whether distance-based radius scaling is enabled.

    Returns boolean

    Deprecated

    Use ssaoMaterial.distanceScaling instead.

  • set distanceScaling(arg): void
  • Parameters

    • arg: boolean

    Returns void

  • get inputColorSpace(): ColorSpace
  • Experimental

    The input color space.

    Returns ColorSpace

  • set inputColorSpace(arg): void
  • Protected Experimental

    Parameters

    • arg: ColorSpace

    Returns void

  • get intensity(): number
  • The intensity.

    Returns number

  • set intensity(arg): void
  • Parameters

    • arg: number

    Returns void

  • get luminanceInfluence(): boolean
  • The luminance influence factor. Range: [0.0, 1.0].

    Returns boolean

  • set luminanceInfluence(value): void
  • Parameters

    • value: boolean

    Returns void

  • set mainCamera(arg): void
  • Sets the main camera.

    Parameters

    • arg: Camera

    Returns void

  • set mainScene(arg): void
  • Sets the main scene.

    Parameters

    • arg: Scene

    Returns void

  • get normalBuffer(): Texture
  • Sets the normal buffer.

    Returns Texture

  • set normalBuffer(value): void
  • Parameters

    • value: Texture

    Returns void

  • get outputColorSpace(): ColorSpace
  • Experimental

    The output color space.

    Should only be changed if this effect converts the input colors to a different color space.

    Returns ColorSpace

  • set outputColorSpace(arg): void
  • Protected Experimental

    Parameters

    • arg: ColorSpace

    Returns void

  • get radius(): number
  • The occlusion sampling radius.

    Returns number

    Deprecated

    Use ssaoMaterial.radius instead.

  • set radius(arg): void
  • Parameters

    • arg: number

    Returns void

  • get rings(): number
  • The amount of spiral turns in the occlusion sampling pattern.

    Returns number

    Deprecated

    Use ssaoMaterial.rings instead.

  • set rings(arg): void
  • Parameters

    • arg: number

    Returns void

  • get samples(): number
  • The amount of occlusion samples per pixel.

    Returns number

    Deprecated

    Use ssaoMaterial.samples instead.

  • set samples(arg): void
  • Parameters

    • arg: number

    Returns void

  • get ssaoMaterial(): SSAOMaterial
  • The SSAO material.

    Returns SSAOMaterial

Methods

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

    The EffectComposer calls this method when it is being destroyed.

    Returns void

  • Returns the blend mode.

    The result of this effect will be blended with the result of the previous effect using this blend mode.

    Returns BlendMode

    The blend mode.

    Deprecated

    Use blendMode instead.

  • Returns the color of the ambient occlusion.

    Returns Color

    The color.

    Deprecated

    Use color instead.

  • Returns the preprocessor macro definitions.

    Returns Map<string, string>

    The extensions.

    Deprecated

    Use defines instead.

  • Returns the WebGL extensions that are required by this effect.

    Returns Set<WebGLExtension>

    The extensions.

    Deprecated

    Use extensions instead.

  • Returns the fragment shader.

    Returns string

    The fragment shader.

  • Returns the name of this effect.

    Returns string

    The name.

    Deprecated

    Use name instead.

  • Returns the resolution settings.

    Returns Resolution

    The resolution.

    Deprecated

    Use resolution instead.

  • Returns the SSAO material.

    Returns SSAOMaterial

    The material.

    Deprecated

    Use ssaoMaterial instead.

  • Returns the uniforms of this effect.

    Returns Map<string, Uniform<any>>

    The extensions.

    Deprecated

    Use uniforms instead.

  • Returns the vertex shader.

    Returns string

    The vertex shader.

  • Performs initialization tasks.

    This method is called when the associated EffectPass is added to an EffectComposer.

    Parameters

    • renderer: WebGLRenderer

      The renderer.

    • alpha: boolean

      Whether the renderer uses the alpha channel or not.

    • frameBufferType: number

      The type of the main frame buffers.

    Returns void

    Example

    if(!alpha && frameBufferType === UnsignedByteType) { this.myRenderTarget.texture.format = RGBFormat; }
    
  • Indicates whether depth-aware upsampling is enabled.

    Returns boolean

    Whether depth-aware upsampling is enabled.

    Deprecated

    Use depthAwareUpsampling instead.

  • Protected

    Sets the effect attributes.

    Effects that have the same attributes will be executed in the order in which they were registered. Some attributes imply a higher priority.

    Parameters

    Returns void

  • Protected

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

    Should be called after changing macros or extensions and after adding/removing uniforms.

    Returns void

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

    Parameters

    • value: Color

      The color.

    Returns void

    Deprecated

    Use color instead.

  • Enables or disables depth-aware upsampling.

    Parameters

    • value: boolean

      Whether depth-aware upsampling should be enabled.

    Returns void

    Deprecated

    Use depthAwareUpsampling instead.

  • Sets the depth texture.

    You may override this method if your effect requires direct access to the depth texture that is bound to the associated EffectPass.

    Parameters

    • depthTexture: Texture

      A depth texture.

    • Optional depthPacking: DepthPackingStrategies

      The depth packing.

    Returns void

  • Sets the occlusion distance cutoff.

    Parameters

    • threshold: number

      The distance threshold. Range [0.0, 1.0].

    • falloff: number

      The falloff. Range [0.0, 1.0].

    Returns void

    Deprecated

    Use ssaoMaterial instead.

  • Protected

    Sets the fragment shader.

    Parameters

    • fragmentShader: string

      The fragment shader.

    Returns void

  • Sets the occlusion proximity cutoff.

    Parameters

    • threshold: number

      The proximity threshold. Range [0.0, 1.0].

    • falloff: number

      The falloff. Range [0.0, 1.0].

    Returns void

    Deprecated

    Use ssaoMaterial instead.

  • Sets the renderer.

    Parameters

    • renderer: WebGLRenderer

      The renderer.

    Returns void

    Deprecated

  • Sets the size.

    Parameters

    • width: number

      The width.

    • height: number

      The height.

    Returns void

  • Protected

    Sets the vertex shader.

    Parameters

    • vertexShader: string

      The vertex shader.

    Returns void

  • Updates this effect.

    Parameters

    • renderer: WebGLRenderer

      The renderer.

    • inputBuffer: WebGLRenderTarget<Texture>

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

    • Optional deltaTime: number

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

    Returns void