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:

❓ What about subsurface scattering?

📰 Ad Break

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 L to hit a viewer looking at an arbitrary view direction V. 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 1; for air is 1.000293 and for water is 1.333.

Looking at our diagram above, we can see that the grey parts of common to both rays. The first ray travels the distance \overline{AD} in a medium with refractive index n_1. The second ray travels the distance \overline{AB}+\overline{BC} in a medium with refractive index n_2. The optical path difference is given by:

    \[OPD = n_2 \left(\overline{AB}+\overline{BC}\right) - n_1  \overline{AD}\]

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 \overline{AB} and \overline{BC} have the same length. Also, the \widehat{ABE} is a right triangle. We assume to know the thickness of the second layer, d, which is equal to the side \overline{BE} 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 \widehat{ABE} triangle: By refreshing your knowledge of trigonometry, we have that:

Hence:

    \[\overline{AB} = \overline{BC} = \boxed{d \sec{\theta_R}}\]

    \[\overline{AB}+\overline{BC} = 2 \boxed{d \sec{\theta_R}}\]

Path Length of the First Ray

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

    \[\overline{AD} = \boxed{\overline{AC}} \sin{\theta_L}\]

By working on the \widehat{ABE} triangle, we can also find the length of its other side \overline{AE}:

    \[\overline{AC} = \overline{AE} + \overline{EC}\]

    \[\overline{AE} = \overline{EC} = d \tan{\theta_R}\]

    \[\overline{AC} = \boxed{2 d \tan{\theta_R}}\]

Hence:

    \[\overline{AD} = \boxed{ 2 d \tan{\theta_R}} \sin{\theta_L}\]

Path Difference

To sum up:

    \[OPD = n_2 \boxed{\left(\overline{AB}+\overline{BC}\right) }- n_1 \boxed{ \overline{AD}  }=\]

    \[= n_2 \boxed{2 d \sec{\theta_R}} - n_1 \boxed{2 d \tan{\theta_R} \sin{\theta_L}} =\]

    \[=2d \left(      n_2  \sec{\theta_R} - n_1 \tan{\theta_R} \sin{\theta_L}    \right)\]

Expanding with the following trigonometric identities \sec{\theta_R} = \frac{1}{\cos{\theta_R}} and \tan{\theta_R} = \frac{\sin{\theta_R}}{\cos{\theta_R}}:

    \[OPD=2d \left(      n_2  \boxed{\sec{\theta_R}} - n_1 \boxed{\tan{\theta_R}} \sin{\theta_L}    \right)=\]

    \[= 2 d \left (n_2 \boxed{\frac{1}{\cos{\theta_R}}}- n_1 \boxed{\frac{\sin{\theta_R}}{\cos{\theta_R}}} \sin{\theta_L}\right) =  \]

    \[= \frac{2d}{\cos{\theta_R}} \left(n_2 - n_1 \sin{\theta_R} \sin{\theta_L }\right)\]

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:

    \[n_1 \sin{\theta_L} = n_2 \sin{\theta_R}\]

From which we can extract:

    \[\sin{\theta_L} = \frac{n_2}{n_1} \sin{\theta_R}\]

Substituting \sin{\theta_L} and grouping by n_2:

    \[OPD = \frac{2d}{\cos{\theta_R}} \left(n_2 - n_1 \sin{\theta_R} \boxed{\sin{\theta_L }}\right) =\]

    \[= \frac{2d}{\cos{\theta_R}} \left(n_2 - \not{n_1} \sin{\theta_R}\boxed{\frac{n_2}{ \not{n_1}} \sin{\theta_R}}\right) =\]

    \[= \frac{2d}{\cos{\theta_R}} \left(\boxed{n_2} - \sin{\theta_R}\boxed{n_2}\sin{\theta_R}\right) =\]

    \[= \frac{\boxed{n_2} 2 d}{\cos{\theta_R}} \left(1 - \sin^2{\theta_R}\right)\]

From Pythagora’s Theorem:

    \[\cos^2{\theta_R} + \sin^2{\theta_R} = 1\]

    \[1 - \sin^2{\theta_R} = \cos^2{\theta_R}\]

Substituting and simplifying:

    \[OPD= \frac{n_2 2 d}{\cos{\theta_R}}\left(\boxed{1 - \sin^2{\theta_R}}\right) =\]

    \[= \frac{n_2 2 d}{\not{\cos{\theta_R}}}\boxed{\cos^{\not{2}}{\theta_R}}=\]

    \[= n_2 2 d\cos{\theta_R} = OPD\]

❓ How come the diffraction grating equation was not derived using the OPD?

❓ The two light rays are exiting the material from different points!

Phase Shift

Like we discussed in The Mathematics of Diffraction Grating, when the OPD 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:

    \[n_2 2 d  \cos{\theta_R} = n \codt w\]

with n 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 A to medium B, when n_A < n_B.

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 n_{air} < n_{film}. 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, n_{film} > n_{air}, 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:

    \[n_2 2 d \cos{\theta_R} = \left(n + \frac{1}{2}\right) \codt w\]

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?

📰 Ad Break

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:

You can download the Unity package for the CD-ROM Shader and Thin-Film Shader effects on Patreon.

Comments

4 responses to “The Mathematics of Thin-Film Interference”

  1. yanning meng avatar
    yanning meng

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

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

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

Leave a Reply

Your email address will not be published. Required fields are marked *