Physics Photography Optics Ray Tracing GLSL

The Physics of Glass: Ray-Tracing Real Camera Lenses & Swirly Bokeh in GLSL


Petzval 85mm · f/1.4 · Cat's-eye vignetting + tangential field curvature active
Real-time optical simulation: left half traces R/G/B rays through spherical glass elements via Snell's law; right half renders the resulting off-axis cat's-eye bokeh discs and axial chromatic fringing.

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:

Vector Refraction & Abbe Number Dispersion
$$n(\lambda) = A + \frac{B}{\lambda^2}, \qquad V_d = \frac{n_d - 1}{n_F - n_C}, \qquad \eta = \frac{n_1(\lambda)}{n_2(\lambda)}$$ $$\mathbf{d}' = \eta\,\mathbf{d} + \Big(\eta\cos\theta_1 - \sqrt{1 - \eta^2(1 - \cos^2\theta_1)}\Big)\mathbf{n}, \qquad \cos\theta_1 = -\mathbf{d}\cdot\mathbf{n}$$

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 AberrationPhysical Root CauseVisual Signature in Photos
Swirly BokehCat's-eye barrel vignetting + sagittal astigmatismTangential almond highlights curving around center
Spherical AberrationMarginal rays focus closer than paraxial raysBright 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 CurvatureNon-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