Scatter-as-gather bokeh depth of field
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.
Also known as DoF
In the family Post-processing, color & imaging, depth of field
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | Official add-on | import { dof } from 'three/addons/tsl/display/DepthOfFieldNode.js' docs |
| Babylon.js 9.38.0 | Built in | DefaultRenderingPipeline.depthOfFieldEnabled (DepthOfFieldEffect) docs |
| Godot 4.7 | Built in | CameraAttributesPractical > dof_blur_far_enabled / dof_blur_near_enabled (gather-based bokeh depth of field) docs |
| Unity | None found | |
| Unreal 5.7 | Built in | Post Process Volume or Cine Camera > Lens > Depth of Field (Cinematic Diaphragm bokeh DOF) docs |
| Blender 5.2 | Built in | EEVEE Render Properties > Depth of Field (gather/scatter bokeh blur driven by Camera Aperture) docs |
| WebGPU W3C | None found | |
| Metal | None found |
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 choose it
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
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 when you want glow rather than a lens model.
Field marks
- 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
Presets
Left: pinhole. Right: gather DoF, each tap weighted by whether its own circle of confusion reaches the pixel
{
"RM": 0.05,
"FOCUS": 0.5,
"NT": 96
}Show GLSL (28 lines)
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
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| depth-of-field-scatter-as-gather-specimen | Tesla T4 1920x1080 | 111× baseline (extreme) · 3.65 ms / 3.87 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| depth-of-field-scatter-as-gather-specimen | NVIDIA L4 1920x1080 | 96.2× baseline (extreme) · 1.53 ms / 1.56 ms · 2.4× faster on L4 | opengl-timer-query · Cross-architecture validation |
| depth-of-field-scatter-as-gather-specimen | NVIDIA A100-SXM4-40GB 1920x1080 | 70.8× baseline (extreme) · 2.04 ms / 2.09 ms · 1.8× faster on A100 | opengl-timer-query · Cross-architecture validation |
Crosses
- Dual-filter and progressive-downsample bloom: HDR highlights drive both bokeh shape and glow; share the downsampled buffers.
Sources
- primaryJorge Jimenez. Next Generation Post Processing in Call of Duty: Advanced Warfare. SIGGRAPH 2014 Advances in Real-Time Rendering.Verified via live page · 2026-11-29
- implementationpmndrs (2015). pmndrs/postprocessing. A post processing library for three.js.GitHub API · license Zlib · 2026-11-29