Loading...
Searching...
No Matches
SdrShaderNode Class Reference

Represents a node that holds shading information. More...

#include <shaderNode.h>

Public Types

using ComplianceResults = std::unordered_map< TfToken, std::vector< SdrIdentifier >, TfToken::HashFunctor >
 

Public Member Functions

SDR_API SdrShaderNode (const SdrIdentifier &identifier, const SdrVersion &version, const std::string &name, const TfToken &family, const TfToken &context, const TfToken &sourceType, const std::string &definitionURI, const std::string &implementationURI, SdrShaderPropertyUniquePtrVec &&properties, const SdrTokenMap &metadata=SdrTokenMap(), const std::string &sourceCode=std::string())
 Constructor.
 
virtual SDR_API ~SdrShaderNode ()
 Destructor.
 
The Basics
const SdrIdentifierGetIdentifier () const
 Return the identifier of the node.
 
SdrVersion GetShaderVersion () const
 Return the version of the node.
 
const std::string & GetName () const
 Gets the name of the node.
 
const TfTokenGetFamily () const
 Gets the name of the family that the node belongs to.
 
const TfTokenGetContext () const
 Gets the context of the shader node.
 
const TfTokenGetSourceType () const
 Gets the type of source that this shader node originated from.
 
const std::string & GetResolvedDefinitionURI () const
 Gets the URI to the resource that provided this node's definition.
 
const std::string & GetResolvedImplementationURI () const
 Gets the URI to the resource that provides this node's implementation.
 
const std::string & GetSourceCode () const
 Returns the source code for this node.
 
SDR_API bool IsValid () const
 Whether or not this node is valid.
 
SDR_API std::string GetInfoString () const
 Gets a string with basic information about this node.
 
Inputs and Outputs

An input or output is also generically referred to as a "property".

SDR_API const SdrTokenVec & GetShaderInputNames () const
 Get an ordered list of all the input names on this shader node.
 
SDR_API const SdrTokenVec & GetShaderOutputNames () const
 Get an ordered list of all the output names on this shader node.
 
SDR_API SdrShaderPropertyConstPtr GetShaderInput (const TfToken &inputName) const
 Get a shader input property by name.
 
SDR_API SdrShaderPropertyConstPtr GetShaderOutput (const TfToken &outputName) const
 Get a shader output property by name.
 
SDR_API SdrTokenVec GetAssetIdentifierInputNames () const
 Returns the list of all inputs that are tagged as asset identifier inputs.
 
SDR_API SdrShaderPropertyConstPtr GetDefaultInput () const
 Returns the first shader input that is tagged as the default input.
 
Metadata

The metadata returned here is a direct result of what the parser plugin is able to determine about the node.

See the documentation for a specific parser plugin to get help on what the parser is looking for to populate these values.

SDR_API const SdrTokenMap & GetMetadata () const
 All metadata that came from the parse process.
 
SDR_API const TfTokenGetLabel () const
 The label assigned to this node, if any.
 
SDR_API const TfTokenGetCategory () const
 The category assigned to this node, if any.
 
SDR_API std::string GetRole () const
 Returns the role of this node.
 
SDR_API std::string GetHelp () const
 The help message assigned to this node, if any.
 
SDR_API const SdrTokenVec & GetDepartments () const
 The departments this node is associated with, if any.
 
SDR_API const SdrTokenVec & GetPages () const
 Gets the pages on which the node's properties reside (an aggregate of the unique SdrShaderProperty::GetPage() values for all of the node's properties).
 
SDR_API const SdrTokenVec & GetOpenPages () const
 Gets the pages which should be opened or expanded by default.
 
SDR_API const SdrTokenVec & GetPrimvars () const
 The list of primvars this node knows it requires / uses.
 
SDR_API const SdrTokenVec & GetAdditionalPrimvarProperties () const
 The list of string input properties whose values provide the names of additional primvars consumed by this node.
 
SDR_API std::string GetImplementationName () const
 Returns the implementation name of this node.
 
Aggregate Information
SDR_API SdrTokenVec GetPropertyNamesForPage (const std::string &pageName) const
 Gets the names of the properties on a certain page (one that was returned by GetPages()).
 
SDR_API SdrTokenVec GetAllVstructNames () const
 Gets all vstructs that are present in the shader.
 

Static Public Member Functions

static SDR_API ComplianceResults CheckPropertyCompliance (const std::vector< SdrShaderNodeConstPtr > &shaderNodes)
 This method checks if same named properties of shaderNodes are compatible with each other.
 

