Search code examples
swiftrealitykitvisionosreality-composer-pro

How to programatically set ShaderGraphMaterial properties?


I have successfully loaded a ShaderGraphMaterial object from a Reality Composer Pro usda file -- here is a the graph program:

enter image description here

When I attempt to set a parameter

try shotTrailMaterial?.setParameter(name: "TimeDelay.Value", value: .float(1.0))

I get a parameterNameNotFound exception. What am I missing? What is the trick to defining and/or accessing these shader parameters?


Solution

  • Here's a sequence of actions to create MaterialX controlled parameter in ShaderGraph:

    • select YourMaterial in RCP left pane
    • in Inspector, choose New Input
    • add Name and correct Type of parameter
    • click Add (this adds a blue node to the Graph)
    • connect this node to any node's input you're going to control
    • then in RealityKit, use the following code

    enter image description here