MaterialGraph
- Module
- AssetSystem
- Header
#include "AssetSystem/Assets/MaterialGraph.h"- Namespace
Mowo
Type aliases
| Alias | Description |
|---|---|
using FStaticSwitchSet = std::vector<FStaticSwitchValue> |
Properties
| Type | Name | Description |
|---|---|---|
std::vector<MaterialGraphNode> | nodes | |
std::vector<MaterialGraphLink> | links | |
uint64_t | nextId | Default 1. |
static constexpr uint32_t | kGraphParamLanes | Default 4. |
static constexpr uint32_t | kGraphParamLanesMax | Default 64. |
static constexpr uint32_t | kFunctionCallMaxInputs | Pins 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_t | kNoErrorNode | "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 float | kWpoBoundUnbounded | Sentinel for an unboundable WPO subtree (see wpoBound). Default 3.0e38f. |
Public functions
| Returns | Name | Description |
|---|---|---|
bool | IsEmpty | |
uint64_t | AddNode | |
void | RemoveNode | |
MaterialGraphNode* | Find | |
const MaterialGraphNode* | Find | |
uint64_t | OutputNodeId | The (first) Output node's id, or 0 when the graph has none. |
uint64_t | Connect | Replaces any existing link into (toNode, toSlot). |
void | Disconnect | |
uint32_t | InputCount | Number of typed input slots a node kind exposes. |
const char* | InputPinName | Label for one input pin. |
bool | IsAttributeNode | Whether a node kind carries a layer bus (FMaterialAttributes) rather than a float4. |
bool | IsSubstrateNode | Whether a node kind carries a Substrate slab. |
uint32_t | SubstrateAlbedoMode | The albedo codebook entry a slab subtree resolves to, following blends down to their inputs. |
uint32_t | FoldSubstrateTop | The authored slab reduced to ONE packed G-Buffer word, or 0 when it does not reduce (outVaries set). |
MaterialCompileResult | Compile | Constant-fold the graph down to the flat PBR + texture-slot result. |
std::string | EmitHLSL | |
ShaderStats | EstimateStats | |
CompiledShader | EmitCompiledShader | The default permutation: every function inlined, every static switch at its StaticBool's own default. |
CompiledShader | EmitCompiledShader | One specific permutation. |
std::vector<std::string> | StaticSwitchNames | Every named static switch reachable in the resolved graph, sorted by name and deduped — the permutation axes, in mask-bit order. |
FStaticSwitchSet | DefaultStaticSwitches | |
FStaticSwitchSet | SwitchSetFromMask | |
uint32_t | MaskFromSwitchSet | |
bool | SwitchValue | |
uint32_t | MaxStaticPermutations | r.Material.MaxStaticPermutations. |
bool | SubstrateEnabled | r.Substrate. |
bool | Resolve | Functions 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> | ReferencedFunctions | Direct function references of this graph (call nodes' paths, deduped). |
std::vector<FFunctionInputDecl> | FunctionInputs | The pins a function body declares, in node order — what a call node shows. |
uint64_t | FunctionOutputNodeId | |
uint32_t | CallInputCount | A call node's pins, resolved through the function library. |
std::string | CallInputPinName | |
bool | CallInputIsScalar | |
const char* | NodeTypeName | Human label for a node kind (palette / node title). |
void | CompileToAsset | Compile + push the result into the asset's Material and texture UUIDs. |
void | Serialize | MDF <-> graph, into/out of a "Graph" child node of the material root. |
bool | Deserialize | |
MaterialGraph | MakeDefault | A minimal starting graph: an Output node fed by a base-color constant. |
bool | Equals | Tolerant structural equality (floats compared with an epsilon) — used by the round-trip self-test. |
Function details
IsEmpty
bool IsEmpty() constAddNode
uint64_t AddNode(MatNodeType type, const Vec2& pos)RemoveNode
void RemoveNode(uint64_t id)Find
MaterialGraphNode* Find(uint64_t id)Find
const MaterialGraphNode* Find(uint64_t id) constOutputNodeId
uint64_t OutputNodeId() constThe (first) Output node's id, or 0 when the graph has none.
Connect
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
void Disconnect(uint64_t linkId)InputCount
static uint32_t InputCount(MatNodeType type)Number of typed input slots a node kind exposes.
InputPinName
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
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
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
uint32_t SubstrateAlbedoMode(uint64_t nodeId, uint64_t& mismatchNode) constThe 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
uint32_t FoldSubstrateTop(uint64_t nodeId, bool& outVaries) constThe 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
MaterialCompileResult Compile() constConstant-fold the graph down to the flat PBR + texture-slot result.
EmitHLSL
std::string EmitHLSL() constEstimateStats
ShaderStats EstimateStats() constEmitCompiledShader
CompiledShader EmitCompiledShader() constThe default permutation: every function inlined, every static switch at its StaticBool's own default.
EmitCompiledShader
CompiledShader EmitCompiledShader(const FStaticSwitchSet& switches) constOne 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
std::vector<std::string> StaticSwitchNames() constEvery named static switch reachable in the resolved graph, sorted by name and deduped — the permutation axes, in mask-bit order.
DefaultStaticSwitches
FStaticSwitchSet DefaultStaticSwitches() constSwitchSetFromMask
static FStaticSwitchSet SwitchSetFromMask(const std::vector<std::string>& names, uint32_t mask, const FStaticSwitchSet& defaults)MaskFromSwitchSet
static uint32_t MaskFromSwitchSet(const std::vector<std::string>& names, const FStaticSwitchSet& set)SwitchValue
static bool SwitchValue(const FStaticSwitchSet& set, const std::string& name, bool fallback)MaxStaticPermutations
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
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
bool Resolve(const FStaticSwitchSet& switches, MaterialGraph& out, std::string& error, uint64_t& errorNode, std::unordered_map<uint64_t, uint64_t>* origin = nullptr) constFunctions 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
std::vector<std::string> ReferencedFunctions() constDirect function references of this graph (call nodes' paths, deduped).
FunctionInputs
std::vector<FFunctionInputDecl> FunctionInputs() constThe 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
uint64_t FunctionOutputNodeId() constCallInputCount
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
static std::string CallInputPinName(const MaterialGraphNode& call, uint32_t slot)CallInputIsScalar
static bool CallInputIsScalar(const MaterialGraphNode& call, uint32_t slot)NodeTypeName
static const char* NodeTypeName(MatNodeType type)Human label for a node kind (palette / node title).
CompileToAsset
void CompileToAsset(MaterialAsset& asset) constCompile + 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
void Serialize(MdfNode& graphNode) constMDF <-> graph, into/out of a "Graph" child node of the material root.
Deserialize
bool Deserialize(const MdfNode& graphNode)MakeDefault
static MaterialGraph MakeDefault(const Vec4& baseColor)A minimal starting graph: an Output node fed by a base-color constant.
Equals
bool Equals(const MaterialGraph& other) constTolerant structural equality (floats compared with an epsilon) — used by the round-trip self-test.