Depth of Field

Blur the scene in front of and behind the focus distance.

DepthOfField blurs the parts of the scene that are far from the focal plane, like a camera lens. It wraps three's DepthOfFieldNode.

It reads the depth of the scene pass, so it needs no extra setup. It is an HDR effect, so bright areas make bright bokeh.

Usage

<script setup lang="ts">
import { TresCanvas } from '@tresjs/core/webgpu'
import { DepthOfField, EffectComposer } from '@tresjs/post-processing/webgpu'
</script>

<template>
  <TresCanvas>
    <!-- Your scene -->

    <EffectComposer>
      <DepthOfField :focus-distance="6.5" :focal-length="3" :bokeh-scale="4" />
    </EffectComposer>
  </TresCanvas>
</template>

Props

focusDistance and focalLength are in world units. bokehScale has no unit.

PropDescriptionDefault
focusDistanceThe distance from the camera to the focal plane.1
focalLengthHow far an object can be from the focal plane before it is fully out of focus.1
bokehScaleThe size of the bokeh.1

Differences from DepthOfFieldPmndrs

DepthOfField exposes the parameters of three's dof() function. focusDistance and focalLength are in world units.

DepthOfFieldPmndrsDepthOfField
worldFocusDistancefocusDistance
worldFocusRangefocalLength
bokehScalebokehScale
focusDistance, focusRangeNot available. They are in normalized depth, from 0 to 1. DepthOfFieldNode only takes world units.
resolutionScale, resolutionX, resolutionYNot available. DepthOfFieldNode always blurs at half resolution.
blendFunctionNot available. The WebGPU family has no blend functions. See Blending.

Further Reading

See the three.js example.