Loading...
Searching...
No Matches
shaderNode.h
Go to the documentation of this file.
1//
2// Copyright 2018 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7
8#ifndef PXR_USD_SDR_SHADER_NODE_H
9#define PXR_USD_SDR_SHADER_NODE_H
10
12
13#include "pxr/pxr.h"
14#include "pxr/usd/sdr/api.h"
16#include "pxr/base/tf/token.h"
17#include "pxr/base/vt/value.h"
18#include "pxr/usd/sdr/declare.h"
19#include "pxr/usd/sdr/shaderNodeMetadata.h"
21
22#include <unordered_map>
23
24PXR_NAMESPACE_OPEN_SCOPE
25
26#define SDR_NODE_FIELD_KEY_TOKENS \
27 ((Identifier, "_identifier")) \
28 ((Name, "_name")) \
29 ((Family, "_family")) /* deprecated */ \
30 ((Function, "_function")) \
31 ((SourceType, "_sourceType")) /* deprecated */ \
32 ((ShadingSystem, "_shadingSystem"))
33
37TF_DECLARE_PUBLIC_TOKENS(SdrNodeFieldKey, SDR_API, SDR_NODE_FIELD_KEY_TOKENS);
38
45{
46public:
47
60
62 SDR_API
64 const SdrIdentifier& identifier,
65 const SdrVersion& version,
66 const std::string& name,
67 const TfToken& function,
68 const TfToken& shadingSystem,
69 const std::string& definitionURI,
70 const std::string& implementationURI,
71 SdrShaderPropertyUniquePtrVec&& properties,
73 const std::string &sourceCode = std::string()
75 identifier,
76 version,
77 name,
78 function,
79 metadata.GetContext(),
80 shadingSystem,
81 definitionURI,
82 implementationURI,
83 std::move(properties),
84 metadata,
85 sourceCode
86 ) {}
87
92 SDR_API
94 const SdrIdentifier& identifier,
95 const SdrVersion& version,
96 const std::string& name,
97 const TfToken& function,
98 const TfToken& context, // deprecated
99 const TfToken& shadingSystem,
100 const std::string& definitionURI,
101 const std::string& implementationURI,
102 SdrShaderPropertyUniquePtrVec&& properties,
104 const std::string &sourceCode = std::string());
106
108 SDR_API
109 virtual ~SdrShaderNode();
110
113
115 const SdrIdentifier& GetIdentifier() const { return _identifier; }
116
118 SdrVersion GetShaderVersion() const { return _version; }
119
121 const std::string& GetName() const { return _name; }
122
127 const TfToken& GetFamily() const { return _function; }
128
134 const TfToken& GetFunction() const { return _function; }
135
145 const TfToken& GetShadingSystem() const { return _shadingSystem; }
146
151 const TfToken& GetSourceType() const { return _shadingSystem; }
152
158 const std::string& GetResolvedDefinitionURI() const { return _definitionURI; }
159
165 const std::string& GetResolvedImplementationURI() const {
166 return _implementationURI;
167 }
168
180 const std::string &GetSourceCode() const { return _sourceCode; }
181
190 SDR_API
191 bool IsValid() const { return _isValid; }
192
195 SDR_API
196 std::string GetInfoString() const;
197
199
203
205 SDR_API
206 const SdrTokenVec& GetShaderInputNames() const;
207
209 SDR_API
210 const SdrTokenVec& GetShaderOutputNames() const;
211
214 SDR_API
215 SdrShaderPropertyConstPtr GetShaderInput(const TfToken& inputName) const;
216
219 SDR_API
220 SdrShaderPropertyConstPtr GetShaderOutput(const TfToken& outputName) const;
221
224 SDR_API
225 SdrTokenVec GetAssetIdentifierInputNames() const;
226
231 SDR_API
232 SdrShaderPropertyConstPtr GetDefaultInput() const;
233
235
236
243
253 SDR_API
254 const SdrTokenMap& GetMetadata() const;
255
257 SDR_API
259
263 const TfToken& GetDomain() const { return _domain; }
264
270 const TfToken& GetSubdomain() const { return _subdomain; }
271
278 const TfToken& GetContext() const { return _context; }
279
286 SDR_API
288
294 SDR_API
295 const TfToken& GetLabel() const { return _label; }
296
303 SDR_API
304 const TfToken& GetCategory() const { return _category; }
305
309 SDR_API
310 std::string GetHelp() const;
311
315 SDR_API
316 const SdrTokenVec& GetDepartments() const { return _departments; }
317
319 SDR_API
320 const SdrTokenVec& GetOpenPages() const { return _openPages; }
321
323 SDR_API
324 const SdrTokenMap& GetPagesShownIf() const { return _pagesShownIf; }
325
336 SDR_API
337 const SdrTokenVec& GetPrimvars() const { return _primvars; }
338
345 SDR_API
346 const SdrTokenVec& GetAdditionalPrimvarProperties() const {
347 return _primvarNamingProperties;
348 }
349
357 SDR_API
358 std::string GetImplementationName() const;
359
361
362
365
371 SDR_API
372 const SdrTokenVec& GetPages() const { return _pages; }
373
377 SDR_API
378 SdrTokenVec GetPropertyNamesForPage(const std::string& pageName) const;
379
381 SDR_API
382 SdrTokenVec GetAllVstructNames() const;
383
385
386 // Stores the result of the compliance check of property names to
387 // sdrShaderNodeIdentifiers
388 using ComplianceResults = std::unordered_map<TfToken,
389 std::vector<SdrIdentifier>,
391
402 SDR_API
403 static
404 ComplianceResults CheckPropertyCompliance(
405 const std::vector<SdrShaderNodeConstPtr> &shaderNodes);
406
409
410 // Performs a post-process on properties to determine information that can
411 // only be determined after parsing or in aggregate. Clients SHOULD NOT
412 // need to call this.
413 void _PostProcessProperties();
414
416
419
437 SDR_API
438 VtValue GetDataForKey(const TfToken& key) const;
439
440protected:
441 SdrShaderNode& operator=(const SdrShaderNode&) = delete;
442
443 bool _isValid;
444 SdrIdentifier _identifier;
445 SdrVersion _version;
446 std::string _name;
447 TfToken _function;
448 TfToken _context;
449 TfToken _shadingSystem;
450 std::string _definitionURI;
451 std::string _implementationURI;
452 SdrShaderPropertyUniquePtrVec _properties;
453 SdrTokenMap _legacyMetadata;
454 SdrShaderNodeMetadata _metadata;
455 std::string _sourceCode;
456
457 SdrShaderPropertyMap _inputs;
458 SdrTokenVec _inputNames;
459 SdrShaderPropertyMap _outputs;
460 SdrTokenVec _outputNames;
461
462 // Stored metadata to support getter API on SdrShaderNode that
463 // returns const ref.
464 TfToken _domain;
465 TfToken _subdomain;
466 TfToken _label;
467 TfToken _category;
468 SdrTokenVec _departments;
469 SdrTokenVec _openPages;
470 SdrTokenMap _pagesShownIf;
471
472 // Processed primvar metadata. `_primvars` contains the names of primvars
473 // consumed by this node, whereas `_primvarNamingProperties` contains the
474 // names of string input properties whose values provide the names of
475 // additional primvars consumed by this node.
476 SdrTokenVec _primvars;
477 SdrTokenVec _primvarNamingProperties;
478
479 // Aggregated pages data, from examining SdrShaderProperty's page metadata
480 SdrTokenVec _pages;
481
482private:
483 // Initializes `_primvars` and `_primvarNamingProperties`
484 void _InitializePrimvars();
485
486 // Determines which pages are present on the node's properties
487 SdrTokenVec _ComputePages() const;
488};
489
490PXR_NAMESPACE_CLOSE_SCOPE
491
492#endif // PXR_USD_SDR_SHADER_NODE_H
Represents a node that holds shading information.
Definition: shaderNode.h:45
SDR_API const SdrTokenMap & GetMetadata() const
All metadata that came from the parse process.
const TfToken & GetFunction() const
Gets the function that the node belongs to.
Definition: shaderNode.h:134
SDR_API const SdrTokenVec & GetPrimvars() const
The list of primvars this node knows it requires / uses.
Definition: shaderNode.h:337
virtual SDR_API ~SdrShaderNode()
Destructor.
SDR_API SdrTokenVec GetAssetIdentifierInputNames() const
Returns the list of all inputs that are tagged as asset identifier inputs.
SDR_API const SdrTokenVec & GetAdditionalPrimvarProperties() const
The list of string input properties whose values provide the names of additional primvars consumed by...
Definition: shaderNode.h:346
const SdrIdentifier & GetIdentifier() const
Return the identifier of the node.
Definition: shaderNode.h:115
SDR_API const TfToken & GetLabel() const
The label assigned to this node, if any.
Definition: shaderNode.h:295
SDR_API SdrShaderPropertyConstPtr GetShaderInput(const TfToken &inputName) const
Get a shader input property by name.
const TfToken & GetFamily() const
Gets the name of the family that the node belongs to.
Definition: shaderNode.h:127
static SDR_API ComplianceResults CheckPropertyCompliance(const std::vector< SdrShaderNodeConstPtr > &shaderNodes)
This method checks if same named properties of shaderNodes are compatible with each other.
SDR_API SdrTokenVec GetAllVstructNames() const
Gets all vstructs that are present in the shader.
SDR_API const TfToken & GetCategory() const
The category assigned to this node, if any.
Definition: shaderNode.h:304
const std::string & GetName() const
Gets the name of the node.
Definition: shaderNode.h:121
SDR_API SdrShaderNode(const SdrIdentifier &identifier, const SdrVersion &version, const std::string &name, const TfToken &function, const TfToken &shadingSystem, const std::string &definitionURI, const std::string &implementationURI, SdrShaderPropertyUniquePtrVec &&properties, const SdrShaderNodeMetadata &metadata=SdrShaderNodeMetadata(), const std::string &sourceCode=std::string())
Constructor.
Definition: shaderNode.h:63
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 SdrShaderNode(const SdrIdentifier &identifier, const SdrVersion &version, const std::string &name, const TfToken &function, const TfToken &context, const TfToken &shadingSystem, const std::string &definitionURI, const std::string &implementationURI, SdrShaderPropertyUniquePtrVec &&properties, const SdrShaderNodeMetadata &metadata=SdrShaderNodeMetadata(), const std::string &sourceCode=std::string())
SDR_API TfToken GetRole() const
Returns the role of this node.
const TfToken & GetDomain() const
Gets the domain of the node.
Definition: shaderNode.h:263
SDR_API SdrShaderPropertyConstPtr GetShaderOutput(const TfToken &outputName) const
Get a shader output property by name.
SDR_API VtValue GetDataForKey(const TfToken &key) const
Gets an item of data from this shader node according to the requested key.
SDR_API std::string GetHelp() const
The help message assigned to this node, if any.
SDR_API const SdrTokenVec & GetPages() const
Gets the pages on which the node's properties reside (an aggregate of the unique SdrShaderProperty::G...
Definition: shaderNode.h:372
const TfToken & GetContext() const
Gets the context of the node.
Definition: shaderNode.h:278
const TfToken & GetShadingSystem() const
Gets the shading system that this shader node originated from.
Definition: shaderNode.h:145
SDR_API const SdrTokenVec & GetDepartments() const
The departments this node is associated with, if any.
Definition: shaderNode.h:316
SDR_API std::string GetImplementationName() const
Returns the implementation name of this node.
const std::string & GetResolvedImplementationURI() const
Gets the URI to the resource that provides this node's implementation.
Definition: shaderNode.h:165
SDR_API const SdrTokenVec & GetShaderInputNames() const
Get an ordered list of all the input names on this shader node.
SdrVersion GetShaderVersion() const
Return the version of the node.
Definition: shaderNode.h:118
SDR_API const SdrShaderNodeMetadata & GetMetadataObject() const
All metadata that came from the parse process.
SDR_API const SdrTokenMap & GetPagesShownIf() const
Gets the shownIf expressions associated with each page.
Definition: shaderNode.h:324
const TfToken & GetSubdomain() const
Gets the subdomain of the node if the subdomain metadata item exists.
Definition: shaderNode.h:270
SDR_API const SdrTokenVec & GetOpenPages() const
Gets the pages which should be opened or expanded by default.
Definition: shaderNode.h:320
const std::string & GetSourceCode() const
Returns the source code for this node.
Definition: shaderNode.h:180
SDR_API SdrShaderPropertyConstPtr GetDefaultInput() const
Returns the first shader input that is tagged as the default input.
const TfToken & GetSourceType() const
Gets the type of source that this shader node originated from.
Definition: shaderNode.h:151
SDR_API bool IsValid() const
Whether or not this node is valid.
Definition: shaderNode.h:191
SDR_API const SdrTokenVec & GetShaderOutputNames() const
Get an ordered list of all the output names on this shader node.
SDR_API std::string GetInfoString() const
Gets a string with basic information about this node.
const std::string & GetResolvedDefinitionURI() const
Gets the URI to the resource that provided this node's definition.
Definition: shaderNode.h:158
SdrShaderNodeMetadata contains generic and named metadata for SdrShaderNode.
SdrVersion.
Definition: declare.h:67
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:90
STL namespace.
This file defines some macros that are useful for declaring and using static TfTokens.
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:92
Functor to use for hash maps from tokens to other things.
Definition: token.h:149
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...