Protected Member Functions

SdrShaderNodeoperator= (const SdrShaderNode &)=delete
 

Protected Attributes

bool _isValid
 
SdrIdentifier _identifier
 
SdrVersion _version
 
std::string _name
 
TfToken _family
 
TfToken _context
 
TfToken _sourceType
 
std::string _definitionURI
 
std::string _implementationURI
 
SdrShaderPropertyUniquePtrVec _properties
 
SdrTokenMap _metadata
 
std::string _sourceCode
 
SdrShaderPropertyMap _inputs
 
SdrTokenVec _inputNames
 
SdrShaderPropertyMap _outputs
 
SdrTokenVec _outputNames
 
SdrTokenVec _primvars
 
SdrTokenVec _primvarNamingProperties
 
TfToken _label
 
TfToken _category
 
SdrTokenVec _departments
 
SdrTokenVec _pages
 
SdrTokenVec _openPages
 

Detailed Description

Represents a node that holds shading information.

Describes information like the name of the node, what its inputs and outputs are, and any associated metadata.

Definition at line 72 of file shaderNode.h.

Member Typedef Documentation

◆ ComplianceResults

using ComplianceResults = std::unordered_map<TfToken, std::vector<SdrIdentifier>, TfToken::HashFunctor>

Definition at line 323 of file shaderNode.h.

Constructor & Destructor Documentation

◆ SdrShaderNode()

SDR_API SdrShaderNode ( const SdrIdentifier identifier,
const SdrVersion version,
const std::string &  name,
const TfToken family,
const TfToken context,
const TfToken sourceType,
const std::string &  definitionURI,
const std::string &  implementationURI,
SdrShaderPropertyUniquePtrVec &&  properties,
const SdrTokenMap &  metadata = SdrTokenMap(),
const std::string &  sourceCode = std::string() 
)

Constructor.

◆ ~SdrShaderNode()

virtual SDR_API ~SdrShaderNode ( )
virtual

Destructor.

Member Function Documentation

◆ CheckPropertyCompliance()

static SDR_API ComplianceResults CheckPropertyCompliance ( const std::vector< SdrShaderNodeConstPtr > &  shaderNodes)
static

This method checks if same named properties of shaderNodes are compatible with each other.

Checks if the same name properties have matching types and default values. In order to determine if same name properties from different shader nodes are compliant, we assume that the first shaderNode in the list providing this property is authoritative, and other nodes differing wrt this property are non-compliant. A map of property names and their respective shaderNodes are stored in the map. An empty map returned represents no compliance issues.

◆ GetAdditionalPrimvarProperties()

SDR_API const SdrTokenVec & GetAdditionalPrimvarProperties ( ) const
inline

The list of string input properties whose values provide the names of additional primvars consumed by this node.

For example, this may return a token named varname. This indicates that the client should query the value of a (presumed to be string-valued) input attribute named varname from its scene description to determine the name of a primvar the node will consume. See GetPrimvars() for additional information.

Definition at line 289 of file shaderNode.h.

◆ GetAllVstructNames()

SDR_API SdrTokenVec GetAllVstructNames ( ) const

Gets all vstructs that are present in the shader.

◆ GetAssetIdentifierInputNames()

SDR_API SdrTokenVec GetAssetIdentifierInputNames ( ) const

Returns the list of all inputs that are tagged as asset identifier inputs.

◆ GetCategory()

SDR_API const TfToken & GetCategory ( ) const
inline

The category assigned to this node, if any.

Distinct from the family returned from GetFamily().

Definition at line 242 of file shaderNode.h.

◆ GetContext()

const TfToken & GetContext ( ) const
inline

Gets the context of the shader node.

The context is the context that the node declares itself as having (or, if a particular node does not declare a context, it will be assigned a default context by the parser).

As a concrete example from the Sdr library, a shader with a specific source type may perform different duties vs. another shader with the same source type. For example, one shader with a source type of SdrArgsParser::SourceType may declare itself as having a context of 'pattern', while another shader of the same source type may say it is used for lighting, and thus has a context of 'light'.

Definition at line 122 of file shaderNode.h.

◆ GetDefaultInput()

SDR_API SdrShaderPropertyConstPtr GetDefaultInput ( ) const

Returns the first shader input that is tagged as the default input.

A default input and its value can be used to acquire a fallback value for a node when the node is considered 'disabled' or otherwise incapable of producing an output value.

◆ GetDepartments()

