HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ShaderGraph Class Reference

#include <ShaderGraph.h>

+ Inheritance diagram for ShaderGraph:

Public Member Functions

 ShaderGraph (const ShaderGraph *parent, const string &name, ConstDocumentPtr document, const StringSet &reservedWords)
 Constructor. More...
 
virtual ~ShaderGraph ()
 Desctructor. More...
 
bool isAGraph () const override
 Return true if this node is a graph. More...
 
ShaderNodegetNode (const string &name)
 Get an internal node by name. More...
 
const ShaderNodegetNode (const string &name) const
 Get an internal node by name. More...
 
const vector< ShaderNode * > & getNodes () const
 Get a vector of all nodes in order. More...
 
size_t numInputSockets () const
 Get number of input sockets. More...
 
size_t numOutputSockets () const
 Get number of output sockets. More...
 
ShaderGraphInputSocketgetInputSocket (size_t index)
 Get socket by index. More...
 
ShaderGraphOutputSocketgetOutputSocket (size_t index=0)
 
const ShaderGraphInputSocketgetInputSocket (size_t index) const
 
const ShaderGraphOutputSocketgetOutputSocket (size_t index=0) const
 
ShaderGraphInputSocketgetInputSocket (const string &name)
 Get socket by name. More...
 
ShaderGraphOutputSocketgetOutputSocket (const string &name)
 
const ShaderGraphInputSocketgetInputSocket (const string &name) const
 
const ShaderGraphOutputSocketgetOutputSocket (const string &name) const
 
const vector
< ShaderGraphInputSocket * > & 
getInputSockets () const
 Get vector of sockets. More...
 
const vector
< ShaderGraphOutputSocket * > & 
getOutputSockets () const
 
void applyInputTransforms (ConstNodePtr node, ShaderNodePtr shaderNode, GenContext &context)
 Apply color and unit transforms to each input of a node. More...
 
ShaderNodecreateNode (ConstNodePtr node, GenContext &context)
 Create a new node in the graph. More...
 
ShaderGraphInputSocketaddInputSocket (const string &name, const TypeDesc *type)
 Add input/output sockets. More...
 
ShaderGraphOutputSocketaddOutputSocket (const string &name, const TypeDesc *type)
 
void addDefaultGeomNode (ShaderInput *input, const GeomPropDef &geomprop, GenContext &context)
 Add a default geometric node and connect to the given input. More...
 
void topologicalSort ()
 Sort the nodes in topological order. More...
 
IdentifierMapgetIdentifierMap ()
 Return the map of unique identifiers used in the scope of this graph. More...
 
- Public Member Functions inherited from ShaderNode
virtual ~ShaderNode ()
 
 ShaderNode (const ShaderGraph *parent, const string &name)
 Constructor. More...
 
const ShaderGraphgetParent () const
 
void setClassification (uint32_t c)
 
uint32_t getClassification () const
 Get classification bits set for this node. More...
 
void addClassification (uint32_t c)
 Add classification bits to this node. More...
 
bool hasClassification (uint32_t c) const
 Return true if this node matches the given classification. More...
 
const stringgetName () const
 Return the name of this node. More...
 
const ShaderNodeImplgetImplementation () const
 Return the implementation used for this node. More...
 
void initialize (const Node &node, const NodeDef &nodeDef, GenContext &context)
 
ShaderInputaddInput (const string &name, const TypeDesc *type)
 Add inputs/outputs. More...
 
ShaderOutputaddOutput (const string &name, const TypeDesc *type)
 
size_t numInputs () const
 Get number of inputs/outputs. More...
 
size_t numOutputs () const
 
ShaderInputgetInput (size_t index)
 Get inputs/outputs by index. More...
 
ShaderOutputgetOutput (size_t index=0)
 
const ShaderInputgetInput (size_t index) const
 
const ShaderOutputgetOutput (size_t index=0) const
 
ShaderInputgetInput (const string &name)
 Get inputs/outputs by name. More...
 
ShaderOutputgetOutput (const string &name)
 
const ShaderInputgetInput (const string &name) const
 
const ShaderOutputgetOutput (const string &name) const
 
const vector< ShaderInput * > & getInputs () const
 Get vector of inputs/outputs. More...
 
const vector< ShaderOutput * > & getOutputs () const
 
void setMetadata (ShaderMetadataVecPtr metadata)
 Set the metadata vector. More...
 
ShaderMetadataVecPtr getMetadata ()
 Get the metadata vector. More...
 
const ShaderMetadataVecPtrgetMetadata () const
 Get the metadata vector. More...
 
bool isEditable (const ShaderInput &input) const
 
bool isEditable (const ShaderGraphInputSocket &input) const
 

