How CAD Shaders Simulate Metal, Glass, and Plastic
In modern Computer-Aided Design (CAD), material shaders rely on Physically Based Rendering (PBR) algorithms to mimic how real-world surfaces interact with light. By mathematically calculating optical phenomena such as reflection, refraction, absorption, and microfacet scattering, these mathematical models transform raw mathematical geometry into photorealistic representations. This article breaks down how CAD rendering engines use specific parameters—such as base color, roughness, index of refraction, and transmission—to accurately distinguish and simulate the distinct visual behaviors of metal, glass, and plastic.
The Foundation: The Bidirectional Reflectance Distribution Function (BRDF)
At the core of CAD shading is the Bidirectional Reflectance Distribution Function (BRDF). The BRDF calculates how much light reflecting off a surface point is scattered in various directions based on the incoming light angle and the viewing angle. Shaders rely heavily on the microfacet theory, which treats surfaces as microscopic distributions of tiny mirrors. A "roughness" map dictates whether these microfacets align uniformly (yielding sharp, mirror-like reflections) or randomly (yielding soft, diffuse blurs).
Simulating Metals: Conductive Surfaces
In physics, metals are electrical conductors. When photons strike a conductor, free electrons interact immediately with the incoming electromagnetic wave. Shaders simulate this unique behavior through specific mathematical rules:
- No Diffuse Reflection: Unlike non-metals, pure metals do not allow light to penetrate beneath the surface and scatter back out. Consequently, a metal shader sets the diffuse component to zero. All visible light originates from specular reflection.
- Tinted Specular Highlights: In non-conductive materials, specular reflections reflect the exact color of the light source (usually white). In metals, specific wavelengths of light are absorbed by the free electrons, causing the reflected light to take on the base color of the metal itself. Gold, for example, reflects yellow and red wavelengths while absorbing blue.
- High Base Reflectance: Metals reflect a significant portion of light even at normal incidence (facing directly toward the camera), often between 70% and 95%, characterized by high extinction coefficients in their complex refractive index calculations.
Simulating Glass: Specular Dielectrics and Transmission
Glass is an electrical insulator (dielectric) that allows light to pass directly through its mass rather than merely bouncing off its boundary. Shaders handle glass by switching from surface reflection to volumetric calculation:
- Index of Refraction (IOR) and Snell’s Law: The critical parameter for glass is its IOR, typically around 1.5 to 1.52 for standard crown glass. The shader uses Snell’s Law to bend light rays as they enter and exit the boundary between air and the digital solid.
- Fresnel Effect: The Fresnel equations govern how much light reflects versus how much transmits. At normal angles (looking straight at a pane of glass), only about 4% of the light reflects, while 96% passes through. At grazing angles, reflection increases toward 100%.
- Absorption and Beer-Lambert Law: To simulate tinted or dense glass, CAD engines implement the Beer-Lambert Law. This calculates light attenuation as a function of the distance light travels through the 3D volume, making thick sections of a model appear darker or more saturated than thin sections.
Simulating Plastic: Two-Layer Dielectrics
Plastics are also dielectric materials, but they feature an internal structure fundamentally different from glass. A plastic shader typically uses a two-layer composite model: a colored bulk substrate beneath a clear, smooth exterior coat.
- Separation of Diffuse and Specular Properties: Light hitting plastic either reflects off the outer boundary layer or penetrates into the pigment layer. The outer reflection is pure specular reflection, meaning it reflects the light source’s color without alteration (resulting in sharp white highlights).
- Subsurface Scattering and Diffuse Color: Light that enters the material bounces repeatedly off pigment particles before emerging in random directions. The shader models this as the diffuse base color, absorbing certain wavelengths according to the material's dye.
- Low Normal Reflectance: Unlike metals, plastic reflects only about 2% to 5% of light at a direct 90-degree viewing angle (IOR roughly between 1.45 and 1.5). The strong glossy look common to polished plastics is primarily perceived at shallow, grazing viewing angles due to the Fresnel equation.