Viewer
    Preparing search index...

    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 Summary)

    Index

    Constructors

    • Constructs a new SSAO effect.

      Parameters

      • Optionalcamera: Camera

        The main camera.

      • OptionalnormalBuffer: Texture

        A texture that contains the scene normals.

      • Optionaloptions: {
            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.

        • Optionalbias?: number

          An occlusion bias. Eliminates artifacts caused by depth discontinuities.

        • OptionalblendFunction?: BlendFunction

          The blend function of this effect.

        • Optionalcolor?: Color

          The color of the ambient occlusion.

        • OptionaldepthAwareUpsampling?: boolean

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

        • OptionaldistanceFalloff?: number

          Deprecated.

        • OptionaldistanceScaling?: boolean

          Deprecated.

        • OptionaldistanceThreshold?: number

          Deprecated.

        • Optionalfade?: number

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

        • Optionalheight?: number

          Deprecated. Use resolutionY instead.

        • Optionalintensity?: number

          The intensity of the ambient occlusion.

        • OptionalluminanceInfluence?: number

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

        • OptionalminRadiusScale?: number

          The minimum radius scale.

        • OptionalnormalDepthBuffer?: Texture

          Deprecated.

        • Optionalradius?: number

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

        • OptionalrangeFalloff?: number

          Deprecated.

        • OptionalrangeThreshold?: number

          Deprecated.

        • OptionalresolutionScale?: number

          The resolution scale.

        • OptionalresolutionX?: number

          The horizontal resolution.

        • OptionalresolutionY?: number

          The vertical resolution.

        • Optionalrings?: number

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

        • Optionalsamples?: number

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

        • Optionalwidth?: number

          Deprecated. Use resolutionX instead.

        • OptionalworldDistanceFalloff?: number

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

        • OptionalworldDistanceThreshold?: number

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

        • OptionalworldProximityFalloff?: number

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

        • OptionalworldProximityThreshold?: number

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

      Returns SSAOEffect

      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.

    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: Color): void

      Parameters

      • arg: Color

      Returns void

    • get depthAwareUpsampling(): boolean

      Indicates whether depth-aware upsampling is enabled.

      Returns boolean

    • set depthAwareUpsampling(arg: boolean): void

      Parameters

      • arg: boolean

      Returns void

    • get distanceScaling(): boolean

      Indicates whether distance-based radius scaling is enabled.

      Returns boolean

      Use ssaoMaterial.distanceScaling instead.

    • set distanceScaling(arg: boolean): void

      Parameters

      • arg: boolean

      Returns void

    • get inputColorSpace(): ColorSpace
      Experimental

      The input color space.

      Returns ColorSpace

    • set inputColorSpace(arg: ColorSpace): void
      Protected Experimental

      Parameters

      • arg: ColorSpace

      Returns void

    • get intensity(): number

      The intensity.

      Returns number

    • set intensity(arg: number): void

      Parameters

      • arg: number

      Returns void

    • get luminanceInfluence(): boolean

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

      Returns boolean

    • set luminanceInfluence(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • set mainCamera(arg: Camera): void

      Sets the main camera.

      Parameters

      • arg: Camera

      Returns void

    • set mainScene(arg: Scene): void

      Sets the main scene.

      Parameters

      • arg: Scene

      Returns void

    • get normalBuffer(): Texture | null

      Sets the normal buffer.

      Returns Texture | null

    • set normalBuffer(value: Texture | null): void

      Parameters

      • value: Texture | null

      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: ColorSpace): void
      Protected Experimental

      Parameters

      • arg: ColorSpace

      Returns void

    • get radius(): number

      The occlusion sampling radius.

      Returns number

      Use ssaoMaterial.radius instead.

    • set radius(arg: number): void

      Parameters

      • arg: number

      Returns void

    • get rings(): number

      The amount of spiral turns in the occlusion sampling pattern.

      Returns number

      Use ssaoMaterial.rings instead.

    • set rings(arg: number): void

      Parameters

      • arg: number

      Returns void

    • get samples(): number

      The amount of occlusion samples per pixel.

      Returns number

      Use ssaoMaterial.samples instead.

    • set samples(arg: number): void

      Parameters

      • arg: number

      Returns void

    • get ssaoMaterial(): SSAOMaterial

      The SSAO material.

      Returns SSAOMaterial

    Methods

    • Adds a listener to an event type.

      Type Parameters

      • T extends keyof Event<string, unknown>

      Parameters

      • type: T

        The type of event to listen to.

      • listener: EventListener<Event<string, unknown>[T], T, SSAOEffect>

        The function that gets called when the event is fired.

      Returns void

    • Adds a listener to an event type.

      Type Parameters

      • T extends string

      Parameters

      • type: T

        The type of event to listen to.

      • listener: EventListener<{}, T, SSAOEffect>

        The function that gets called when the event is fired.

      Returns void

    • Fire an event type.

      Type Parameters

      • T extends keyof Event<string, unknown>

      Parameters

      • event: BaseEvent<T> & Event<string, unknown>[T]

        The event that gets fired.

      Returns void

    • 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 effect attributes.

      Returns EffectAttribute

      The attributes.

    • 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.

      Use blendMode instead.

    • Returns the color of the ambient occlusion.

      Returns Color

      The color.

      Use color instead.

    • Returns the preprocessor macro definitions.

      Returns Map<string, string>

      The extensions.

      Use defines instead.

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

      Returns Set<WebGLExtension>

      The extensions.

      Use extensions instead.

    • Returns the fragment shader.

      Returns string

      The fragment shader.

    • Returns the name of this effect.

      Returns string

      The name.

      Use name instead.

    • Returns the resolution settings.

      Returns Resolution

      The resolution.

      Use resolution instead.

    • Returns the SSAO material.

      Returns SSAOMaterial

      The material.

      Use ssaoMaterial instead.

    • Returns the uniforms of this effect.

      Returns Map<string, Uniform<any>>

      The extensions.

      Use uniforms instead.

    • Returns the vertex shader.

      Returns string

      The vertex shader.

    • Checks if listener is added to an event type.

      Type Parameters

      • T extends keyof Event<string, unknown>

      Parameters

      • type: T

        The type of event to listen to.

      • listener: EventListener<Event<string, unknown>[T], T, SSAOEffect>

        The function that gets called when the event is fired.

      Returns boolean

    • Checks if listener is added to an event type.

      Type Parameters

      • T extends string

      Parameters

      • type: T

        The type of event to listen to.

      • listener: EventListener<{}, T, SSAOEffect>

        The function that gets called when the event is fired.

      Returns boolean

    • 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

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

      Returns boolean

      Whether depth-aware upsampling is enabled.

      Use depthAwareUpsampling instead.

    • Removes a listener from an event type.

      Type Parameters

      • T extends keyof Event<string, unknown>

      Parameters

      • type: T

        The type of the listener that gets removed.

      • listener: EventListener<Event<string, unknown>[T], T, SSAOEffect>

        The listener function that gets removed.

      Returns void

    • Removes a listener from an event type.

      Type Parameters

      • T extends string

      Parameters

      • type: T

        The type of the listener that gets removed.

      • listener: EventListener<{}, T, SSAOEffect>

        The listener function that gets removed.

      Returns void

    • 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

      • attributes: EffectAttribute

        The attributes.

      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

      Use color instead.

    • Enables or disables depth-aware upsampling.

      Parameters

      • value: boolean

        Whether depth-aware upsampling should be enabled.

      Returns void

      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.

      • OptionaldepthPacking: 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

      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

      Use ssaoMaterial instead.

    • Sets the renderer.

      Parameters

      • renderer: WebGLRenderer

        The renderer.

      Returns void

    • 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

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

      • OptionaldeltaTime: number

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

      Returns void