6#ifndef MATERIALX_SHADERGRAPH_H
7#define MATERIALX_SHADERGRAPH_H
23MATERIALX_NAMESPACE_BEGIN
62 bool isAGraph()
const override {
return true; }
71 const vector<ShaderNode*>&
getNodes()
const {
return _nodeOrder; }
92 const vector<ShaderGraphInputSocket*>&
getInputSockets()
const {
return _outputOrder; }
93 const vector<ShaderGraphOutputSocket*>& getOutputSockets()
const {
return _inputOrder; }
177 const string& sourceColorSpace,
const string& targetColorSpace,
bool asInput);
187 std::unordered_map<string, ShaderNodePtr> _nodeMap;
188 std::vector<ShaderNode*> _nodeOrder;
192 std::unordered_map<ShaderInput*, ColorSpaceTransform> _inputColorTransformMap;
194 std::unordered_map<ShaderInput*, UnitTransform> _inputUnitTransformMap;
197 std::unordered_map<ShaderOutput*, ColorSpaceTransform> _outputColorTransformMap;
199 std::unordered_map<ShaderOutput*, UnitTransform> _outputUnitTransformMap;
226 return _upstream == rhs._upstream &&
227 _downstream == rhs._downstream &&
228 _stack == rhs._stack;
232 return !(*
this == rhs);
260 using StackFrame = std::pair<ShaderOutput*, size_t>;
261 std::vector<StackFrame> _stack;
262 std::set<ShaderOutput*> _path;
265MATERIALX_NAMESPACE_END
Color management system classes.
shared_ptr< class ColorManagementSystem > ColorManagementSystemPtr
A shared pointer to a ColorManagementSystem.
Definition: ColorManagementSystem.h:25
The top-level Document class.
shared_ptr< const Document > ConstDocumentPtr
A shared pointer to a const Document.
Definition: Document.h:24
shared_ptr< Element > ElementPtr
A shared pointer to an Element.
Definition: Element.h:31
shared_ptr< ValueElement > ValueElementPtr
A shared pointer to a ValueElement.
Definition: Element.h:41
std::set< string > StringSet
A set of strings.
Definition: Library.h:59
Macros for declaring imported and exported symbols.
shared_ptr< const Node > ConstNodePtr
A shared pointer to a const Node.
Definition: Node.h:26
shared_ptr< class ShaderGraph > ShaderGraphPtr
A shared pointer to a shader graph.
Definition: ShaderGraph.h:39
Classes for nodes created during shader generation.
shared_ptr< class ShaderNode > ShaderNodePtr
Shared pointer to a ShaderNode.
Definition: ShaderNode.h:35
Base class for syntax handling for shader generators.
std::unordered_map< string, size_t > IdentifierMap
Map holding identifier names and a counter for creating unique names from them.
Definition: Syntax.h:35
Type descriptor for a MaterialX data type.
shared_ptr< class UnitSystem > UnitSystemPtr
A shared pointer to a UnitSystem.
Definition: UnitSystem.h:26
The base class for MaterialX elements.
Definition: Element.h:80
A context class for shader generation.
Definition: GenContext.h:31
Class holding options to configure shader generation.
Definition: GenOptions.h:76
An element representing a declaration of geometric property data.
Definition: Geom.h:352
The base class for interface elements such as Node, NodeDef, and NodeGraph.
Definition: Interface.h:312
A node graph element within a Document.
Definition: Node.h:322
An edge returned during shader graph traversal.
Definition: ShaderGraph.h:205
Iterator class for traversing edges between nodes in a shader graph.
Definition: ShaderGraph.h:219
ShaderGraphEdgeIterator & operator++()
Iterate to the next edge in the traversal.
ShaderGraphEdge operator*() const
Dereference this iterator, returning the current output in the traversal.
Definition: ShaderGraph.h:236
static const ShaderGraphEdgeIterator & end()
Return the end iterator.
ShaderGraphEdgeIterator & begin()
Return a reference to this iterator to begin traversal.
Definition: ShaderGraph.h:246
Class representing a graph (DAG) for shader generation.
Definition: ShaderGraph.h:44
void addUnitTransformNode(ShaderOutput *output, const UnitTransform &transform, GenContext &context)
Add a unit transform node and connect to the given output.
virtual ~ShaderGraph()
Desctructor.
Definition: ShaderGraph.h:50
void addUnitTransformNode(ShaderInput *input, const UnitTransform &transform, GenContext &context)
Add a unit transform node and connect to the given input.
bool isAGraph() const override
Return true if this node is a graph.
Definition: ShaderGraph.h:62
ShaderGraphInputSocket * addInputSocket(const string &name, TypeDesc type)
Add input sockets.
void addOutputSockets(const InterfaceElement &elem)
Add output sockets from an interface element (nodedef, nodegraph or node)
const ShaderNode * getNode(const string &name) const
Get an internal node by name.
ShaderNode * getNode(const string &name)
Get an internal node by name.
void addInputSockets(const InterfaceElement &elem, GenContext &context)
Add input sockets from an interface element (nodedef, nodegraph or node)
size_t numInputSockets() const
Get number of input sockets.
Definition: ShaderGraph.h:74
void setVariableNames(GenContext &context)
For inputs and outputs in the graph set the variable names to be used in generated code.
static ShaderGraphEdgeIterator traverseUpstream(ShaderOutput *output)
Return an iterator for traversal upstream from the given output.
void addColorTransformNode(ShaderInput *input, const ColorSpaceTransform &transform, GenContext &context)
Add a color transform node and connect to the given input.
void topologicalSort()
Sort the nodes in topological order.
ShaderNode * createNode(ConstNodePtr node, GenContext &context)
Create a new node in the graph.
ShaderGraph(const ShaderGraph *parent, const string &name, ConstDocumentPtr document, const StringSet &reservedWords)
Constructor.
void disconnect(ShaderNode *node) const
Break all connections on a node.
const vector< ShaderGraphInputSocket * > & getInputSockets() const
Get vector of sockets.
Definition: ShaderGraph.h:92
void applyInputTransforms(ConstNodePtr node, ShaderNodePtr shaderNode, GenContext &context)
Apply color and unit transforms to each input of a node.
ShaderGraphInputSocket * getInputSocket(size_t index)
Get socket by index.
Definition: ShaderGraph.h:80
void bypass(ShaderNode *node, size_t inputIndex, size_t outputIndex=0)
Bypass a node for a particular input and output, effectively connecting the input's upstream connecti...
void addColorTransformNode(ShaderOutput *output, const ColorSpaceTransform &transform, GenContext &context)
Add a color transform node and connect to the given output.
IdentifierMap & getIdentifierMap()
Return the map of unique identifiers used in the scope of this graph.
Definition: ShaderGraph.h:119
static ShaderGraphPtr create(const ShaderGraph *parent, const string &name, ElementPtr element, GenContext &context)
Create a new shader graph from an element.
static ShaderGraphPtr create(const ShaderGraph *parent, const NodeGraph &nodeGraph, GenContext &context)
Create a new shader graph from a nodegraph.
size_t numOutputSockets() const
Get number of output sockets.
Definition: ShaderGraph.h:77
void populateColorTransformMap(ColorManagementSystemPtr colorManagementSystem, ShaderPort *shaderPort, const string &sourceColorSpace, const string &targetColorSpace, bool asInput)
Populate the color transform map for the given shader port, if the provided combination of source and...
void addDefaultGeomNode(ShaderInput *input, const GeomPropDef &geomprop, GenContext &context)
Add a default geometric node and connect to the given input.
void optimize()
Optimize the graph, removing redundant paths.
void addUpstreamDependencies(const Element &root, GenContext &context)
Traverse from the given root element and add all dependencies upstream.
void addNode(ShaderNodePtr node)
Add a node to the graph.
ShaderGraphOutputSocket * addOutputSocket(const string &name, TypeDesc type)
Add output sockets.
void populateUnitTransformMap(UnitSystemPtr unitSystem, ShaderPort *shaderPort, ValueElementPtr element, const string &targetUnitSpace, bool asInput)
Populates the appropriate unit transform map if the provided input/parameter or output has a unit att...
void createConnectedNodes(const ElementPtr &downstreamElement, const ElementPtr &upstreamElement, ElementPtr connectingElement, GenContext &context)
Create node connections corresponding to the connection between a pair of elements.
const vector< ShaderNode * > & getNodes() const
Get a vector of all nodes in order.
Definition: ShaderGraph.h:71
ShaderGraphInputSocket * getInputSocket(const string &name)
Get socket by name.
Definition: ShaderGraph.h:86
void finalize(GenContext &context)
Perform all post-build operations on the graph.
Class representing a node in the shader generation DAG.
Definition: ShaderNode.h:320
ShaderInput * getInput(size_t index)
Get inputs/outputs by index.
Definition: ShaderNode.h:447
size_t numInputs() const
Get number of inputs/outputs.
Definition: ShaderNode.h:443
An output on a ShaderNode.
Definition: ShaderNode.h:295
An input or output port on a ShaderNode.
Definition: ShaderNode.h:123
Base class for syntax objects used by shader generators to emit code with correct syntax for each lan...
Definition: Syntax.h:41
A type descriptor for MaterialX data types.
Definition: TypeDesc.h:35