SDR_API const SdrTokenVec & GetDepartments ( ) const
inline

The departments this node is associated with, if any.

Definition at line 259 of file shaderNode.h.

◆ GetFamily()

const TfToken & GetFamily ( ) const
inline

Gets the name of the family that the node belongs to.

An empty token will be returned if the node does not belong to a family.

Definition at line 108 of file shaderNode.h.

◆ GetHelp()

SDR_API std::string GetHelp ( ) const

The help message assigned to this node, if any.

◆ GetIdentifier()

const SdrIdentifier & GetIdentifier ( ) const
inline

Return the identifier of the node.

Definition at line 98 of file shaderNode.h.

◆ GetImplementationName()

SDR_API std::string GetImplementationName ( ) const

Returns the implementation name of this node.

The name of the node is how to refer to the node in shader networks. The label is how to present this node to users. The implementation name is the name of the function (or something) this node represents in the implementation. Any client using the implementation must call this method to get the correct name; using getName() is not correct.

◆ GetInfoString()

SDR_API std::string GetInfoString ( ) const

Gets a string with basic information about this node.

Helpful for things like adding this node to a log.

◆ GetLabel()

SDR_API const TfToken & GetLabel ( ) const
inline

The label assigned to this node, if any.

Distinct from the name returned from GetName(). In the context of a UI, the label value might be used as the display name for the node instead of the name.

Definition at line 237 of file shaderNode.h.

◆ GetMetadata()

SDR_API const SdrTokenMap & GetMetadata ( ) const

All metadata that came from the parse process.

◆ GetName()

const std::string & GetName ( ) const
inline

Gets the name of the node.

Definition at line 104 of file shaderNode.h.

◆ GetOpenPages()

SDR_API const SdrTokenVec & GetOpenPages ( ) const
inline

Gets the pages which should be opened or expanded by default.

Definition at line 271 of file shaderNode.h.

◆ GetPages()

SDR_API const SdrTokenVec & GetPages ( ) const
inline

Gets the pages on which the node's properties reside (an aggregate of the unique SdrShaderProperty::GetPage() values for all of the node's properties).

Nodes themselves do not reside on pages. In an example scenario, properties might be divided into two pages, 'Simple' and 'Advanced'.

Definition at line 267 of file shaderNode.h.

◆ GetPrimvars()

SDR_API const SdrTokenVec & GetPrimvars ( ) const
inline

The list of primvars this node knows it requires / uses.

For example, a shader node may require the 'normals' primvar to function correctly. Additional, user specified primvars may have been authored on the node. These can be queried via GetAdditionalPrimvarProperties(). Together, GetPrimvars() and GetAdditionalPrimvarProperties(), provide the complete list of primvar requirements for the node.

Definition at line 280 of file shaderNode.h.

◆ GetPropertyNamesForPage()

SDR_API SdrTokenVec GetPropertyNamesForPage ( const std::string &  pageName) const

Gets the names of the properties on a certain page (one that was returned by GetPages()).

To get properties that are not assigned to a page, an empty string can be used for pageName.

◆ GetResolvedDefinitionURI()

const std::string & GetResolvedDefinitionURI ( ) const
inline

Gets the URI to the resource that provided this node's definition.

Could be a path to a file, or some other resource identifier. This URI should be fully resolved.

See also
SdrShaderNode::GetResolvedImplementationURI()

Definition at line 143 of file shaderNode.h.

◆ GetResolvedImplementationURI()

const std::string & GetResolvedImplementationURI ( ) const
inline

Gets the URI to the resource that provides this node's implementation.

Could be a path to a file, or some other resource identifier. This URI should be fully resolved.

See also
SdrShaderNode::GetResolvedDefinitionURI()

Definition at line 150 of file shaderNode.h.

◆ GetRole()

SDR_API std::string GetRole ( ) const

Returns the role of this node.

This is used to annotate the role that the shader node plays inside a shader network. We can tag certain shaders to indicate their role within a shading network. We currently tag primvar reading nodes, texture reading nodes and nodes that access volume fields (like extinction or scattering). This is done to identify resources used by a shading network.

◆ GetShaderInput()

SDR_API SdrShaderPropertyConstPtr GetShaderInput ( const TfToken inputName) const

Get a shader input property by name.

nullptr is returned if an input with the given name does not exist.

◆ GetShaderInputNames()

SDR_API const SdrTokenVec & GetShaderInputNames ( ) const

Get an ordered list of all the input names on this shader node.

◆ GetShaderOutput()

