← 🎨 Colours & Light
🟢 6+ years

🌈 How a rainbow forms

Liquid (n)
Secondary bow (51°)
Primary ~42° · red on outer edge
💡 Sunlight refracts, reflects once and disperses inside each raindrop. Red exits at ~42°, violet at ~40° — and the secondary bow (two reflections) shows reversed colours at ~51°.
Lower the sun · toggle the secondary bow · change the liquid

🌈 Rainbow — Atmospheric Scattering

Atmospheric light scattering demonstrates how rainbows form. Sunlight refracts through water droplets, separating into the colour spectrum. Move the sun position to see how the rainbow angle changes.

🔬 What It Demonstrates

Snell's law governs refraction at the droplet surface. Different wavelengths refract at slightly different angles (dispersion), separating white light into colours.

🎮 How to Use

Move the sun position to see how the rainbow arc responds. The primary rainbow is always at 42° from the anti-solar point.

💡 Did You Know?

The secondary rainbow (sometimes visible outside the primary) has reversed colour order and is caused by two internal reflections inside the droplet. The dark band between them is called Alexander's dark band.

About the Rainbow Dispersion Simulation

This GLSL fragment shader recreates how sunlight forms a rainbow inside spherical raindrops. Each ray enters a drop, refracts, reflects once off the back surface, refracts again on exit, and disperses because the refractive index n(λ) varies with wavelength. Rays pile up at a minimum-deviation angle, producing the primary bow at roughly 42° around the antisolar point, with red on the outer edge and violet within.

The on-screen panel lets you adjust the sun's elevation (0–70°), the overall intensity, and the droplet liquid (water, a denser liquid, or glycerol), and toggle the secondary bow. Raising the sun above about 42° pushes the arc below the horizon, just as in nature. Understanding this geometry matters in atmospheric optics, meteorology, and the design of optical instruments that exploit dispersion.

Frequently Asked Questions

What does this simulation show?

It renders a rainbow as it forms when sunlight is refracted, reflected and dispersed inside raindrops. The primary arc appears at about 42 degrees from the antisolar point with red on the outside, and an optional fainter secondary arc appears at about 51 degrees with the colours reversed.

Why does a rainbow appear at about 42 degrees?

Light passing through a sphere with one internal reflection has a minimum deviation angle, so rays bunch up at that angle and reinforce one another. For water this minimum-deviation, or rainbow, angle works out to roughly 42 degrees, which is why the bow always forms there regardless of drop size.

What causes the colours to separate?

The refractive index of water depends slightly on wavelength, a property called dispersion. Violet light has a higher index (about 1.343) than red (about 1.331), so it bends more and exits at a smaller angle. This spreads white sunlight into the spectral band you see across the arc.

What do the controls do?

Sun elevation sets how high the sun sits, which moves the bow up or down; intensity scales the overall brightness; the liquid selector switches between water, a denser liquid and glycerol, changing the refractive index; and the secondary-bow toggle shows or hides the fainter 51-degree arc and Alexander's dark band.

Why can't I see the rainbow when the sun is high?

The arc is centred on the antisolar point, which lies opposite the sun and sinks below the horizon as the sun climbs. Once the sun rises above about 42 degrees the whole primary bow drops out of sight, so the simulation fades the arc out above that elevation, matching real observations.

What is the equation behind the rainbow angle?

Snell's law, sin i = n sin r, governs refraction at the surface. For k internal reflections the minimum-deviation entry angle satisfies cos i = sqrt((n squared minus 1) divided by k times (k plus 2)), and the scattering angle from the antisolar point follows from the total deviation. The shader evaluates this directly for each wavelength.

What is the secondary bow and Alexander's dark band?

The secondary bow comes from two internal reflections rather than one, so it appears at about 51 degrees, is fainter, and has its colours reversed with red on the inner edge. Between the two bows lies a dimmer region known as Alexander's dark band, where little light is scattered back toward the observer.

How does changing the liquid affect the bow?

Switching to a denser liquid or glycerol raises the refractive index, which shifts the minimum-deviation angle inward and changes the spread of colours. The live readout recomputes the primary and secondary angles for the chosen medium, so you can watch the arc tighten as the index increases.

Is the simulation physically accurate?

The colour ordering, the roughly 42 and 51 degree angles, dispersion by wavelength and Alexander's dark band all follow the correct optics. It is a stylised real-time approximation rather than a full radiative-transfer model, so the on-screen screen-radius scaling and brightness are tuned for clarity rather than exact photometric values.

Why does each person see a different rainbow?

A rainbow is not fixed in space; it is defined by the angle between the sunlight and your line of sight, centred on the shadow of your own head. Because that geometry is unique to each viewer's position, no two observers ever see exactly the same arc, even standing side by side.

Where is this physics applied in the real world?

The same dispersion and refraction principles underlie atmospheric optics phenomena such as halos and glories, the design of prisms and spectrometers, and remote-sensing techniques that infer raindrop size from a rainbow's width and brightness. Studying these angles also helps meteorologists interpret sky conditions.