Back to Portfolio

2D Geometric Optics Simulation

Spectrum Distribution

Accumulates photons over time. Watch the rainbow pattern emerge!

⚠️ If you see overexposed (white) pixels, adjust the sensitivity slider

10°
500/s
1.0x
0.00

Motivation:

While I was being the teaching assistant in a rendering class, I noticed most students struggling with getting refraction to work properly, although it's one of the fundamentals. This motivated me to create this demo, giving some intuition on the topic without introducing any deep theory.

Instructions:

• Click to place light source

• Drag to move objects

• Watch photons split and create rainbows through the prism

• Each photon represents a different wavelength

A Gentle Introduction to Geometric Optics

This is an introductory educational demo that shows an interesting way to visualize optical phenomena: modeling light as a stream of photons with probabilistic behavior. While this approach trades physical rigor for simplicity and visual clarity, it can help build intuition about refraction, reflection, and dispersion.

Rendering Perspective:

At every interface between materials with different refractive indices, incident light is partially reflected and partially transmitted (refracted). The Fresnel equations determine the exact energy split between these two components. In path tracing and Monte Carlo rendering, we cannot afford to deterministically split rays at every interface—instead, we use stochastic sampling: each ray makes a probabilistic choice between reflection and refraction, weighted by the Fresnel reflectance coefficient R. With probability R, the ray reflects; with probability (1-R), it refracts. Over many samples, the aggregate distribution converges to the correct energy partition. This approach is unbiased and naturally handles complex multi-bounce scenarios without exponential ray splitting.

What This Demo Shows:

Important Limitations:

This simulation significantly simplifies real optics. We treat photons as rays (no wave effects like interference or diffraction), exaggerate dispersion for visibility, and use geometric approximations throughout. Real optical phenomena involve electromagnetic wave theory, polarization, coherence, and many other effects not captured here. This demo is purely for educational visualization—not for accurate optical design.

Metamerism: Different Spectra, Same Appearance

An important phenomenon this demo illustrates is metamerism: different spectral distributions can appear identical to the human eye. For example, the "Purple (Red+Blue)" mode mixes red (~650nm) and blue (~420nm) photons, creating the visual perception of purple—yet a "true" single-wavelength purple (~420nm) looks nearly the same to us. This is because human color vision is trichromatic: we have only three types of cone cells, so any combination of wavelengths that stimulates them in the same ratio appears identical.

Our simplified model maps wavelength directly to RGB, which approximates but oversimplifies real eye sensitivity curves (the actual spectral response functions are more complex bell curves). Despite this limitation, the demo shows why spectral analysis with prisms is valuable: two colors that look identical to the eye reveal their true composition when dispersed—a single-wavelength purple creates one narrow band, while red+blue creates two distinct separated bands. This principle is used in spectroscopy to identify materials.

Geometric Optics with Chromatic Effects:

One interesting aspect: we can demonstrate wavelength-dependent phenomena (dispersion, color) using only geometric ray tracing, without implementing full wave mechanics. The wavelength is just a parameter that affects the refractive index and perceived color. This shows the power (and limitations) of geometric optics as an approximation.