The Physics of Glass: Ray-Tracing Real Camera Lenses & Swirly Bokeh in GLSL
Every photographer has heard of the Helios 44-2 or Petzval 85mm's legendary "swirly bokeh" – and most people assume it comes from a weird aperture shape. It doesn't. Swirly bokeh is pure 3D geometry: an optical illusion produced by mechanical cat's-eye vignetting inside a long lens barrel combined with uncorrected Petzval field curvature. By ray-tracing spherical glass interfaces with Snell's law and Cauchy dispersion, we can reproduce every classic lens signature from first principles.
1. Exact Vector Snell's Law & Cauchy Chromatic Dispersion
For a ray with unit direction $\mathbf{d}$ striking a spherical glass surface of radius $R_k$ and unit normal $\mathbf{n}$, the refracted direction $\mathbf{d}'$ depends on the wavelength-dependent refractive index $n(\lambda)$ given by the Cauchy equation:
Crown glass ($V_d \approx 64$) bends red and blue light at nearly the same angle; flint glass ($V_d \approx 36$) bends blue far more strongly. Achromatic doublets cement a positive crown element to a negative flint element so $\Delta\phi_{\text{crown}}/V_{d,1} + \Delta\phi_{\text{flint}}/V_{d,2} = 0$, cancelling longitudinal chromatic aberration (LoCA).
2. Why Petzval Lenses Swirl: Cat's-Eye Entrance Pupils
For an on-axis point light, the circular aperture stop projects as a perfect circle onto the sensor. Move off-axis to image height $r$, and the front and rear lens barrel rims clip opposite sides of the oblique ray bundle, intersecting two offset circles of radius $a$ separated by $s(r) \propto r / f\text{-number}$. That intersection is a tangentially oriented almond ("cat's eye") whose major axis lies strictly perpendicular to the radial vector – making a forest of background highlights visually rotate around the frame center.
💻 GLSL: Exact 3D Ray-Sphere Surface Intersection & Vector RefractionGLSL
// Exact 3D Ray-Sphere Surface Intersection & Vector Refraction
bool refractSurface(inout vec3 ro, inout vec3 rd, float zCenter, float R, float apRad, float eta) {
vec3 oc = ro - vec3(0.0, 0.0, zCenter);
float b = dot(oc, rd);
float c = dot(oc, oc) - R * R;
float disc = b * b - c;
if (disc < 0.0) return false;
float t = -b + (R > 0.0 ? -sqrt(disc) : sqrt(disc));
if (t <= 0.0) return false;
vec3 hit = ro + rd * t;
if (length(hit.xy) > apRad) return false; // mechanical barrel vignetting!
vec3 n = normalize(hit - vec3(0.0, 0.0, zCenter));
if (dot(n, rd) > 0.0) n = -n;
vec3 refr = refract(rd, n, eta);
if (length(refr) < 1e-4) return false; // total internal reflection
ro = hit; rd = normalize(refr);
return true;
}
| Optical Aberration | Physical Root Cause | Visual Signature in Photos |
|---|---|---|
| Swirly Bokeh | Cat's-eye barrel vignetting + sagittal astigmatism | Tangential almond highlights curving around center |
| Spherical Aberration | Marginal rays focus closer than paraxial rays | Bright soap-bubble rim on bokeh balls (or creamy glow) |
| Longitudinal CA (LoCA) | Wavelength dispersion $n(\lambda_{\text{blue}}) \gt n(\lambda_{\text{red}})$ | Magenta fringing in front of focus, green behind focus |
| Petzval Curvature | Non-zero Petzval sum $\sum (n_k' - n_k)/(n_k n_k' R_k)$ | Focal plane bends into a bowl rather than a flat sensor |