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

DepthOfFieldEffect

Extends:

three~EventDispatcherEffect → DepthOfFieldEffect

Indirect Implements:

A depth of field effect.

Based on a graphics study by Adrian Courrèges and an article by Steve Avery: https://www.adriancourreges.com/blog/2016/09/09/doom-2016-graphics-study/ https://pixelmischiefblog.wordpress.com/2016/11/25/bokeh-depth-of-field/

Constructor Summary

Public Constructor
public

constructor(camera: Camera, options: Object)

Constructs a new depth of field effect.

Member Summary

Public Members
public

This pass blurs the foreground CoC buffer to soften edges.

public get

The current bokeh scale.

public set
public get
this get was deprecated. Use cocMaterial instead.

The circle of confusion material.

public get

The circle of confusion material.

public get

cocTexture: Texture

The circle of confusion texture.

public set
public get

The mask function.

public set
public

target: Vector3

A target position that should be kept in focus.

Method Summary

Public Methods
public

calculateFocusDistance(target: Vector3): Number

Calculates the focus distance from the camera to the given position.

public
this method was deprecated. Use blurPass instead.

Returns the pass that blurs the foreground CoC buffer to soften edges.

public
this method was deprecated. Use bokehScale instead.

Returns the current bokeh scale.

public
this method was deprecated. Use cocMaterial instead.

Returns the circle of confusion material.

public
this method was deprecated. Use resolution instead.

Returns the resolution settings.

public

getTarget(): Vector3

this method was deprecated. Use target instead.

Returns the current auto focus target.

public

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

Performs initialization tasks.

public
this method was deprecated. Use bokehScale instead.

Sets the bokeh scale.

public

setDepthTexture(depthTexture: Texture, depthPacking: DepthPackingStrategies)

Sets the depth texture.

public

setSize(width: Number, height: Number)

Updates the size of internal render targets.

public

setTarget(value: Vector3)

this method was deprecated. Use target instead.

Sets the auto focus target.

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, options: Object) source

Constructs a new depth of field effect.

Override:

Effect#constructor

Params:

NameTypeAttributeDescription
camera Camera

The main camera.

options Object
  • optional

The options.

options.blendFunction BlendFunction
  • optional

The blend function of this effect.

options.worldFocusDistance Number
  • optional

The focus distance in world units.

options.worldFocusRange Number
  • optional

The focus distance in world units.

options.focusDistance Number
  • optional
  • default: 0.0

The normalized focus distance. Range is [0.0, 1.0].

options.focusRange Number
  • optional
  • default: 0.1

The focus range. Range is [0.0, 1.0].

options.focalLength Number
  • optional
  • default: 0.1

Deprecated.

options.bokehScale Number
  • optional
  • default: 1.0

The scale of the bokeh blur.

options.resolutionScale Number
  • optional
  • default: 0.5

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.

Public Members

public blurPass: KawaseBlurPass source

This pass blurs the foreground CoC buffer to soften edges.

public get bokehScale: Number source

The current bokeh scale.

public set bokehScale source

public get circleOfConfusionMaterial: CircleOfConfusionMaterial source

this get was deprecated. Use cocMaterial instead.

The circle of confusion material.

public get cocMaterial: CircleOfConfusionMaterial source

The circle of confusion material.

public get cocTexture: Texture source

The circle of confusion texture.

public set mainCamera source

Sets the main camera.

Override:

Effect#mainCamera

public get maskFunction: MaskFunction source

The mask function. Default is MULTIPLY_RGB.

public set maskFunction source

public target: Vector3 source

A target position that should be kept in focus. Set to null to disable auto focus.

Public Methods

public calculateFocusDistance(target: Vector3): Number source

Calculates the focus distance from the camera to the given position.

Params:

NameTypeAttributeDescription
target Vector3

The target.

Return:

Number

The normalized focus distance.

public getBlurPass(): KawaseBlurPass source

this method was deprecated. Use blurPass instead.

Returns the pass that blurs the foreground CoC buffer to soften edges.

Return:

KawaseBlurPass

The blur pass.

public getBokehScale(): Number source

this method was deprecated. Use bokehScale instead.

Returns the current bokeh scale.

Return:

Number

The scale.

public getCircleOfConfusionMaterial(): CircleOfConfusionMaterial source

this method was deprecated. Use cocMaterial instead.

Returns the circle of confusion material.

Return:

CircleOfConfusionMaterial

The material.

public getResolution(): Resolution source

this method was deprecated. Use resolution instead.

Returns the resolution settings.

Return:

Resolution

The resolution.

public getTarget(): Vector3 source

this method was deprecated. Use target instead.

Returns the current auto focus target.

Return:

Vector3

The target.

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 setBokehScale(value: Number) source

this method was deprecated. Use bokehScale instead.

Sets the bokeh scale.

Params:

NameTypeAttributeDescription
value Number

The scale.

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 setSize(width: Number, height: Number) source

Updates the size of internal render targets.

Override:

Effect#setSize

Params:

NameTypeAttributeDescription
width Number

The width.

height Number

The height.

public setTarget(value: Vector3) source

this method was deprecated. Use target instead.

Sets the auto focus target.

Params:

NameTypeAttributeDescription
value Vector3

The target.

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.