Static Public Member Functions

static ShaderGraphPtr create (const ShaderGraph *parent, const string &name, ElementPtr element, GenContext &context)
 
static ShaderGraphPtr create (const ShaderGraph *parent, const NodeGraph &nodeGraph, GenContext &context)
 Create a new shader graph from a nodegraph. More...
 
static ShaderGraphEdgeIterator traverseUpstream (ShaderOutput *output)
 Return an iterator for traversal upstream from the given output. More...
 
- Static Public Member Functions inherited from ShaderNode
static ShaderNodePtr create (const ShaderGraph *parent, const string &name, const NodeDef &nodeDef, GenContext &context)
 Create a new node from a nodedef. More...
 
static ShaderNodePtr create (const ShaderGraph *parent, const string &name, ShaderNodeImplPtr impl, unsigned int classification=Classification::TEXTURE)
 Create a new node from a node implementation. More...
 

Protected Member Functions

void createConnectedNodes (const ElementPtr &downstreamElement, const ElementPtr &upstreamElement, ElementPtr connectingElement, GenContext &context)
 
void addNode (ShaderNodePtr node)
 Add a node to the graph. More...
 
void addInputSockets (const InterfaceElement &elem, GenContext &context)
 Add input sockets from an interface element (nodedef, nodegraph or node) More...
 
void addOutputSockets (const InterfaceElement &elem)
 Add output sockets from an interface element (nodedef, nodegraph or node) More...
 
void addUpstreamDependencies (const Element &root, GenContext &context)
 
void addColorTransformNode (ShaderInput *input, const ColorSpaceTransform &transform, GenContext &context)
 Add a color transform node and connect to the given input. More...
 
void addColorTransformNode (ShaderOutput *output, const ColorSpaceTransform &transform, GenContext &context)
 Add a color transform node and connect to the given output. More...
 
void addUnitTransformNode (ShaderInput *input, const UnitTransform &transform, GenContext &context)
 Add a unit transform node and connect to the given input. More...
 
void addUnitTransformNode (ShaderOutput *output, const UnitTransform &transform, GenContext &context)
 Add a unit transform node and connect to the given output. More...
 
void finalize (GenContext &context)
 Perform all post-build operations on the graph. More...
 
void optimize (GenContext &context)
 Optimize the graph, removing redundant paths. More...
 
void bypass (GenContext &context, ShaderNode *node, size_t inputIndex, size_t outputIndex=0)
 
void setVariableNames (GenContext &context)
 
void populateColorTransformMap (ColorManagementSystemPtr colorManagementSystem, ShaderPort *shaderPort, const string &sourceColorSpace, const string &targetColorSpace, bool asInput)
 
void populateUnitTransformMap (UnitSystemPtr unitSystem, ShaderPort *shaderPort, ValueElementPtr element, const string &targetUnitSpace, bool asInput)
 
void disconnect (ShaderNode *node) const
 Break all connections on a node. More...
 
- Protected Member Functions inherited from ShaderNode
void createMetadata (const NodeDef &nodeDef, GenContext &context)
 Create metadata from the nodedef according to registered metadata. More...
 

Protected Attributes

ConstDocumentPtr _document
 
std::unordered_map< string,
ShaderNodePtr
_nodeMap
 
std::vector< ShaderNode * > _nodeOrder
 
IdentifierMap _identifiers
 
std::unordered_map
< ShaderInput
*, ColorSpaceTransform
_inputColorTransformMap
 
std::unordered_map
< ShaderInput *, UnitTransform
_inputUnitTransformMap
 
std::unordered_map
< ShaderOutput
*, ColorSpaceTransform
_outputColorTransformMap
 
std::unordered_map
< ShaderOutput
*, UnitTransform
_outputUnitTransformMap
 
- Protected Attributes inherited from ShaderNode
const ShaderGraph_parent
 
string _name
 
uint32_t _classification
 
std::unordered_map< string,
ShaderInputPtr
_inputMap
 
vector< ShaderInput * > _inputOrder
 
std::unordered_map< string,
ShaderOutputPtr
_outputMap
 
vector< ShaderOutput * > _outputOrder
 
ShaderNodeImplPtr _impl
 
ShaderMetadataVecPtr _metadata
 

Additional Inherited Members

- Static Public Attributes inherited from ShaderNode
static const ShaderNodePtr NONE
 
static const string CONSTANT
 
static const string DOT
 
static const string IMAGE
 
static const string SURFACESHADER
 
static const string SCATTER_MODE
 
static const string BSDF_R
 
static const string BSDF_T
 
static const string TRANSFORM_POINT
 
static const string TRANSFORM_VECTOR
 
