Have you ever wondered about the rainbows on CDs, gasoline puddles or soap bubbles? All of these have the same cause: The interference of light on thin surfaces. Today, we’ll try to render something that looks like a soap bubble.

Some Physics

When a ray of light hits the surface of the soap bubble, it is either instantly reflected, or it enters the soap film and is refracted. When it is refracted, it can then be reflected off the other end of the soap, and then leave it again at a slightly different spot. There are countless other possiblities for the ray to bounce around, but these are the two that we will focus on here.

Two different paths that a beam of light can take through the soap film.

Two different paths that a beam of light can take through the soap film.

Because the width of the soap layer is comparable to the wavelength of visible light, the resulting color of the light rays will change considerably depending on the incidence angle.

Finished visualization

Putting it all together, we get this nice little interactive visualization.