Pseudo lens flare
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.
In the family Post-processing, color & imaging, lens effects
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | Official add-on | import { lensflare } from 'three/addons/tsl/display/LensflareNode.js' (WebGL: Lensflare object) docs |
| Babylon.js 9.38.0 | Built in | new BABYLON.LensFlareSystem('lf', emitter, scene) docs |
| Godot 4.7 | None found | No built-in screen-space lens flare pass on Environment (only glow/bloom). |
| Unity | Built in | GameObject > Effects > Lens Flare (SRP); Volume > Screen Space Lens Flare docs Data-driven lens flare asset plus a screen-space lens flare override, URP and HDRP. |
| Unreal 5.7 | Built in | Post Process Volume > Lens > Lens Flares docs |
| Blender 5.2 | Built in | Compositor > Add > Filter > Glare, Glare Type = Ghosts (or Streaks) docs Image-space glare in the compositor. |
| WebGPU W3C | None found | |
| Metal | None found |
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 choose it
Reach for it when
- 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
Choose it for a cheap cinematic lens artefact driven by whatever is bright in the frame, with no occlusion queries.
Prefer sprite-based flares with occlusion for hero art-directed suns. For soft glow without ghosts use Dual-filter and progressive-downsample bloom.
Field marks
- 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
Presets
Left: bright lights only. Right: screen-space ghosts (image re-sampled through the centre at several scales) with chromatic offset
{
"GAIN": 0.8,
"CA": 0.03
}Show GLSL (24 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 GAIN=0.8; // P
const float CA=0.03; // P
const vec4 M=vec4(-2.2,-1.2,-0.75,0.65); // P
vec3 B(vec2 p){
vec2 a=p-vec2(.3,.18),b=p+vec2(.28,.2);
return vec3(.012,.014,.022)+vec3(1.,.85,.6)*.004/(dot(a,a)+.0006)+vec3(.6,.8,1.)*.002/(dot(b,b)+.0006);}
vec3 bp(vec2 p){return max(B(p)-1.,vec3(0.));}
void mainImage(out vec4 fragColor,in vec2 fragCoord){
vec2 uv=(fragCoord-.5*iResolution.xy)/iResolution.y;bool R=uv.x>0.;
vec3 col=B(uv);
if(R){vec3 fl=vec3(0.);
for(int i=0;i<4;i++){float m=M[i];
float w=pow(1.-clamp(length(uv)*1.5,0.,1.),1.5);
vec3 g=vec3(bp(uv*m*(1.+CA)).r,bp(uv*m).g,bp(uv*m*(1.-CA)).b);
fl+=g*w*mix(vec3(1.,.8,.6),vec3(.6,.8,1.),float(i)/3.);}
col+=fl*GAIN;}
col=col/(1.+col);
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 |
|---|---|---|---|
| lens-flare-specimen | Tesla T4 1920x1080 | 3.16× baseline (light) · 0.104 ms / 0.109 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| lens-flare-specimen | NVIDIA L4 1920x1080 | 2.78× baseline (light) · 0.044 ms / 0.044 ms · 2.4× faster on L4 | opengl-timer-query · Cross-architecture validation |
| lens-flare-specimen | NVIDIA A100-SXM4-40GB 1920x1080 | 2.02× baseline (light) · 0.058 ms / 0.058 ms · 1.8× faster on A100 | opengl-timer-query · Cross-architecture validation |
Crosses
- Dual-filter and progressive-downsample bloom: Ghosts are sampled from the bloom downsample chain.
Sources
- primaryJohn Chapman. Pseudo Lens Flare. john-chapman-graphics.blogspot.com.Verified via live page · 2026-11-29
- implementationUnity-Technologies (2016). Unity-Technologies/PostProcessing. Post Processing StackGitHub API · license NOASSERTION · archived · 2026-11-29