MaterialModule
The material module of a scene (rendering-revamp §RVM-7): one GLSL function per material definition in use, the instance rows and the parameter values that the renderers read through evalMaterial().
In the namespace construct::shader. Declared in src/libs/libconstruct/construct/shader/MaterialModule.hpp.
Detailed description
Each definition becomes mat_<n>(paramBase), which fills a MaterialInputs, the OpenPBR channels, from the parameter buffer. evalMaterial(instance) reads the instance row and dispatches to the function by index, as the SDF dispatch does for definitions. No value is baked into the GLSL (§EV-2.3): a definition's channels ride in the parameter buffer, each as the CPU resolves it (model::MaterialDefinition::channelValue(), the source flatten() reads), so an edit of a value, a constant included, is an upload and never a compile. Phase 16 replaces the read of a pattern, a gradient or an expression channel with its own code in the definition's function.
Definition 0 is mat_inline: the four numbers and the transparency of a model::Material, for an item that holds an explicit material (a bench, a preview, a thumbnail) and for a node with no document item.
Two instances of one definition with equal values share one row (A7). The GLSL depends only on the set of definitions, so a new value never changes it; source() and sourceKey() say when it does.
A definition keeps its index for the life of the module: clearInstances() drops the instances and keeps the definitions, so a host that rebuilds its instances with every node build gives the shader it already compiled rows it can read. A definition that this shader does not know yet, one that a new module adds while it compiles (§EV-2.4), falls back to the instance's flat values through mat_inline: each instance row names that fallback row.
Until the OpenPBR BSDF of phase 12, the hosts read the module through two adapters to today's shading, sdfMaterialOf() and the tracer's materialRowOf(), which give the numbers flatten() gives. Today's emission is the base color times the luminance (RVPM-5), so a definition that does not declare emission_color binds it to base_color.