Skip to content

Documentation / scene / MaterialBlueprintIR

Class: MaterialBlueprintIR

Defined in: libs/scene/src/utility/blueprint/material/ir.ts:1218

Material Blueprint Intermediate Representation

Remarks

The IR is a compiled representation of the material node graph that can be efficiently translated to shader code. It performs:

  • Type checking and validation
  • Expression optimization (common subexpression elimination via reference counting)
  • Uniform extraction (constants become shader uniforms)
  • Dependency analysis (determines required vertex attributes)

The compilation process:

  1. Traverse the DAG in topological order
  2. Build an IR expression tree
  3. Track uniforms and behaviors
  4. Generate optimized shader code from the IR

Constructors

Constructor

new MaterialBlueprintIR(dag, hash, editorState): MaterialBlueprintIR

Defined in: libs/scene/src/utility/blueprint/material/ir.ts:1250

Creates and compiles a material blueprint IR

Parameters

dag

BlueprintDAG

The material node graph DAG

hash

string

Unique identifier for this material

editorState

BluePrintEditorState

Editor state snapshot

Returns

MaterialBlueprintIR

Remarks

Automatically compiles the DAG during construction. Check the ok property to verify successful compilation.

Accessors

ok

Get Signature

get ok(): boolean

Defined in: libs/scene/src/utility/blueprint/material/ir.ts:1269

Whether the IR compiled successfully

Returns

boolean

True if compilation produced valid outputs


hash

Get Signature

get hash(): string

Defined in: libs/scene/src/utility/blueprint/material/ir.ts:1273

Gets the unique hash for this material

Returns

string


editorState

Get Signature

get editorState(): BluePrintEditorState

Defined in: libs/scene/src/utility/blueprint/material/ir.ts:1277

Gets the editor state snapshot

Returns

BluePrintEditorState


behaviors

Get Signature

get behaviors(): MaterialBlueprintIRBehaviors

Defined in: libs/scene/src/utility/blueprint/material/ir.ts:1281

Gets the behavior flags indicating shader requirements

Returns

MaterialBlueprintIRBehaviors


DAG

Get Signature

get DAG(): BlueprintDAG

Defined in: libs/scene/src/utility/blueprint/material/ir.ts:1285

Gets the material node DAG

Returns

BlueprintDAG

Set Signature

set DAG(dag): void

Defined in: libs/scene/src/utility/blueprint/material/ir.ts:1288

Parameters
dag

BlueprintDAG

Returns

void


uniformValues

Get Signature

get uniformValues(): IRUniformValue[]

Defined in: libs/scene/src/utility/blueprint/material/ir.ts:1292

Gets the array of uniform values to set at runtime

Returns

IRUniformValue[]


uniformTextures

Get Signature

get uniformTextures(): IRUniformTexture[]

Defined in: libs/scene/src/utility/blueprint/material/ir.ts:1296

Gets the array of uniform textures to bind at runtime

Returns

IRUniformTexture[]

Methods

compile()

compile(): boolean

Defined in: libs/scene/src/utility/blueprint/material/ir.ts:1311

Compiles the material node graph to IR

Returns

boolean

True if compilation succeeded, false otherwise

Remarks

Processes all root nodes (typically a single material output node) and builds IR expressions for all connected inputs. Collects all required uniforms and sets behavior flags.

Compilation fails if any required input is missing.


create()

create(pb): object[]

Defined in: libs/scene/src/utility/blueprint/material/ir.ts:1369

Generates shader code from the IR

Parameters

pb

ProgramBuilder

The program builder to generate code with

Returns

object[]

Array of named shader expressions, or null if IR is invalid

Remarks

Translates all IR expressions to actual shader code. Should be called within a shader function scope.

Example

typescript
pb.fragmentShader(function() {
  const outputs = ir.create(this);
  this.baseColor = outputs.find(o => o.name === 'baseColor').exp;
  this.normal = outputs.find(o => o.name === 'normal').exp;
});

Released under the MIT License.