DepthOfField

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/

import { DepthOfField } from '@react-three/postprocessing'

return (
  <DepthOfField
    focusDistance={3} // where to focus, in world units
    focusRange={2} // depth range that stays in focus, in world units
    bokehScale={2} // bokeh size
  />
)

Example

DepthOfField demo

Props

NameTypeDefaultDescription
blendFunctionBlendFunctionBlendFunction.NORMALThe blend function of this effect.
focusDistanceNumber3The focus distance in world units.
focusRangeNumber2The focus range in world units.
bokehScaleNumber1The scale of the bokeh blur.
targetVector3A world position to keep in focus. Overrides focusDistance.
depthTexture{ texture: Texture, packing: number }A depth texture to use instead of the composer's own.
resolutionScaleNumber0.5The render resolution scale.
resolutionXNumberResolution.AUTO_SIZEThe render width.
resolutionYNumberResolution.AUTO_SIZEThe render height.
opacityNumber1The opacity of this effect.

focalLength, worldFocusDistance, worldFocusRange, width, height and blur are deprecated.