static const string TRANSFORM_NORMAL
 
static const string TEXTURE2D_GROUPNAME
 
static const string TEXTURE3D_GROUPNAME
 
static const string PROCEDURAL2D_GROUPNAME
 
static const string PROCEDURAL3D_GROUPNAME
 
static const string GEOMETRIC_GROUPNAME
 

Detailed Description

Class representing a graph (DAG) for shader generation

Definition at line 43 of file ShaderGraph.h.

Constructor & Destructor Documentation

ShaderGraph::ShaderGraph ( const ShaderGraph parent,
const string name,
ConstDocumentPtr  document,
const StringSet reservedWords 
)

Constructor.

virtual ShaderGraph::~ShaderGraph ( )
inlinevirtual

Desctructor.

Definition at line 50 of file ShaderGraph.h.

Member Function Documentation

void ShaderGraph::addColorTransformNode ( ShaderInput input,
const ColorSpaceTransform transform,
GenContext context 
)
protected

Add a color transform node and connect to the given input.

void ShaderGraph::addColorTransformNode ( ShaderOutput output,
const ColorSpaceTransform transform,
GenContext context 
)
protected

Add a color transform node and connect to the given output.

void ShaderGraph::addDefaultGeomNode ( ShaderInput input,
const GeomPropDef geomprop,
GenContext context 
)

Add a default geometric node and connect to the given input.

ShaderGraphInputSocket* ShaderGraph::addInputSocket ( const string name,
const TypeDesc type 
)

Add input/output sockets.

void ShaderGraph::addInputSockets ( const InterfaceElement elem,
GenContext context 
)
protected

Add input sockets from an interface element (nodedef, nodegraph or node)

void ShaderGraph::addNode ( ShaderNodePtr  node)
protected

Add a node to the graph.

ShaderGraphOutputSocket* ShaderGraph::addOutputSocket ( const string name,
const TypeDesc type 
)
void ShaderGraph::addOutputSockets ( const InterfaceElement elem)
protected

Add output sockets from an interface element (nodedef, nodegraph or node)

void ShaderGraph::addUnitTransformNode ( ShaderInput input,
const UnitTransform transform,
GenContext context 
)
protected

Add a unit transform node and connect to the given input.

void ShaderGraph::addUnitTransformNode ( ShaderOutput output,
const UnitTransform transform,
GenContext context 
)
protected

Add a unit transform node and connect to the given output.

void ShaderGraph::addUpstreamDependencies ( const Element root,
GenContext context 
)
protected

Traverse from the given root element and add all dependencies upstream. The traversal is done in the context of a material, if given, to include bind input elements in the traversal.

void ShaderGraph::applyInputTransforms ( ConstNodePtr  node,
ShaderNodePtr  shaderNode,
GenContext context 
)

Apply color and unit transforms to each input of a node.

void ShaderGraph::bypass ( GenContext context,
ShaderNode node,
size_t  inputIndex,
size_t  outputIndex = 0 
)
protected

Bypass a node for a particular input and output, effectively connecting the input's upstream connection with the output's downstream connections.

static ShaderGraphPtr ShaderGraph::create ( const ShaderGraph parent,
const string name,
ElementPtr  element,
GenContext context 
)
static

Create a new shader graph from an element. Supported elements are outputs and shader nodes.

static ShaderGraphPtr ShaderGraph::create ( const ShaderGraph parent,
const NodeGraph nodeGraph,
GenContext context 
)
static

Create a new shader graph from a nodegraph.

void ShaderGraph::createConnectedNodes ( const ElementPtr downstreamElement,
const ElementPtr upstreamElement,
ElementPtr  connectingElement,
GenContext context 
)
protected

Create node connections corresponding to the connection between a pair of elements.

Parameters
downstreamElementElement representing the node to connect to.
upstreamElementElement representing the node to connect from
connectingElementIf non-null, specifies the element on on the downstream node to connect to.
contextContext for generation.
ShaderNode* ShaderGraph::createNode ( ConstNodePtr  node,
GenContext context 
)

Create a new node in the graph.

void ShaderGraph::disconnect ( ShaderNode node) const
protected

Break all connections on a node.

void ShaderGraph::finalize ( GenContext context)
protected

Perform all post-build operations on the graph.

IdentifierMap& ShaderGraph::getIdentifierMap ( )
inline

Return the map of unique identifiers used in the scope of this graph.

Definition at line 115 of file ShaderGraph.h.

ShaderGraphInputSocket* ShaderGraph::getInputSocket ( size_t  index)
inline

Get socket by index.

Definition at line 80 of file ShaderGraph.h.

const ShaderGraphInputSocket* ShaderGraph::getInputSocket ( size_t  index) const
inline

