---
id: "depth-of-field-scatter-as-gather"
title: "Scatter-as-gather bokeh depth of field"
aliases: [DoF]
domain: "post"
stage: "post"
realtime: "realtime"
platforms: [webgl2, webgpu, desktop-gpu, mobile-gpu, unity, unreal]
year_introduced: 2014
inputs: [hdr-image, depth]
outputs: [hdr-image]
style: "photoreal"
dynamic: "dynamic"
cost: "medium"
authority: "Jimenez"
url: "https://texelatlas.vercel.app/t/depth-of-field-scatter-as-gather/"
sources_verified_at: "2026-11-29"
---
# Scatter-as-gather bokeh depth of field (Jimenez)

> Depth of field from a circle of confusion buffer: far and near fields are split, blurred with a gather kernel that emulates scatter of bright points into bokeh discs, then composited with the sharp focus layer.

## Reach for it when

- blurry foreground leaks sharp edges around subject
- bokeh blur looks wrong near depth discontinuities
- realistic camera focus blur in real time
- near field blur must spread over in-focus objects

## How it works

A circle-of-confusion value is computed per pixel from depth, focus distance, aperture and focal length. The image is split into a near-field layer (which must bleed over the in-focus region) and a far-field layer, each premultiplied by its CoC weight and downsampled. A gather pass samples in a disc pattern around each pixel, but instead of taking all samples equally it keeps a sample only if its own CoC is large enough to reach the centre pixel, which approximates scattering each sample as a bokeh disc. Tap positions follow a spiral or Poisson pattern and the bokeh shape is controlled by the kernel. A small post-blur removes undersampling noise, and the layers are composited with the full-resolution in-focus layer using the CoC as alpha.

## When to use it

Choose it when you want convincing bokeh with highlights that read as discs and correct near-field bleeding at interactive cost.

