A real camera lens stays sharp only near its focus distance, and blurs progressively in front of and behind it (bokeh). Three.js’s BokehPass(scene, camera, { focus, aperture, maxblur }) addon first renders the scene into a depth texture, then blends in blur for each pixel proportional to how far its depth is from the focus value.
focus is the distance from the camera that stays sharp, aperture is like an f-stop (bigger means blur ramps up faster), and maxblur caps how strong the blur can get. All three can change at runtime via, say, bokehPass.uniforms.focus.value — the demo oscillates focus with a sine wave, so which of five shapes reads as sharp keeps sweeping back and forth, as if the camera were racking focus.
Because the blur samples the full-screen texture repeatedly, it’s heavier than most other post-processing. Keep the camera’s near/far tight around the scene’s actual depth range so the depth texture has enough precision for a smooth blur instead of visible banding.
When to use
Product showcases, cinematic camera moves, or anywhere focus needs to pull the eye to one subject.