Definition at line 82 of file ShaderGraph.h.

ShaderGraphInputSocket* ShaderGraph::getInputSocket ( const string name)
inline

Get socket by name.

Definition at line 86 of file ShaderGraph.h.

const ShaderGraphInputSocket* ShaderGraph::getInputSocket ( const string name) const
inline

Definition at line 88 of file ShaderGraph.h.

const vector<ShaderGraphInputSocket*>& ShaderGraph::getInputSockets ( ) const
inline

Get vector of sockets.

Definition at line 92 of file ShaderGraph.h.

ShaderNode* ShaderGraph::getNode ( const string name)

Get an internal node by name.

const ShaderNode* ShaderGraph::getNode ( const string name) const

Get an internal node by name.

const vector<ShaderNode*>& ShaderGraph::getNodes ( ) const
inline

Get a vector of all nodes in order.

Definition at line 71 of file ShaderGraph.h.

ShaderGraphOutputSocket* ShaderGraph::getOutputSocket ( size_t  index = 0)
inline

Definition at line 81 of file ShaderGraph.h.

const ShaderGraphOutputSocket* ShaderGraph::getOutputSocket ( size_t  index = 0) const
inline

Definition at line 83 of file ShaderGraph.h.

ShaderGraphOutputSocket* ShaderGraph::getOutputSocket ( const string name)
inline

Definition at line 87 of file ShaderGraph.h.

const ShaderGraphOutputSocket* ShaderGraph::getOutputSocket ( const string name) const
inline

Definition at line 89 of file ShaderGraph.h.

const vector<ShaderGraphOutputSocket*>& ShaderGraph::getOutputSockets ( ) const
inline

Definition at line 93 of file ShaderGraph.h.

bool ShaderGraph::isAGraph ( ) const
inlineoverridevirtual

Return true if this node is a graph.

Reimplemented from ShaderNode.

Definition at line 62 of file ShaderGraph.h.

size_t ShaderGraph::numInputSockets ( ) const
inline

Get number of input sockets.

Definition at line 74 of file ShaderGraph.h.

size_t ShaderGraph::numOutputSockets ( ) const
inline

Get number of output sockets.

Definition at line 77 of file ShaderGraph.h.

void ShaderGraph::optimize ( GenContext context)
protected

Optimize the graph, removing redundant paths.

void ShaderGraph::populateColorTransformMap ( ColorManagementSystemPtr  colorManagementSystem,
ShaderPort shaderPort,
const string sourceColorSpace,
const string targetColorSpace,
bool  asInput 
)
protected

Populate the color transform map for the given shader port, if the provided combination of source and target color spaces are supported for its data type.

void ShaderGraph::populateUnitTransformMap ( UnitSystemPtr  unitSystem,
ShaderPort shaderPort,
ValueElementPtr  element,
const string targetUnitSpace,
bool  asInput 
)
protected

Populates the appropriate unit transform map if the provided input/parameter or output has a unit attribute and is of the supported type

void ShaderGraph::setVariableNames ( GenContext context)
protected

For inputs and outputs in the graph set the variable names to be used in generated code. Making sure variable names are valid and unique to avoid name conflicts during shader generation.

void ShaderGraph::topologicalSort ( )

Sort the nodes in topological order.

static ShaderGraphEdgeIterator ShaderGraph::traverseUpstream ( ShaderOutput output)
static

Return an iterator for traversal upstream from the given output.

Member Data Documentation

ConstDocumentPtr ShaderGraph::_document
protected

Definition at line 182 of file ShaderGraph.h.

IdentifierMap ShaderGraph::_identifiers
protected

Definition at line 185 of file ShaderGraph.h.

std::unordered_map<ShaderInput*, ColorSpaceTransform> ShaderGraph::_inputColorTransformMap
protected

Definition at line 188 of file ShaderGraph.h.

std::unordered_map<ShaderInput*, UnitTransform> ShaderGraph::_inputUnitTransformMap
protected

Definition at line 190 of file ShaderGraph.h.

std::unordered_map<string, ShaderNodePtr> ShaderGraph::_nodeMap
protected

Definition at line 183 of file ShaderGraph.h.

std::vector<ShaderNode*> ShaderGraph::_nodeOrder
protected

Definition at line 184 of file ShaderGraph.h.

std::unordered_map<ShaderOutput*, ColorSpaceTransform> ShaderGraph::_outputColorTransformMap
protected

Definition at line 193 of file ShaderGraph.h.

std::unordered_map<ShaderOutput*, UnitTransform> ShaderGraph::_outputUnitTransformMap
protected

Definition at line 195 of file ShaderGraph.h.


The documentation for this class was generated from the following file: