<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/ShaderGraph",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:11ShaderGraphAAC"
  },
  "title" : "ShaderGraph"
}
-->

# ShaderGraph

```
final class ShaderGraph
```

## Topics

### Classes

[`class NodeLibrary`](/documentation/RealityKit/ShaderGraph/NodeLibrary)

A catalog of node definitions supported by RealityKit.

### Structures

[`struct Edge`](/documentation/RealityKit/ShaderGraph/Edge)

Represents a connection between two nodes in a shader graph.

[`struct Node`](/documentation/RealityKit/ShaderGraph/Node)

[`struct NodeDefinition`](/documentation/RealityKit/ShaderGraph/NodeDefinition)

A description of a node type supported by RealityKit, including its inputs, outputs, and platform availability.

### Initializers

[`convenience init(from: Data) throws`](/documentation/RealityKit/ShaderGraph/init(from:))

Creates a graph from data previously produced by [`encode()`](/documentation/RealityKit/ShaderGraph/encode()).

[`init(named: String, inputs: [ShaderGraph.NodeDefinition.Input], outputs: [ShaderGraph.NodeDefinition.Output]) throws`](/documentation/RealityKit/ShaderGraph/init(named:inputs:outputs:))

Creates a shader graph with the given name, inputs, and outputs.

[`init(named: String, inputs: [ShaderGraph.NodeDefinition.Input], outputs: [ShaderGraph.NodeDefinition.Output], nodeLibrary: ShaderGraph.NodeLibrary) throws`](/documentation/RealityKit/ShaderGraph/init(named:inputs:outputs:nodeLibrary:))

Creates a shader graph with the given name, inputs, and outputs.

### Instance Properties

[`var arguments: ShaderGraph.Node`](/documentation/RealityKit/ShaderGraph/arguments)

The virtual node representing this graph’s inputs.

[`var edges: [ShaderGraph.Edge]`](/documentation/RealityKit/ShaderGraph/edges)

[`var functionConstantInputs: [String]`](/documentation/RealityKit/ShaderGraph/functionConstantInputs)

The names of graph inputs whose values are baked in at program compilation time.

[`var inputs: [ShaderGraph.NodeDefinition.Input]`](/documentation/RealityKit/ShaderGraph/inputs)

The declared input ports of this graph.

[`var nodes: [String : ShaderGraph.Node]`](/documentation/RealityKit/ShaderGraph/nodes)

All nodes in the graph, keyed by node name.

[`var outputs: [ShaderGraph.NodeDefinition.Output]`](/documentation/RealityKit/ShaderGraph/outputs)

The declared output ports of this graph.

[`var primvarMappings: [String : ShaderGraph.TextureCoordinate]`](/documentation/RealityKit/ShaderGraph/primvarMappings)

Maps primvar names used in this graph to texture coordinate channels.

[`var results: ShaderGraph.Node`](/documentation/RealityKit/ShaderGraph/results)

The virtual node representing this graph’s outputs.

### Instance Methods

[`func addConstant(ShaderGraph.Value) throws -> String`](/documentation/RealityKit/ShaderGraph/addConstant(_:))

[`func addConstant(ShaderGraph.Value, named: String) throws -> String`](/documentation/RealityKit/ShaderGraph/addConstant(_:named:))

[`func addEdge(ShaderGraph.Edge) throws`](/documentation/RealityKit/ShaderGraph/addEdge(_:))

Adds an edge to the graph.

[`func addNode(ShaderGraph.Node) throws -> String`](/documentation/RealityKit/ShaderGraph/addNode(_:))

Adds a node to the graph and returns its name.

[`func canAddEdge(ShaderGraph.Edge) -> Bool`](/documentation/RealityKit/ShaderGraph/canAddEdge(_:))

Returns whether an edge can be added to the graph.

[`func canAddNode(ShaderGraph.Node) -> Bool`](/documentation/RealityKit/ShaderGraph/canAddNode(_:))

Returns whether a node can be added to the graph.

[`func connect(_:outputPort:to:inputPort:)`](/documentation/RealityKit/ShaderGraph/connect(_:outputPort:to:inputPort:))

Connect a node with a given output, to a node with a given input.
If outputPort is nil, the first output on outputNode is used.

[`func containsEdge(ShaderGraph.Edge) -> Bool`](/documentation/RealityKit/ShaderGraph/containsEdge(_:))

Returns whether the graph contains an edge equal to the given edge.

[`func encode() throws -> Data`](/documentation/RealityKit/ShaderGraph/encode())

Encodes the graph into a binary representation.

[`func removeEdge(ShaderGraph.Edge) throws`](/documentation/RealityKit/ShaderGraph/removeEdge(_:))

Removes an edge from the graph.

[`func removeNode(String) throws`](/documentation/RealityKit/ShaderGraph/removeNode(_:))

[`func replace(nodes: [String : ShaderGraph.Node], edges: [ShaderGraph.Edge]) throws`](/documentation/RealityKit/ShaderGraph/replace(nodes:edges:))

Replaces all nodes and edges in the graph.

[`func updateNode(ShaderGraph.Node, forKey: String) throws`](/documentation/RealityKit/ShaderGraph/updateNode(_:forKey:))

Replaces the node stored under the given name.

[`func validate() -> Bool`](/documentation/RealityKit/ShaderGraph/validate())

Checks whether the graph is well-formed without producing a Metal library.

[`func validateAddingEdge(ShaderGraph.Edge) throws`](/documentation/RealityKit/ShaderGraph/validateAddingEdge(_:))

Validates that an edge can be added to the graph without adding it, throwing a descriptive error if not.

[`func validateAddingNode(ShaderGraph.Node) throws`](/documentation/RealityKit/ShaderGraph/validateAddingNode(_:))

Validates that a node can be added to the graph without adding it, throwing a descriptive error if not.

### Subscripts

[`subscript(String) -> ShaderGraph.Node?`](/documentation/RealityKit/ShaderGraph/subscript(_:))

### Type Aliases

[`typealias EdgeError`](/documentation/RealityKit/ShaderGraph/EdgeError)

[`typealias EdgeType`](/documentation/RealityKit/ShaderGraph/EdgeType)

[`typealias NodeError`](/documentation/RealityKit/ShaderGraph/NodeError)

[`typealias NodeKey`](/documentation/RealityKit/ShaderGraph/NodeKey)

[`typealias NodeType`](/documentation/RealityKit/ShaderGraph/NodeType)

### Enumerations

[`enum DataType`](/documentation/RealityKit/ShaderGraph/DataType)

[`enum TextureCoordinate`](/documentation/RealityKit/ShaderGraph/TextureCoordinate)

[`enum Value`](/documentation/RealityKit/ShaderGraph/Value)

## Relationships

### Conforms To

[`Equatable`](/documentation/Swift/Equatable)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)