This is a WIP proposal for how to provide utilities for "flattening" graphs within MaterialX.
Criteria:
The ability to choose which "roots" within a graph to flatten.
one or more selected outputs
a selected node or a selected subset of nodes
selection based on an attribute, or metadata. (e.g. based on "target")
The choice of flattening
just a node
a node + all upstream nodes.
just upstream nodes.
The ability to flatten nodes which are implemented as nodegraphs. This can even include "standard library" definitions:
Note that this is a desired ability to have for creating a copy of an implementation for "publishing" workflows.
e.g. "glossiness_anisotropy"
"flattened"
If a node has attributes / metadata on parent nodes then there should be the option to pass these on to the flattened nodes.
The ability to flatten "in-place" or create extracted copies of "flattened" nodes.
The extraction process should take into account upstream data inputs such as geometry streams.
It is possible to add a "action" hook for each sub-graph to flatten. For example a shader generation "hook" could be provided where a given node is selected and to create the shader for all upstream nodes a temporary output is created to perform sampling with.
Note that this flattening logic is complimentary to existing image "baking" utilities by adding baking a the "action".
Note that flattening logic can be hooked into "reference" implementation generation as well (currently no implementations are output for nodegraph implementations).
This is a WIP proposal for how to provide utilities for "flattening" graphs within MaterialX.
Criteria:
The ability to choose which "roots" within a graph to flatten.
The choice of flattening
The ability to flatten nodes which are implemented as nodegraphs. This can even include "standard library" definitions:
If a node has attributes / metadata on parent nodes then there should be the option to pass these on to the flattened nodes.
The ability to flatten "in-place" or create extracted copies of "flattened" nodes.
It is possible to add a "action" hook for each sub-graph to flatten. For example a shader generation "hook" could be provided where a given node is selected and to create the shader for all upstream nodes a temporary output is created to perform sampling with.
Note that this flattening logic is complimentary to existing image "baking" utilities by adding baking a the "action".
Note that flattening logic can be hooked into "reference" implementation generation as well (currently no implementations are output for nodegraph implementations).