{
 "id": "depth-of-field-scatter-as-gather",
 "title": "Scatter-as-gather bokeh depth of field",
 "aliases": [
  "DoF"
 ],
 "domain": "post",
 "subdomain": "depth of field",
 "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",
 "summary": "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.",
 "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": "Choose it when you want convincing bokeh with highlights that read as discs and correct near-field bleeding at interactive cost.\n\nPrefer a cheap Gaussian or Kawase blur when you only need a soft background and have no budget. Prefer `dual-filter-bloom` when you want glow rather than a lens model.",
 "cost": {
  "class": "medium",
  "notes": "Gather with tens of taps at half or quarter resolution, plus composite; qualitative."
 },
 "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"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:https://www.iryoku.com/next-generation-post-processing-in-call-of-duty-advanced-warfare",
   "type": "talk",
   "title": "Next Generation Post Processing in Call of Duty: Advanced Warfare",
   "authors": [
    "Jorge Jimenez"
   ],
   "year": null,
   "venue": "SIGGRAPH 2014 Advances in Real-Time Rendering",
   "url": "https://www.iryoku.com/next-generation-post-processing-in-call-of-duty-advanced-warfare",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261115081758/https://www.iryoku.com/next-generation-post-processing-in-call-of-duty-advanced-warfare/",
     "timestamp": "20261115081758"
    },
    "page_title": "Jorge Jimenez &#8211; Game Developer &#8211; Next Generation Post Processing in Call of Duty: Advanced Warfare",
    "host": "iryoku.com",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://www.iryoku.com/next-generation-post-processing-in-call-of-duty-advanced-warfare → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://www.iryoku.com/next-generation-post-processing-in-call-of-duty-advanced-warfare → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 0.95,
   "__bib": "jimeneznext"
  },
  {
   "role": "implementation",
   "key": "gh:pmndrs/postprocessing",
   "type": "code",
   "title": "pmndrs/postprocessing",
   "description": "A post processing library for three.js.",
   "authors": [
    "pmndrs"
   ],
   "year": 2015,
   "venue": "GitHub",
   "url": "https://github.com/pmndrs/postprocessing",
   "ids": {
    "repo": "pmndrs/postprocessing"
   },
   "license": "Zlib",
   "extra": {
    "stars": 3009,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-11-22T15:27:35Z",
    "language": "JavaScript",
    "homepage": null,
    "license_name": "zlib License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/pmndrs/postprocessing",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/pmndrs/postprocessing",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/pmndrs/postprocessing",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/pmndrs/postprocessing",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/pmndrs/postprocessing",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/pmndrs/postprocessing",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "pmndrs2015pmndrs"
  }
 ],
 "presets": [
  {
   "id": "depth-of-field-scatter-as-gather-specimen",
   "title": "Left: pinhole. Right: gather DoF, each tap weighted by whether its own circle of confusion reaches the pixel",
   "runtime": "glsl-fragment",
   "params": {
    "RM": 0.05,
    "FOCUS": 0.5,
    "NT": 96
   },
   "code": "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.);}\nfloat lum(vec3 c){return dot(c,vec3(.2126,.7152,.0722));}\nvec3 gam(vec3 c){return pow(clamp(c,0.,1.),vec3(1./2.2));}\n\nconst float RM=0.05; // P\nconst float FOCUS=0.5; // P\nconst int NT=96; // P\nvec4 scn(vec2 p){\n  vec3 c=mix(vec3(.04,.05,.1),vec3(.14,.09,.2),p.y+.5);float z=1.;\n  vec2 g=p*13.,id=floor(g);float h=hash(id);\n  vec2 cp=(id+.5+(vec2(hash(id+3.),hash(id+7.))-.5)*.5)/13.;\n  if(h>.45)c+=vec3(1.,.75+.2*hash(id+1.),.45+.5*hash(id+2.))*6.*smoothstep(.002,-.002,length(p-cp)-.011);\n  float r=length(p-vec2(0.,-.02));\n  if(abs(r-.14)<.026){c=vec3(.9,.85,.7)*(.35+.65*step(.5,fract(atan(p.y,p.x)*3.8197)));z=.5;}\n  if(length(p-vec2(.18,-.3))<.07){c=vec3(.2,.7,.4)*(.6+.4*sin(p.x*120.));z=.12;}\n  return vec4(c,z);}\nfloat coc(float z){return clamp(abs(z-FOCUS)*2.,0.,1.);}\nvoid mainImage(out vec4 fragColor,in vec2 fragCoord){\n  vec2 uv=(fragCoord-.5*iResolution.xy)/iResolution.y;bool R=uv.x>0.;vec2 q=vec2(uv.x+(R?-.25:.25),uv.y);\n  vec3 col;\n  if(!R) col=scn(q).rgb;\n  else{vec4 c0=scn(q);vec3 acc=c0.rgb*.001;float ws=.001;\n    for(int i=0;i<NT;i++){float a=float(i)*2.39996,r=sqrt((float(i)+.5)/float(NT))*RM;\n      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;}\n    col=acc/ws;}\n  col=col/(1.+col*.6);\n  if(abs(uv.x)<.0015)col=vec3(1.);fragColor=vec4(gam(col),1.);\n}",
   "basis": "original",
   "license_note": "written for this index",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-29",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "depth-of-field-scatter-as-gather",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-29T15:51:50.471Z",
     "renderer": "Chromium 145.0.7632.6 headless, WebGL2 via ANGLE/SwiftShader, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.4168,
      "std": 0.1615,
      "unique_colors": 244
     },
     "image": "/specimens/depth-of-field-scatter-as-gather-specimen.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "dual-filter-bloom",
  "per-object-motion-blur"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "dual-filter-bloom",
   "why": "HDR highlights drive both bokeh shape and glow; share the downsampled buffers."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/post/depth-of-field-scatter-as-gather.json"
 },
 "solves": [
  "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"
 ],
 "authority": "Jimenez",
 "url": "https://texelatlas.vercel.app/t/depth-of-field-scatter-as-gather/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 111.02,
  "tier": "extreme",
  "p50_ms": 3.6526,
  "p95_ms": 3.867,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "depth-of-field-scatter-as-gather-specimen",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 96.15,
   "tier": "extreme",
   "p50_ms": 1.5288,
   "p95_ms": 1.5609,
   "speedup_x": 2.39,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 70.84,
   "tier": "extreme",
   "p50_ms": 2.0403,
   "p95_ms": 2.0865,
   "speedup_x": 1.79,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}