How to programatically set ShaderGraphMaterial properties?
Asked Answered
D

1

3

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?

Doenitz answered 19/1 at 6:31 Comment(0)
P
3

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

Pharisaic answered 19/1 at 6:56 Comment(1)
My confusion was that I was trying to make one of my nodes a parameter. I had to deselect all the nodes (by just clicking on the background). Then I could see the "New Input" option in the Inspector.Doenitz

© 2022 - 2024 — McMap. All rights reserved.