Prefer a cheap Gaussian or Kawase blur when you only need a soft background and have no budget. Prefer [Dual-filter and progressive-downsample bloom](https://texelatlas.vercel.app/t/dual-filter-bloom.md) when you want glow rather than a lens model.

## Cost

medium — Gather with tens of taps at half or quarter resolution, plus composite; qualitative.
Measured GPU Weight: 111.02× baseline (extreme) — 3.6526 ms median / 3.867 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 96.15× baseline (extreme) — 1.5288 ms median (2.39× faster on L4).
Ampere A100 scaling: 70.84× baseline (extreme) — 2.0403 ms median (1.79× faster on A100).

## Failure modes

- Disocclusion artifacts: sharp objects cannot blur over the background that they hide
- Visible tap patterns or noise when undersampled
- Sharp silhouettes with halos around in-focus objects against blurred backgrounds
- Transparent objects and particles lack depth and stay sharp

## Engine support

- babylonjs: builtin — `DefaultRenderingPipeline.depthOfFieldEnabled (DepthOfFieldEffect)` (evidence: https://github.com/BabylonJS/Babylon.js/blob/9.38.0/packages/dev/core/src/PostProcesses/depthOfFieldEffect.ts, checked 2026-12-01)
- blender: builtin — `EEVEE Render Properties > Depth of Field (gather/scatter bokeh blur driven by Camera Aperture)` (evidence: https://docs.blender.org/manual/en/5.2/render/eevee/render_settings/depth_of_field.html, checked 2026-12-01)
- godot: builtin — `CameraAttributesPractical > dof_blur_far_enabled / dof_blur_near_enabled (gather-based bokeh depth of field)` (evidence: https://github.com/godotengine/godot/blob/4.4-stable/scene/resources/camera_attributes.cpp, checked 2026-12-01)
- threejs: official — `import { dof } from 'three/addons/tsl/display/DepthOfFieldNode.js'` (evidence: https://github.com/mrdoob/three.js/blob/r187/examples/jsm/tsl/display/DepthOfFieldNode.js, checked 2026-12-01)
- unreal: builtin — `Post Process Volume or Cine Camera > Lens > Depth of Field (Cinematic Diaphragm bokeh DOF)` (evidence: https://dev.epicgames.com/documentation/en-us/unreal-engine/cinematic-depth-of-field-in-unreal-engine, checked 2026-12-01)

## Dataflow

- Inputs: hdr-image, depth
- Outputs: hdr-image
- Platforms: webgl2, webgpu, desktop-gpu, mobile-gpu, unity, unreal

## Presets

### Left: pinhole. Right: gather DoF, each tap weighted by whether its own circle of confusion reaches the pixel (glsl-fragment; rendered 2026-11-29)

```json
{
  "RM": 0.05,
  "FOCUS": 0.5,
  "NT": 96
}
```

```glsl
float hash(vec2 c){uvec2 u=uvec2(ivec2(floor(c)));uint h=u.x*1597334673u^u.y*3812015801u;h^=h>>15;h*=2246822519u;h^=h>>13;h*=3266489917u;h^=h>>16;return float(h)*(1./4294967296.);}
float lum(vec3 c){return dot(c,vec3(.2126,.7152,.0722));}
vec3 gam(vec3 c){return pow(clamp(c,0.,1.),vec3(1./2.2));}

const float RM=0.05; // P
const float FOCUS=0.5; // P
const int NT=96; // P
vec4 scn(vec2 p){
  vec3 c=mix(vec3(.04,.05,.1),vec3(.14,.09,.2),p.y+.5);float z=1.;
  vec2 g=p*13.,id=floor(g);float h=hash(id);
  vec2 cp=(id+.5+(vec2(hash(id+3.),hash(id+7.))-.5)*.5)/13.;
  if(h>.45)c+=vec3(1.,.75+.2*hash(id+1.),.45+.5*hash(id+2.))*6.*smoothstep(.002,-.002,length(p-cp)-.011);
  float r=length(p-vec2(0.,-.02));
  if(abs(r-.14)<.026){c=vec3(.9,.85,.7)*(.35+.65*step(.5,fract(atan(p.y,p.x)*3.8197)));z=.5;}
  if(length(p-vec2(.18,-.3))<.07){c=vec3(.2,.7,.4)*(.6+.4*sin(p.x*120.));z=.12;}
  return vec4(c,z);}
float coc(float z){return clamp(abs(z-FOCUS)*2.,0.,1.);}
void mainImage(out vec4 fragColor,in vec2 fragCoord){
  vec2 uv=(fragCoord-.5*iResolution.xy)/iResolution.y;bool R=uv.x>0.;vec2 q=vec2(uv.x+(R?-.25:.25),uv.y);
  vec3 col;
  if(!R) col=scn(q).rgb;
  else{vec4 c0=scn(q);vec3 acc=c0.rgb*.001;float ws=.001;
    for(int i=0;i<NT;i++){float a=float(i)*2.39996,r=sqrt((float(i)+.5)/float(NT))*RM;
      vec4 s=scn(q+vec2(cos(a),sin(a))*r);float w=clamp((coc(s.w)*RM-r)/.004+.5,0.,1.);if(s.w>c0.w+.01)w*=smoothstep(0.,.35,coc(c0.w));acc+=s.rgb*w;ws+=w;}
    col=acc/ws;}
  col=col/(1.+col*.6);
  if(abs(uv.x)<.0015)col=vec3(1.);fragColor=vec4(gam(col),1.);
}
```

Attribution: written for this index

## Combines with

- [Dual-filter and progressive-downsample bloom](https://texelatlas.vercel.app/t/dual-filter-bloom.md): HDR highlights drive both bokeh shape and glow; share the downsampled buffers.

## Sources

1. [primary] Jorge Jimenez Next Generation Post Processing in Call of Duty: Advanced Warfare. SIGGRAPH 2014 Advances in Real-Time Rendering. https://www.iryoku.com/next-generation-post-processing-in-call-of-duty-advanced-warfare (verified via http on 2026-11-29)
2. [implementation] pmndrs (2015) pmndrs/postprocessing. https://github.com/pmndrs/postprocessing License: Zlib. (verified via github on 2026-11-29)

## Cite this entry

Texel. "Scatter-as-gather bokeh depth of field." https://texelatlas.vercel.app/t/depth-of-field-scatter-as-gather/ (accessed 2026-12-01).
