{
 "id": "lens-flare",
 "title": "Pseudo lens flare",
 "aliases": [],
 "domain": "post",
 "subdomain": "lens effects",
 "stage": "post",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "unity",
  "unreal"
 ],
 "year_introduced": 2013,
 "inputs": [
  "hdr-image"
 ],
 "outputs": [
  "hdr-image"
 ],
 "style": "both",
 "dynamic": "dynamic",
 "summary": "Screen-space approximation of lens ghosts and halo: mirror the bright parts of the image about the screen centre, tint and chain them, and add the result back to the HDR buffer.",
 "how_it_works": "A thresholded, downsampled copy of the HDR image provides the bright features. For each of N ghosts, a sample coordinate is mirrored around the image centre and scaled by an increasing factor, producing copies of the light sources along the line through the centre. A radial weight fades ghosts near the edges. A halo is formed by sampling along the direction to the centre at a fixed radius and weighting by a ring function. Each ghost is tinted via a 1D gradient texture and chromatic dispersion offsets of the three channels. The result is blurred slightly, optionally multiplied by a dirt texture, and added back before tonemapping.",
 "when_to_use": "Choose it for a cheap cinematic lens artefact driven by whatever is bright in the frame, with no occlusion queries.\n\nPrefer sprite-based flares with occlusion for hero art-directed suns. For soft glow without ghosts use `dual-filter-bloom`.",
 "cost": {
  "class": "cheap",
  "notes": "A handful of fetches per pixel at quarter resolution, qualitative."
 },
 "failure_modes": [
  "Ghosts appear for any bright pixel, so specular glints produce unintended flare",
  "Flicker when a light moves off screen and its ghosts pop out",
  "Looks artificial and repetitive without a lens dirt or aperture shape",
  "Costs and result depend on the threshold, which is scene specific"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:https://john-chapman-graphics.blogspot.com/2013/02/pseudo-lens-flare.html",
   "type": "web",
   "title": "Pseudo Lens Flare",
   "authors": [
    "John Chapman"
   ],
   "year": null,
   "venue": "john-chapman-graphics.blogspot.com",
   "url": "https://john-chapman-graphics.blogspot.com/2013/02/pseudo-lens-flare.html",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261023030315/https://john-chapman-graphics.blogspot.com/2013/02/pseudo-lens-flare.html",
     "timestamp": "20261023030315"
    },
    "page_title": "john-chapman-graphics: Pseudo Lens Flare",
    "host": "john-chapman-graphics.blogspot.com",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://john-chapman-graphics.blogspot.com/2013/02/pseudo-lens-flare.html → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://john-chapman-graphics.blogspot.com/2013/02/pseudo-lens-flare.html → 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": "http",
     "endpoint": "GET https://john-chapman-graphics.blogspot.com/2013/02/pseudo-lens-flare.html → 200",
     "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": "chapmanpseudo"
  },
  {
   "role": "implementation",
   "key": "gh:unity-technologies/postprocessing",
   "type": "code",
   "title": "Unity-Technologies/PostProcessing",
   "description": "Post Processing Stack",
   "authors": [
    "Unity-Technologies"
   ],
   "year": 2016,
   "venue": "GitHub",
   "url": "https://github.com/Unity-Technologies/PostProcessing",
   "ids": {
    "repo": "Unity-Technologies/PostProcessing"
   },
   "license": "NOASSERTION",
   "extra": {
    "stars": 3744,
    "stars_checked": "2026-11-29",
    "archived": true,
    "fork": false,
    "pushed_at": "2024-06-05T07:45:22Z",
    "language": "C#",
    "homepage": null,
    "license_name": "Other"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/Unity-Technologies/PostProcessing",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/Unity-Technologies/PostProcessing",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/Unity-Technologies/PostProcessing",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/Unity-Technologies/PostProcessing",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/Unity-Technologies/PostProcessing",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/Unity-Technologies/PostProcessing",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "unitytechnologies2016unity"
  }
 ],
 "presets": [
  {
   "id": "lens-flare-specimen",
   "title": "Left: bright lights only. Right: screen-space ghosts (image re-sampled through the centre at several scales) with chromatic offset",
   "runtime": "glsl-fragment",
   "params": {
    "GAIN": 0.8,
    "CA": 0.03
   },
   "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 GAIN=0.8; // P\nconst float CA=0.03; // P\nconst vec4 M=vec4(-2.2,-1.2,-0.75,0.65); // P\nvec3 B(vec2 p){\n  vec2 a=p-vec2(.3,.18),b=p+vec2(.28,.2);\n  return vec3(.012,.014,.022)+vec3(1.,.85,.6)*.004/(dot(a,a)+.0006)+vec3(.6,.8,1.)*.002/(dot(b,b)+.0006);}\nvec3 bp(vec2 p){return max(B(p)-1.,vec3(0.));}\nvoid mainImage(out vec4 fragColor,in vec2 fragCoord){\n  vec2 uv=(fragCoord-.5*iResolution.xy)/iResolution.y;bool R=uv.x>0.;\n  vec3 col=B(uv);\n  if(R){vec3 fl=vec3(0.);\n    for(int i=0;i<4;i++){float m=M[i];\n      float w=pow(1.-clamp(length(uv)*1.5,0.,1.),1.5);\n      vec3 g=vec3(bp(uv*m*(1.+CA)).r,bp(uv*m).g,bp(uv*m*(1.-CA)).b);\n      fl+=g*w*mix(vec3(1.,.8,.6),vec3(.6,.8,1.),float(i)/3.);}\n    col+=fl*GAIN;}\n  col=col/(1.+col);\n  if(abs(uv.x)<.0015)col=vec3(1.);\n  fragColor=vec4(gam(col),1.);\n}",
   "basis": "original",
   "license_note": "written for this index",
   "execution_fidelity": "faithful-pass",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-29",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "lens-flare",
     "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.2881,
      "std": 0.1221,
      "unique_colors": 212
     },
     "image": "/specimens/lens-flare-specimen.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "dual-filter-bloom",
  "chromatic-aberration"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "dual-filter-bloom",
   "why": "Ghosts are sampled from the bloom downsample chain."
  }
 ],
 "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/lens-flare.json"
 },
 "solves": [
  "bright lights look flat with no lens artefacts",
  "want cheap cinematic ghosts and halos",
  "need flare effect without occlusion queries",
  "scene sun should create camera-like streaks"
 ],
 "authority": "Chapman",
 "url": "https://texelatlas.vercel.app/t/lens-flare/",
 "execution_fidelity": "faithful-pass",
 "fidelity_label": "Faithful Pass",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 3.16,
  "tier": "light",
  "p50_ms": 0.104,
  "p95_ms": 0.1088,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "lens-flare-specimen",
  "execution_fidelity": "faithful-pass",
  "fidelity_label": "Faithful Pass",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 2.78,
   "tier": "light",
   "p50_ms": 0.0442,
   "p95_ms": 0.0444,
   "speedup_x": 2.35,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 2.02,
   "tier": "light",
   "p50_ms": 0.0581,
   "p95_ms": 0.0582,
   "speedup_x": 1.79,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}