Simulating Oil Slicks and Bubbles with glTF Iridescence
This article explains how the KHR_materials_iridescence
extension in glTF enables 3D graphics engines to realistically simulate
optical phenomena like soap bubbles and oil slicks. By introducing a
physically based thin-film interference model into standard PBR
(Physically Based Rendering) workflows, this extension allows digital
materials to shift colors dynamically based on light angle, view
perspective, and layer thickness without relying on pre-baked color
textures.
The Physics: Thin-Film Interference
The iridescent colors observed on oil films, soap bubbles, and insect wings do not originate from chemical pigments. Instead, they are caused by thin-film wave interference.
When a light ray strikes a surface covered by an ultra-thin transparent or semi-transparent layer:
- Part of the light wave reflects off the top boundary of the thin film.
- The remaining light enters the film, refracts, reflects off the lower boundary (the substrate interface), and exits back into the air.
Because the second wave travels a slightly longer distance, it exits out of phase with the first wave. Depending on the film's thickness, its refractive index, and the observer's viewing angle, specific wavelengths of light constructively interfere (amplifying certain colors) while others destructively interfere (canceling out). As the angle of view shifts, the path length changes, creating the characteristic rainbow sheen.
Core Parameters of
KHR_materials_iridescence
The glTF extension KHR_materials_iridescence captures
this behavior mathematically using a set of dedicated properties:
iridescenceFactor: A scalar value (0.0 to 1.0) and optional texture that defines the intensity and presence of the iridescence across the model.iridescenceIor: The Index of Refraction (IOR) of the thin film. This dictates how much light slows down and bends inside the film layer, directly influencing phase shifts and reflectance. Typical values range from 1.3 to 1.6.iridescenceThicknessMinimumandiridescenceThicknessMaximum: Defines the physical range of the film’s thickness in nanometers (nm). Most visible interference effects occur between 100 nm and 800 nm.iridescenceThicknessTexture: A grayscale map that interpolates between the minimum and maximum thickness values across the surface. This map is vital for breaking visual uniformity.
Recreating Soap Bubbles
To replicate a soap bubble in glTF:
- Base Material: Set low roughness (near 0.0) for a
crisp specular reflection and combine it with the
KHR_materials_transmissionextension to make the substrate transparent. - Film IOR: Set
iridescenceIorto approximately 1.33, which matches the optical density of water/soapy liquid. - Thickness Variation: A soap bubble film constantly
thins due to gravity and air currents. By defining a thickness range
roughly between 100 nm and 400 nm and supplying an animated or swirling
noise map via
iridescenceThicknessTexture, the bubble produces characteristic soft, pastel color bands that shift dynamically as the bubble deforms or rotates.
Recreating Oil Slicks
Simulating an oil slick on water or wet asphalt uses a similar approach with different material inputs:
- Substrate: The underlying base is typically dark and opaque (low transmission, low base color values) to represent wet pavement or deep water, providing maximum contrast for the surface reflections.
- Film IOR: Hydrocarbons like petroleum have a higher
refractive index than water, usually between 1.45 and 1.50. Setting
iridescenceIorwithin this range shifts the interference to produce deeper, more saturated hues. - Thickness Gradient: Oil spreads unevenly across fluid or rough surfaces, creating stepped puddles. Setting the thickness range between 200 nm and 800 nm with a non-uniform texture generates the distinct rings of cyan, yellow, magenta, and green typically observed along the perimeter of a puddle.
Efficient Real-Time Rendering
Full spectral simulation of light waves is too computationally
expensive for real-time applications. Renderers supporting
KHR_materials_iridescence approximate the Airy
equations—the analytical formulas for wave interference in single-layer
coatings. By resolving these equations into standard RGB outputs at the
fragment stage, glTF engines deliver physically accurate,
angle-dependent color shifts at negligible performance cost.