Materials
Every material is one set of OpenPBR parameters. There is no material class hierarchy: a glass, a car paint and a velvet are the same record with different weights. The scene copy stores each material as a 128-byte record, and the path tracer turns the record into a BSDF at every hit.
Two spellings
import { openPbrToRtMaterial, type RtMaterialInput } from '@pmndrs/raytracer';
const materials: RtMaterialInput[] = [
{ baseColor: [0.9, 0.6, 0.2], metalness: 1, specularRoughness: 0.25 }, // RtMaterialInput: gold-like metal
openPbrToRtMaterial({ transmissionWeight: 1, specularIor: 1.5, specularRoughness: 0 }), // clear glass
];
Two defaults differ between the spellings: the coat IOR (1.5 in RtMaterialInput, OpenPBR's 1.6 in OpenPbrParams) and the sheen/fuzz roughness (0.3 and 0.5). anisotropyRotation is in turns in RtMaterialInput and in radians in OpenPbrParams.
Parameters (RtMaterialInput)
Roughness is perceptual (GGX alpha = roughness²). Textures multiply their factors as glTF does: base colour × texture, roughness × G, metalness × B, emission × texture.
What gets rendered
At each hit the path tracer picks one BSDF from the record. The rules, in order:
On top of these:
- Sheen:
sheenWeight> 0 with a non-blacksheenColorwraps the BSDF in OpenPBR's fuzz layer (Zeltner's LTC sheen). - Thin film: an uncoated metal or opaque dielectric with
thinFilmWeight> 0 gets an iridescent Fresnel. It needslayering: 'albedo'(below). - Anisotropy:
specularAnisotropystretches the GGX lobe of metals along the vertex tangent. The mesh needs tangents (glTFTANGENT). - Emission: from the front face, or both faces with
emissionTwoSided. An emitter without an emission texture is also a light (see Lights). - Alpha mask: with
alphaModemask, a hit where the base colour alpha ×opacityis belowalphaCutoffis passed through. The kernel only compiles the cutout test for a textured scene.
The coat weight and the transmission weight are thresholded at 0.5: there is no partial coat or partial transmission. These parameters are stored but not rendered yet: coat colour, alphaMode blend (partial opacity renders opaque), subsurface, diffuse roughness, and the metal's F82 tint. dispersion is only read in spectral mode (Experimental).
Layered BSDF settings
The layered BSDF (a dielectric interface over a base) has two ways to evaluate it:
With 'albedo', albedoBase: 'internal' (default) is the closed form of a diffuse base under a dielectric; 'openpbr' uses the OpenPBR specification's albedo scaling instead. albedoCorrection brings the closed form's energy to the random walk's on rough interfaces: 'texture' (default, an 8 × 8 lookup texture), 'lut' (the same table as WGSL constants) or 'none'.
const options = ptSceneOptions(scene, { layered: { layering: 'stochastic' } });
Only the lobes a scene uses
Each lobe costs WGSL, and a big kernel compiles slowly (on Windows in particular). ptSceneOptions(scene) calls ptMaterialFeatures on the scene's material table and compiles only what the table needs:
Every material in the table counts, even one no ray ever hits.
If you write kernel options by hand, pass integrator.materials ({ features: ptMaterialFeatures(records) }) as ptSceneOptions does. Without it the kernel uses its legacy material adapter, which renders every non-metal as pure Lambert. See Integrator options.
glTF
loadGltf maps glTF materials and their KHR_materials_* extensions to these parameters. Loading glTF has the table.