SDR_API SdrShaderPropertyConstPtr GetShaderOutput ( const TfToken outputName) const

Get a shader output property by name.

nullptr is returned if an output with the given name does not exist.

◆ GetShaderOutputNames()

SDR_API const SdrTokenVec & GetShaderOutputNames ( ) const

Get an ordered list of all the output names on this shader node.

◆ GetShaderVersion()

SdrVersion GetShaderVersion ( ) const
inline

Return the version of the node.

Definition at line 101 of file shaderNode.h.

◆ GetSourceCode()

const std::string & GetSourceCode ( ) const
inline

Returns the source code for this node.

This will be empty for most nodes. It will be non-empty only for the nodes that are constructed using SdrRegistry::GetShaderNodeFromSourceCode(), in which case, the source code has not been parsed (or even compiled) yet.

An unparsed node with non-empty source-code but no properties is considered to be invalid. Once the node is parsed and the relevant properties and metadata are extracted from the source code, the node becomes valid.

See also
SdrShaderNode::IsValid

Definition at line 165 of file shaderNode.h.

◆ GetSourceType()

const TfToken & GetSourceType ( ) const
inline

Gets the type of source that this shader node originated from.

Note that this is distinct from GetContext(), which is the type that the node declares itself as having.

As a concrete example from the Sdr library, several shader parsers exist and operate on different types of shaders. In this scenario, each distinct type of shader (OSL, Args, etc) is considered a different source, even though they are all shaders. In addition, the shaders under each source type may declare themselves as having a specific context (shaders can serve different roles). See GetContext() for more information on this.

Definition at line 136 of file shaderNode.h.

◆ IsValid()

SDR_API bool IsValid ( ) const
inline

Whether or not this node is valid.

A node that is valid indicates that the parser plugin was able to successfully parse the contents of this node.

Note that if a node is not valid, some data like its name, URI, source code etc. could still be available (data that was obtained during the discovery process). However, other data that must be gathered from the parsing process will NOT be available (eg, inputs and outputs).

Definition at line 176 of file shaderNode.h.

Member Data Documentation

◆ _category

TfToken _category
protected

Definition at line 382 of file shaderNode.h.

◆ _context

TfToken _context
protected

Definition at line 360 of file shaderNode.h.

◆ _definitionURI

std::string _definitionURI
protected

Definition at line 362 of file shaderNode.h.

◆ _departments

SdrTokenVec _departments
protected

Definition at line 383 of file shaderNode.h.

◆ _family

TfToken _family
protected

Definition at line 359 of file shaderNode.h.

◆ _identifier

SdrIdentifier _identifier
protected

Definition at line 356 of file shaderNode.h.

◆ _implementationURI

std::string _implementationURI
protected

Definition at line 363 of file shaderNode.h.

◆ _inputNames

SdrTokenVec _inputNames
protected

Definition at line 369 of file shaderNode.h.

◆ _inputs

SdrShaderPropertyMap _inputs
protected

Definition at line 368 of file shaderNode.h.

◆ _isValid

bool _isValid
protected

Definition at line 355 of file shaderNode.h.

◆ _label

TfToken _label
protected

Definition at line 381 of file shaderNode.h.

◆ _metadata

SdrTokenMap _metadata
protected

Definition at line 365 of file shaderNode.h.

◆ _name

std::string _name
protected

Definition at line 358 of file shaderNode.h.

◆ _openPages

SdrTokenVec _openPages
protected

Definition at line 385 of file shaderNode.h.

◆ _outputNames

SdrTokenVec _outputNames
protected

Definition at line 371 of file shaderNode.h.

◆ _outputs

SdrShaderPropertyMap _outputs
protected

Definition at line 370 of file shaderNode.h.

◆ _pages

SdrTokenVec _pages
protected

Definition at line 384 of file shaderNode.h.

◆ _primvarNamingProperties

SdrTokenVec _primvarNamingProperties
protected

Definition at line 378 of file shaderNode.h.

◆ _primvars

SdrTokenVec _primvars
protected

Definition at line 377 of file shaderNode.h.

◆ _properties

SdrShaderPropertyUniquePtrVec _properties
protected

Definition at line 364 of file shaderNode.h.

◆ _sourceCode

std::string _sourceCode
protected

Definition at line 366 of file shaderNode.h.

◆ _sourceType

TfToken _sourceType
protected

Definition at line 361 of file shaderNode.h.

◆ _version

SdrVersion _version
protected

Definition at line 357 of file shaderNode.h.


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