The Mathematics of Thin-Film Interference

This post continues our journey through the Mathematical foundations of iridescence. This time, we will discuss a new way in which material can split light: thin-film interference. This is how bubbles (and car paint) get their unique reflections.

You can find the complete series here:

A link to download the Unity project used in this series is also provided at the end of the page.

Introduction

In the previous posts, we have described how materials with certain repeated patterns exhibit iridescent reflections. Such a phenomenon is called diffraction grating. However, that is not the only way in which a material can split light into its components. Another one is called thin-film interference and occurs when a material is made out of multiple layers.

The diagram below shows a typical example of thin-film interference. Let’s imagine this to be a thin layer of water distributed onto a different surface. When a ray of light hits the water, it splits in two; a part is reflected back, while the rest goes deeper into the material. The latter ray is subjected to refraction, a phenomenon that causes light to “bend” when entering or exiting different materials.

Reflection and refraction can only happen where two different materials meet. For this reason, light continues to bounce inside the material until there’s energy left.

The reason why this phenomenon causes iridescent reflections to appear is, once again, due to the fact that light behaves like a wave. All those rays have travelled different distances; hence, they will reach the eye of the viewer with different phases. Under certain circumstances, some of those light rays will be in phase, amplifying each other. As a result, some colours will be boosted in the final reflection, while other will cancel each other out. Once again, iridescence is caused by constructive interference.

As you can see, there can be countless occasions for light to interfere. A calculation of that proportion is often unfeasible for rendering games in real-time. In this tutorial, we will focus on a simplified version of this problem, which only takes into account the interference of the first two rays:

The first diagram presented in this introduction indeed refers to subsurface scattering (or SSS). That is the process through which light travels inside a medium, to exit from a different point.

There are few important differences in the way thin-film interference and subsurface scattering appear. The first one is that thin-film interference causes a specular reflection, while sub surface scattering results in a diffuse one. This is because in SSS a single ray of light travels chaotically inside a material; when it finally exists, it has an arbitrary and unpredictable direction. In thin-film interference, instead, light is very well behaved and we can trace each ray deterministically.

Optical Path Difference

Like we did in the tutorial on diffraction grating, once again we have to calculate the difference in length travelled by the two reflected rays. However, there are a couple of important difference that needs to be highlighted. Diffraction grating is a diffusive phenomenon: rays are scattered in all directions. In that context, it made sense for an incoming ray of light from a light direction to hit a viewer looking at an arbitrary view direction . Thin-film interference is a specular phenomenon. Surfaces are perfectly smooth, and rays are reflected with the same incident angle.

Another issue is that rays are travelling through different media. This has a direct effect on their phase, as light travels at different speeds in different media. This forces us to rely on a quantity called optical path difference, which (loosely speaking) measures the phase offset of two light rays. For rays travelling through the same medium, the optical path difference is equal to the difference in length of their paths. For different media, we have to take into account their refractive index. This is a property that determines how much light “bends” when it enters into or exits from a material. The refractive index of empty space is equal to ; for air is and for water is .

Looking at our diagram above, we can see that the grey parts of common to both rays. The first ray travels the distance in a medium with refractive index . The second ray travels the distance in a medium with refractive index . The optical path difference is given by:

Path Length of the Second Ray

Let’s start by calculating the path length of the second ray, since is the easier one. It is easy to see that both and have the same length. Also, the is a right triangle. We assume to know the thickness of the second layer, , which is equal to the side of the triangle.

If you are unfamilair with trigonometry, the following diagram should help you understanding how to calculate the length of all the unknown sides of the triangle: By refreshing your knowledge of trigonometry, we have that:

Hence:

Path Length of the First Ray

Calculating the length of is easy, and we have done it already in The Mathematics of Diffraction Grating. In that post we concludede that:

By working on the  triangle, we can also find the length of its other side :

Hence:

Path Difference

To sum up:

Expanding with the following trigonometric identities and :

To progress in this expansion even further, we need to mention a foundamental equation in optics, called the Snell’s law. It connects the refractive indices to the incident and reflected angles:

From which we can extract:

Substituting and grouping by :

From Pythagora’s Theorem:

Substituting and simplifying:

