UPDATE 2.0: Updated for my presentation at the Blender Conference 2022
I updated the OSL script to use the current language features and made GPU-compatible nodes from it with OSLPy. The output is fully benchmarked against optical models I used as a scientific researcher in nanophotonics. Get the Node group (Blender 3.3) plus all materials shown below here:
OSL Scripts used to generate the node:
Note: you’ll need a modified OSLPy in order to generate the node groups.
This post will be updated over the course of the week!
Example output:
Blend file
Background
The colors of soap bubbles is caused by a phenomenon called thin-film interference. Cycles does not natively support the calculation of this effect, but I have implemented a model which, within the limitations of Cycles, gives accurate results. In order to calculate accurate results, the Node Group needs the refractive index of the materials involved.
Next to soap bubbles and other glassy materials, oxide layers on metals can also be accurately calculated. Below the heating of iron is shown, where an increased temperature corresponds to a thicker oxide layer, which in turn causes the color to change.
The blend file above has the following material presets (change the material of the test object to view)
These materials are examples of how the Node Group can be used to calculate common interference phenomena in Blender.
Using the Node Groups:
To be updated, but you can watch the presentation
1.3 Outputs:
- R: reflected percentage of the light, per color (RGB), at the angle between the normal and the ray of light.
- T: transmitted percentage of light, per color. Can be hooked up to a refractive shader.
By hooking these up to glossy and refractive shaders, metallic and glass-like materials can be made. Examples are present in the blend file.
2.1 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. The node groups use:
- 650 nm for red
- 532 nm for green
- 450 nm for blue
2.2 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 (D65 white point).