This Blend file implements physically correct passing of light through thin films of materials, and allows you to render phenomena such as soap bubbles, oxide layers on metals, thin metal films and polychromic car paints. As a bonus, a physically correct calculation of the Fresnel reflectance for metals is included as well, based on complex indices of refraction (also known as n and k values, see complex refractive index). Here, n stands for the 'classic' index of refraction and k stands for the extinction coefficient, which describes absorption. This combination accurately describes the interaction of light with many types of materials, including glass-like materials, metals and car paints.
The base layer of the material may be coated with one or two thin, possibly absorbing, layers in which interference can occur. Light can interfere with itself, leading to a variety of rainbow-colored phenomena seen in for example oil spills on the street and soap bubbles. See the images for examples rendered with the script (bubbles lit by and background part of free HDR image pack by www.hdrlabs.com [not included]). The previews of single materials are rendered with the provided .blend file.
See original thread
Also, see the talk on this topic I gave at BCon22.
Some helpful hints:
Choosing values for n and k
The shader allows you to enter the values to use for the refractive index (n) and the extinction coefficient (k) for the red, green and blue channels. These values are often listed as a function of the wavelength of the light, for example at refractiveindex.info. Wavelengths that are perceived as red run from something like 625 nm to 670 nm, green is about 520 nm to 550 nm and blue is about 440 nm to 470 nm. Which wavelength you choose to use for red, green and blue depends on your own preference; there is no wrong choice, and the shader will behave physically correct regardless. Of course for different choices of n and k at slightly different wavelengths, the material is likely to change appearance slightly.
Optimized values of n and k for metals
So-called spectral renderers use the tabulated n and k values for each wavelength in the visible light spectrum to calculate what a material should look like. Cycles on the other hand only uses three color channels, one for red, one for green and one for blue. You might wonder what n and k values would best approximate the results of a spectral renderer. I have optimized the values of n and k for the metals that are included in the blend file to look as close as possible to the output from a spectral renderer, when the metal is illuminated with white light.