❓ How come the diffraction grating equation was not derived using the OPD?
In Part 5 of the tutorial on Iridescence, The Mathematics of Diffraction Grating, we have seen something very similar. We calculated the path difference between two rays, to find out which wavelength interfered constructively with each other. In that tutorial, however, there is no mention of the optical path difference. There is actually no mention of the refractive index!This is because both

This is because, in diffraction grating, both rays are travelling the same medium: air. Following the current approach proposed in this post, the corrected diffraction grating equation becomes:

However, as we have discussed before, . For the purposes of this tutorial, we can assume to be exactly 1.

Yes, this also means that diffraction grating appears different in different media

❓ The two light rays are exiting the material from different points!
In this derivation we are making a very important simplification. We assume that the two light rays are actually coming out from the same point.

As it can be seen from the first diagram, this is clearly not the case. The second ray exits the material at a different point, so it might not be close enough to interfere with the first one. While we have indeed simplified the problem, this only has a marginal effect.

The first ray does not interfere with the first one, although it will with another ray that hit the material at an earlier time. This can be seen clearly in the following diagram:

Two incident rays of light (green and red) hit the material. The two reflected green rays do not interfere with each other; similarly, the two reflected red rays do not interfere with each other. However, the first green ray and the second red ray do exit the material from the same point. Hence, they are close enough to interfere.

By reasoning like this, we can assume that all the reflected rays generated by a single ray interfere with each other. Even if they actually exit the material at different points.

While this works relatively well for materials that are flat, it will cause inaccuracies on curved or uneven surfaces. However, such approximation errors are negligible when compared with the fact that we are only considering the interference between two rays.

Phase Shift

Like we discussed in The Mathematics of Diffraction Grating, when the between two light rays is an integer multiple of a wavelength, that wavelength is amplified by constructive interference. We could be tempted to simply derive the following condition:

with being an integer number. However, this would be a mistake. There is another optical phenomenon that we have not encountered before in this tutorial: phase shift. When a ray of light bounces off a medium, its wavelength can be subjected to a phase shift of 180 degrees. This will happen to all reflected rays travelling from medium to medium , when .

If we take the example of a soap bubble, the first ray to be reflected off the surface film will indeed be subjected to a phase shift since . This means that the phase of the first ray will be shifted by 180 degrees.

Before changing our equation, however, we need to check whether a similar phase shift occurs to the second ray or not. The only moment in which the second ray is reflected is when it crosses the film barrier. However, , so no phase shift occurs. This means that, in the case of a soap bubble floating in the air, only the first ray is subjected to a phase shift.

As a result, we have to alter our equation to take this into account:

We will see, in the next part of this tutorial, an efficient way to do this procedurally based on the refractive indices of the media.

❓ How come the diffraction grating equation did not take into account the phase shift?
As discussed before, we are not interested in the phase shift itself. What we really care is whether both light rays are in phase or not.

In diffraction grating, both rays bounce off the same material in the same way. This means that if a phase shift occurs, they will both experience it. Which also means that it is not going to affect the final phase.

Conclusion

This tutorial introduces the Mathematical foundations of the optical phenomenon known as thin-film interference. In the next post, we will see how we can actually implement that in a Shader.

You can find the complete series here:

💖 Support this blog

This website exists thanks to the contribution of patrons on Patreon. If you think these posts have either helped or inspired you, please consider supporting this blog.

You will be notified when a new tutorial is released!

📝 Licensing

You are free to use, adapt and build upon this tutorial for your own projects (even commercially) as long as you credit me.

You are not allowed to redistribute the content of this tutorial on other platforms, especially the parts that are only available on Patreon.

If the knowledge you have gained had a significant impact on your project, a mention in the credit would be very appreciated. ❤️🧔🏻

1. yanning meng

Finally🎉🎉 I’ve been waited for a long time!
Thank you again Alan!

• I KNOW RIGHT!!!

Webmentions

• Car Paint Shader: Thin-Film Interference - Alan Zucconi September 6, 2022

[…] post completes the journey started in The Mathematics of Thin-Film Interference, by explaining how to turn the equations previously presented into actual shader […]

• Understanding Diffraction Grating - Alan Zucconi September 6, 2022

[…] Part 9. The Mathematics of Thin-Film Interference […]