class

MaterialGraph

Module
AssetSystem
Header
#include "AssetSystem/Assets/MaterialGraph.h"
Namespace
Mowo

Type aliases

AliasDescription
using FStaticSwitchSet = std::vector<FStaticSwitchValue>

Properties

TypeNameDescription
std::vector<MaterialGraphNode>nodes
std::vector<MaterialGraphLink>links
uint64_tnextIdDefault 1.
static constexpr uint32_tkGraphParamLanesDefault 4.
static constexpr uint32_tkGraphParamLanesMaxDefault 64.
static constexpr uint32_tkFunctionCallMaxInputsPins a call node exposes at most. A function declaring more inputs is refused at compile time rather than silently truncated. Default 8.
static constexpr uint64_tkNoErrorNode"No node" for CompiledShader::errorNode. Node ids are handed out from nextId = 1, so zero can never name a real node. Default 0.
static constexpr floatkWpoBoundUnboundedSentinel for an unboundable WPO subtree (see wpoBound). Default 3.0e38f.

Public functions

ReturnsNameDescription
boolIsEmpty
uint64_tAddNode
voidRemoveNode
MaterialGraphNode*Find
const MaterialGraphNode*Find
uint64_tOutputNodeIdThe (first) Output node's id, or 0 when the graph has none.
uint64_tConnectReplaces any existing link into (toNode, toSlot).
voidDisconnect
uint32_tInputCountNumber of typed input slots a node kind exposes.
const char*InputPinNameLabel for one input pin.
boolIsAttributeNodeWhether a node kind carries a layer bus (FMaterialAttributes) rather than a float4.
boolIsSubstrateNodeWhether a node kind carries a Substrate slab.
uint32_tSubstrateAlbedoModeThe albedo codebook entry a slab subtree resolves to, following blends down to their inputs.
uint32_tFoldSubstrateTopThe authored slab reduced to ONE packed G-Buffer word, or 0 when it does not reduce (outVaries set).
MaterialCompileResultCompileConstant-fold the graph down to the flat PBR + texture-slot result.
std::stringEmitHLSL
ShaderStatsEstimateStats
CompiledShaderEmitCompiledShaderThe default permutation: every function inlined, every static switch at its StaticBool's own default.
CompiledShaderEmitCompiledShaderOne specific permutation.
std::vector<std::string>StaticSwitchNamesEvery named static switch reachable in the resolved graph, sorted by name and deduped — the permutation axes, in mask-bit order.
FStaticSwitchSetDefaultStaticSwitches
FStaticSwitchSetSwitchSetFromMask
uint32_tMaskFromSwitchSet
boolSwitchValue
uint32_tMaxStaticPermutationsr.Material.MaxStaticPermutations.
boolSubstrateEnabledr.Substrate.
boolResolveFunctions and switches, resolved: every MaterialFunctionCall inlined (fresh ids, pins rewired, recursion refused) and every StaticSwitch replaced by a wire from its selected input.
std::vector<std::string>ReferencedFunctionsDirect function references of this graph (call nodes' paths, deduped).
std::vector<FFunctionInputDecl>FunctionInputsThe pins a function body declares, in node order — what a call node shows.
uint64_tFunctionOutputNodeId
uint32_tCallInputCountA call node's pins, resolved through the function library.
std::stringCallInputPinName
boolCallInputIsScalar
const char*NodeTypeNameHuman label for a node kind (palette / node title).
voidCompileToAssetCompile + push the result into the asset's Material and texture UUIDs.
voidSerializeMDF <-> graph, into/out of a "Graph" child node of the material root.
boolDeserialize
MaterialGraphMakeDefaultA minimal starting graph: an Output node fed by a base-color constant.
boolEqualsTolerant structural equality (floats compared with an epsilon) — used by the round-trip self-test.

Function details

IsEmpty

C++
bool IsEmpty() const

AddNode

C++
uint64_t AddNode(MatNodeType type, const Vec2& pos)

RemoveNode

C++
void RemoveNode(uint64_t id)

Find

C++
MaterialGraphNode* Find(uint64_t id)

Find

C++
const MaterialGraphNode* Find(uint64_t id) const

OutputNodeId

C++
uint64_t OutputNodeId() const

The (first) Output node's id, or 0 when the graph has none.

Connect

C++
uint64_t Connect(uint64_t fromNode, uint64_t toNode, uint32_t toSlot)

Replaces any existing link into (toNode, toSlot). Returns the new link id.

Disconnect

C++
void Disconnect(uint64_t linkId)

InputCount

C++
static uint32_t InputCount(MatNodeType type)

Number of typed input slots a node kind exposes.

InputPinName

C++
static const char* InputPinName(MatNodeType type, uint32_t slot)

Label for one input pin. It lives next to InputCount because the two have to grow together: the material editor keeps its own copy of this table, whose default arm labels any slot it has not been taught with the last name in its list — a wrong label rather than a missing one.

IsAttributeNode

C++
static bool IsAttributeNode(MatNodeType type)

Whether a node kind carries a layer bus (FMaterialAttributes) rather than a float4. Mixing the two is a compile error, not a coercion.

IsSubstrateNode

C++
static bool IsSubstrateNode(MatNodeType type)

Whether a node kind carries a Substrate slab. A third bus, kept apart from the layer bus for the reason the two exist separately at all: a horizontal layer blend crossfades seven PBR channels, a slab blend crossfades three slab fields, and a wire that could be either would compile and render plausibly and wrongly.

SubstrateAlbedoMode

C++
uint32_t SubstrateAlbedoMode(uint64_t nodeId, uint64_t& mismatchNode) const

The albedo codebook entry a slab subtree resolves to, following blends down to their inputs. mismatchNode receives the id of the first blend whose two sides disagree (kNoErrorNode when they all agree) — the mode is two bits baked into the shader as a define, so a disagreement is a hard limit and not something to average. Shared with the editor so the diagnostic and the compile error can never drift apart.

FoldSubstrateTop

C++
uint32_t FoldSubstrateTop(uint64_t nodeId, bool& outVaries) const

The authored slab reduced to ONE packed G-Buffer word, or 0 when it does not reduce (outVaries set). Two consumers cache a single answer per surface rather than shading per pixel — the GI surface cache stores one colour per card texel, and the ray-traced hit shading blends against that cache — so both need a slab that is constant over the material. A graph whose coverage rides a texture has no such word, and answering 0 there leaves those two paths shading the base surface exactly as they did before Substrate existed. That is a visible gap, not a silent one: the material editor says so on the node, because an average coat invented here would make a snow line bounce snow-coloured light into the crevices it does not reach.

Compile

C++
MaterialCompileResult Compile() const

Constant-fold the graph down to the flat PBR + texture-slot result.

EmitHLSL

C++
std::string EmitHLSL() const

EstimateStats

C++
ShaderStats EstimateStats() const

EmitCompiledShader

C++
CompiledShader EmitCompiledShader() const

The default permutation: every function inlined, every static switch at its StaticBool's own default.

EmitCompiledShader

C++
CompiledShader EmitCompiledShader(const FStaticSwitchSet& switches) const

One specific permutation. switches overrides the defaults by name; a name the graph does not declare is ignored (an instance may carry a switch its parent has since removed), an axis not named keeps its default.

StaticSwitchNames

C++
std::vector<std::string> StaticSwitchNames() const

Every named static switch reachable in the resolved graph, sorted by name and deduped — the permutation axes, in mask-bit order.

DefaultStaticSwitches

C++
FStaticSwitchSet DefaultStaticSwitches() const

SwitchSetFromMask

C++
static FStaticSwitchSet SwitchSetFromMask(const std::vector<std::string>& names, uint32_t mask, const FStaticSwitchSet& defaults)

MaskFromSwitchSet

C++
static uint32_t MaskFromSwitchSet(const std::vector<std::string>& names, const FStaticSwitchSet& set)

SwitchValue

C++
static bool SwitchValue(const FStaticSwitchSet& set, const std::string& name, bool fallback)

MaxStaticPermutations

C++
static uint32_t MaxStaticPermutations()

r.Material.MaxStaticPermutations. A graph whose 2^N exceeds it fails to compile with an error naming the axis that crossed the line — the cook would otherwise compile that many blobs per pass template per target.

SubstrateEnabled

C++
static bool SubstrateEnabled()

r.Substrate. Read at EMIT time, not at shade time: with it off the Output node's Substrate slot is not read at all, so a graph that authors a slab emits the same source it would have emitted without one and every committed sidecar, hash and cooked blob name is unmoved. Changing it requires recompiling the materials that use it.

Resolve

C++
bool Resolve(const FStaticSwitchSet& switches, MaterialGraph& out, std::string& error, uint64_t& errorNode, std::unordered_map<uint64_t, uint64_t>* origin = nullptr) const

Functions and switches, resolved: every MaterialFunctionCall inlined (fresh ids, pins rewired, recursion refused) and every StaticSwitch replaced by a wire from its selected input. origin maps each node that came out of a function body to the call node in THIS graph, so a refusal raised inside a body can be pointed at the call. Returns false with error/errorNode set on a missing function, a recursion or a non-StaticBool feeding a switch's Value pin.

ReferencedFunctions

C++
std::vector<std::string> ReferencedFunctions() const

Direct function references of this graph (call nodes' paths, deduped).

FunctionInputs

C++
std::vector<FFunctionInputDecl> FunctionInputs() const

The pins a function body declares, in node order — what a call node shows. Reads the graph as a function; a material graph reports none.

FunctionOutputNodeId

C++
uint64_t FunctionOutputNodeId() const

CallInputCount

C++
static uint32_t CallInputCount(const MaterialGraphNode& call)

A call node's pins, resolved through the function library. An unresolvable function reports zero pins so the canvas shows the node as broken rather than with eight anonymous inputs.

CallInputPinName

C++
static std::string CallInputPinName(const MaterialGraphNode& call, uint32_t slot)

CallInputIsScalar

C++
static bool CallInputIsScalar(const MaterialGraphNode& call, uint32_t slot)

NodeTypeName

C++
static const char* NodeTypeName(MatNodeType type)

Human label for a node kind (palette / node title).

CompileToAsset

C++
void CompileToAsset(MaterialAsset& asset) const

Compile + push the result into the asset's Material and texture UUIDs. The push is transparent to the override mask (it reproduces the graph, it does not author fields), and it is refused outright on a material that has a parent: a graph is a ROOT material's authoring surface, an instance is a mask over one.

Serialize

C++
void Serialize(MdfNode& graphNode) const

MDF <-> graph, into/out of a "Graph" child node of the material root.

Deserialize

C++
bool Deserialize(const MdfNode& graphNode)

MakeDefault

C++
static MaterialGraph MakeDefault(const Vec4& baseColor)

A minimal starting graph: an Output node fed by a base-color constant.

Equals

C++
bool Equals(const MaterialGraph& other) const

Tolerant structural equality (floats compared with an epsilon) — used by the round-trip self-test.

Generated from AssetSystem/Assets/MaterialGraph.h via assetsystem.json · Nov 4, 2026Version 1.0.0