I am new to the graph editor and was able to achieve some results. However, I am noticing that my graphs are getting very tangled, confusing, and hard to debug. I was wondering whether:
-
is it possible to define variables, to store the value of computations, and refer to them in other parts of the graph, without having to link them graphically? This would help in tidying the tangled mess I created. In the "Explore materials in Reality Composer Pro" video, I saw that it is possible to create "instances", but I am not sure if that is what I need. For example: does the shader compiler optimize them, so that there is no need to recompute each instance?
-
Is there any functionality to debug the graph, trying inputs and seeing what the numeric outputs would be?
Hi @eddo
To answer your questions:
- This sounds like something a NodeGraph could help remedy. Node graphs allow you to compose shader logic into reusable chunks, which can help to detangle your shader. Of course, you'll still have to link all the nodes together. You can convert existing nodes into a node graph by highlighting them, control clicking, and selecting Compose Node Graph, or you can simply add a new NodeGraph node to the graph. If you create an instance of a node graph, any changes made to the internal logic of the original node graph will propagate to all of its instance copies, allowing you to efficiently reuse shader logic.
- The simplest approach to debugging the output of a node in your shader is to visualize it with a color. For example, if you want to debug the output of a node that outputs a
float
value, you can Convert thefloat
to acolor3f
and then connect that to theColor
input of an Unlit Surface node, which in turn you can connect to the Outputs node. This will display the output of the node as a color on the surface of your model, where colors from black to white map to values from the range 0 to 1. While this can help you get a preliminary understanding of the output values, it's often good to think about what exactly it is you want to know about the output value. For example, if what you really want to know is whether or not the node is outputting values greater than a certain value, you can utilize an If Greater node with an output of typecolor3f
, and have it output a green color for theTrue Result
and a red color for theFalse Result
. All pixels that appear appear green are pixels for which the output of the node is greater than your specified value.
Happy to share more tips if you have specifics on what it is you're trying to debug!