MaterialProgram

The GLSL function of one material definition, and the plan of the values it reads from the parameter buffer (rendering-revamp §RVM-6, §RVM-7).

In the namespace construct::shader. Declared in src/libs/libconstruct/construct/shader/MaterialProgram.hpp.

Detailed description

A definition's channels come from five kinds of source: a constant, a parameter, a pattern through a remap, a pattern through a gradient, and an expression; a normal input takes a bump. build() writes one function, MaterialInputs FN(uint b, SurfaceContext ctx, MaterialPatternValues pv), with a helper for each gradient. In the GLSL, FN is a placeholder in double braces, and the module puts the definition's name in its place. The patterns' values come in pv: build() writes FN_patternSetup() and FN_patternCount(), and the module evaluates every pattern of every definition at one call site of the fields (MaterialModule, materialPatternsOf()), so the driver inlines each field once, not once per definition. A placeholder FIELD:id in double braces stands for the module's number of field record id. Every number of the record that is not code (a constant, a parameter's value, a remap bound, a gradient stop, a pattern's scale and parameters) is a slot of the parameter block, read at b, so a value edit is an upload and never a compile (§EV-2.3). Expressions are code, through expredit::ExprCompiler::lowerToGlsl().

The block starts with the channels of MaterialModule::layoutOf(), each the value MaterialDefinition::channelValue() resolves, as phase 11 packed them: a procedural channel's slot holds its flat value, which the function does not read. The procedural slots follow, in the order build() met them.

A pattern evaluates a field record (a field_ function, renamed by the module) at the shading point, in the item's frame (object), in world space (world), or in the frame of a named field item of the scene with that item's own parameters (item). A pattern whose code cannot be built, an unknown field or an expression the compiler refuses, makes the whole program refuse: error() says why, and the function reads only the channel slots, the flat material.

In this section