Table of Contents
MaterialX support in TinyUSDZ
- Support Blender v5.x exported MaterialX(OpenPBR)
- MaterialXConfigAPI inline description of MaterialX material.
- No support for shader network in Tydra RenderMaterial
NOTE: MaterialX Parser Logic Summary in OpenUSD
v25.11
This document summarizes the node graph parsing logic in pxr/usd/usdMtlx/parser.cpp.
Overview
The parser converts MaterialX node definitions into USD's Sdr (Shader Definition Registry) shader nodes. It implements SdrParserPlugin to integrate with USD's shader discovery system.
Key Components
1. ShaderBuilder (lines 78-136)
A builder pattern class that accumulates data for constructing SdrShaderNode:
- Fields:
discoveryResult,valid,definitionURI,implementationURI,context,properties,metadata - AddPropertyNameRemapping(): Maps MaterialX property names to USD names
- AddProperty(): Converts MaterialX typed elements to
SdrShaderProperty - Build(): Creates the final
SdrShaderNodeUniquePtr
2. Property Parsing (AddProperty, lines 224-391)
Converts MaterialX inputs/outputs to Sdr properties:
- Type Resolution: Maps MaterialX types to USD Sdf types via
UsdMtlxGetUsdType() - Default Values: Extracts via
UsdMtlxGetUsdValue() - Metadata Extraction:
defaultinputfor outputstargetfor inputscolorspacefor inputs/outputs- UI metadata:
uiname,doc,uifolder,uimin,uimax,uisoftmin,uisoftmax,uistep - Unit info:
unit,unittype
- Primvar Handling: Tracks
defaultgeompropreferences, replacingUV0with the configured primary UV set name
3. ParseElement (lines 436-551)
Main NodeDef parsing function:
-
Context Determination (lines 444-454):
- Checks type's semantic for "shader" to get context
- Falls back to standard typedefs
- Defaults to
SdrNodeContext->Pattern
-
Node Metadata (lines 462-467):
Label= nodeDef's node stringCategory= nodeDef's typeHelpfromdocattributeTargetfromtargetattributeRolefromnodegroupattribute
-
Primvar Collection (lines 471-535):
ND_geompropvalue*nodes: add$geompropND_texcoord_vector2: add primary UV set name- Implementation NodeGraph traversal:
geompropvaluenodes: extract primvar fromgeompropinputtexcoordnodes: add primary UV setimage/tiledimagenodes: add primary UV set if no texcoord already added
internalgeompropsattribute: parse and add primvars
-
Property Collection (lines 538-544):
- Iterates
nodeDef->getActiveInputs()for input properties - Iterates
nodeDef->getActiveOutputs()for output properties
- Iterates
4. UsdMtlxParserPlugin (lines 556-643)
The main parser plugin:
ParseShaderNode() (lines 567-622):
- Load MaterialX document from
resolvedUriorsourceCode - Look up NodeDef by
identifierorsubIdentifier - Create
ShaderBuilderand callParseElement() - Return built shader node
GetDiscoveryTypes(): Returns ["mtlx"]
GetSourceType(): Returns empty string (default source type)
Data Flow
MaterialX Document
│
▼
NodeDef lookup
│
▼
ShaderBuilder
│
├─── ParseElement() ───┬─── Extract context
│ ├─── Extract metadata
│ ├─── Collect primvars
│ └─── Parse inputs/outputs
│
▼
AddProperty() for each input/output
│
├─── Type conversion (UsdMtlxGetUsdType)
├─── Default value (UsdMtlxGetUsdValue)
├─── Metadata extraction
└─── Primvar tracking
│
▼
ShaderBuilder.Build()
│
▼
SdrShaderNode
Key Tokens (lines 32-56)
Private tokens for attribute names:
mtlx,defaultgeomprop,defaultinput,doc,enum,enumvaluesnodecategory,nodegroup,target,uifolder,uimax,uiminuiname,uisoftmax,uisoftmin,uistep,unit,unittype,UV0
Environment Settings
USDMTLX_PRIMARY_UV_NAME: Override the primary UV set name (defaults to USD'sUsdUtilsGetPrimaryUVSetName(), typically "st")
Role Normalization (lines 405-414)
For stdlib texture nodes, texture2d and texture3d roles are normalized to texture for Sdr compatibility.