Materials and typed shader graphs¶
A material definition declares a graph, stable parameters, binding layout, and model/domain contracts. A material instance supplies parameter values and resource bindings. Scene submissions refer to a material instance of the current runtime. Passes select a prepared program and pipeline for the model, material variant, render target, and geometry contract they consume.
Choose the right variability¶
Pick a uniform or descriptor edit for a value that keeps the same program and binding layout. A graph feature changes the authored graph code. A shading-model feature changes the evaluator’s code inclusion. Keep the two feature identities distinct. Disable code only for features whose omission preserves the declared material response.
The shader builder records typed C++ graph operations and produces target shader programs through lowering, target compilation, and linking. Keep bindings and semantic inputs in the graph contract and retain the resulting program metadata. Reusable shader modules can be prepared and linked with explicit identities in the available compiler workflows. Module parse, IR load, link, final backend code generation, and native pipeline creation are distinct operations with separate compatibility and performance costs.
Arrange preparation¶
Build shader and pipeline resources before recording. A material that changes layouts, uses another feature combination, or becomes visible for a new pass may require another prepared variant. Use the renderer’s async preparation route and keep the current prepared material available during a replacement where the profile supports it.
On a compiler-free configuration require matching compiled program artifacts. Development compilation requires policy permission and a configured compiler/provider. Durable artifacts and native driver caches reduce repeat work when their identities match. See Resources, native content, and caching.
OpenPBR surface and working colors¶
The supplied OpenPBR surface supports authoring base, glossy, coat, fuzz, transmission, subsurface, thin-film, and emission behavior. The material describes the response at a surface. Lighting, reflection, and transport systems determine what arrives there and where it travels.
The stock OpenPBR working basis is scene-linear ACEScg. Other producers can declare linear Rec.709 and convert at the explicit boundary. Decode texture transfer encoding once, convert color inputs when entering the working space, and sample normal, roughness, mask, and other data maps as data. Texture storage format, working RGB basis, exposure, creative look, tone mapping, display gamut, and surface transfer are separate decisions. A scene-referred grade LUT uses the working basis at its declared boundary. See OpenPBR raster and progressive transport for current transport coverage.
Compose part of a shader graph¶
This function excerpt authors one scene-linear RGB output into an existing graph. The caller owns stage construction and declares the type and role of the output in its consumer. A graph expression belongs to the same builder that owns its dependencies.
#include <Renderer/ShaderContracts/Shaders/Graph/ShaderGraphBuilder.h>
namespace SnAPI::Renderer::Docs
{
// Build a typed color output for a graph consumer that declares a Color result.
void AddTintedColor(ShaderGraphBuilder& graph, const ShaderFloat3& linearColor)
{
const auto tint = graph.Float3(0.8f, 0.6f, 0.25f);
graph.Output("Color", graph.Multiply(linearColor, tint));
}
}
The literal and multiplication are recorded in typed shader IR. Nothing executes on the GPU until the graph belongs to an admitted, prepared program and a pass records work. The color here is already in the graph’s working basis.