Compute Graph
Build and run custom particle effects and compute simulations for RealityKit using a programmable node graph.
Overview
Compute Graph is a node-based framework for building particle simulations and general-purpose GPU compute graphs in RealityKit. Where ShaderGraph lets you build material appearance through a node-based visual editor, Compute Graph provides the same graph-driven, connection-based authoring for simulation behavior. Use Compute Graph when you build tools or editors that need fine-grained, per-stage control over how simulations execute on the GPU. Reality Composer Pro uses this framework to author and preview particle systems for RealityKit scenes.
The Swift API centers on a three-step compilation pipeline. Describe a simulation as a ComputeNodeGraph, a directed graph of typed nodes and edges. Then produce a ComputeNodeGraph.Assembly from the graph, which resolves the buffer, uniform, and texture layout the simulation requires. Compile that assembly into ComputeNodeGraph.Pipelines to produce GPU shader code; a single set of pipelines can back multiple ComputeGraphSimulation instances running concurrently. Supply custom Metal Shading Language functions through a ComputeNodeGraph.Library alongside the framework’s built-in node namespaces.
At runtime, ComputeGraphSimulation drives GPU execution. Call advance(_:) each frame, passing a ComputeGraphSimulation.AdvanceParams that carries the time delta, a Metal command buffer, a compute encoder, and optional world-space transforms. To inject elements programmatically, call spawn(elements:in:using:) with ElementSpawnParameters values that set each element’s initial position, velocity, size, color, and lifetime.
Topics
Graph definition and assembly
ComputeNodeGraphComputeNodeGraph.AssemblyComputeNodeGraph.PipelinesComputeNodeGraph.PipelinesDescriptorComputeNodeGraph.NodeDefinitionComputeNodeGraph.LibraryComputeNodeGraph.LibraryReference
Node parameters and connections
Simulation-stage nodes
Utility nodes
graphgrouptexturerandommatrix4x4fmatrix4x4hviewpointelement_integratetexture_sampletexture_sample1dorient_to_velocitygridDebugCellsgridFromPointsspawn_demo
Running a simulation
ComputeGraphSimulationElementSpawnParametersElementGroupingComputeGraphSimulation.SimulationRateSorting
Graph resources
Geometry and simulation inputs
ComputeNodeGraph.TopologyCoordinateSpaceComputeNodeGraph.StructureLayoutStripOrientationViewpointMouseParams