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")) \
30 ((SourceType, "_sourceType"))
31
32TF_DECLARE_PUBLIC_TOKENS(SdrNodeFieldKey, SDR_API, SDR_NODE_FIELD_KEY_TOKENS);
33
40{
41public:
51 SDR_API
53 const SdrIdentifier& identifier,
54 const SdrVersion& version,
55 const std::string& name,
56 const TfToken& family,
57 const TfToken& context,
58 const TfToken& sourceType,
59 const std::string& definitionURI,
60 const std::string& implementationURI,
61 SdrShaderPropertyUniquePtrVec&& properties,
63 const std::string &sourceCode = std::string());
64
66 SDR_API
67 virtual ~SdrShaderNode();
68
71
73 const SdrIdentifier& GetIdentifier() const { return _identifier; }
74
76 SdrVersion GetShaderVersion() const { return _version; }
77
79 const std::string& GetName() const { return _name; }
80
83 const TfToken& GetFamily() const { return _family; }
84
97 const TfToken& GetContext() const { return _context; }
98
111 const TfToken& GetSourceType() const { return _sourceType; }
112
118 const std::string& GetResolvedDefinitionURI() const { return _definitionURI; }
119
125 const std::string& GetResolvedImplementationURI() const {
126 return _implementationURI;
127 }
128
140 const std::string &GetSourceCode() const { return _sourceCode; }
141
150 SDR_API
151 bool IsValid() const { return _isValid; }
152
155 SDR_API
156 std::string GetInfoString() const;
157
159
163
165 SDR_API
166 const SdrTokenVec& GetShaderInputNames() const;
167
169 SDR_API
170 const SdrTokenVec& GetShaderOutputNames() const;
171
174 SDR_API
175 SdrShaderPropertyConstPtr GetShaderInput(const TfToken& inputName) const;
176
179 SDR_API
180 SdrShaderPropertyConstPtr GetShaderOutput(const TfToken& outputName) const;
181
184 SDR_API
185 SdrTokenVec GetAssetIdentifierInputNames() const;
186
191 SDR_API
192 SdrShaderPropertyConstPtr GetDefaultInput() const;
193
195
196
203
213 SDR_API
214 const SdrTokenMap& GetMetadata() const;
215
217 SDR_API
219
225 SDR_API
226 const TfToken& GetLabel() const { return _label; }
227
232 SDR_API
233 const TfToken& GetCategory() const { return _category; }
234
241 SDR_API
243
247 SDR_API
248 std::string GetHelp() const;
249
251 SDR_API
252 const SdrTokenVec& GetDepartments() const { return _departments; }
253
259 SDR_API
260 const SdrTokenVec& GetPages() const { return _pages; }
261
263 SDR_API
264 const SdrTokenVec& GetOpenPages() const { return _openPages; }
265
267 SDR_API
268 const SdrTokenMap& GetPagesShownIf() const { return _pagesShownIf; }
269
280 SDR_API
281 const SdrTokenVec& GetPrimvars() const { return _primvars; }
282
289 SDR_API
290 const SdrTokenVec& GetAdditionalPrimvarProperties() const {
291 return _primvarNamingProperties;
292 }
293
301 SDR_API
302 std::string GetImplementationName() const;
303
305
306
309
313 SDR_API
314 SdrTokenVec GetPropertyNamesForPage(const std::string& pageName) const;
315
317 SDR_API
318 SdrTokenVec GetAllVstructNames() const;
319
321
322 // Stores the result of the compliance check of property names to
323 // sdrShaderNodeIdentifiers
324 using ComplianceResults = std::unordered_map<TfToken,
325 std::vector<SdrIdentifier>,
327
338 SDR_API
339 static
340 ComplianceResults CheckPropertyCompliance(
341 const std::vector<SdrShaderNodeConstPtr> &shaderNodes);
342
345
346 // Performs a post-process on properties to determine information that can
347 // only be determined after parsing or in aggregate. Clients SHOULD NOT
348 // need to call this.
349 void _PostProcessProperties();
350
352
355
372 SDR_API
373 VtValue GetDataForKey(const TfToken& key) const;
374
375protected:
376 SdrShaderNode& operator=(const SdrShaderNode&) = delete;
377
378 bool _isValid;
379 SdrIdentifier _identifier;
380 SdrVersion _version;
381 std::string _name;
382 TfToken _family;
383 TfToken _context;
384 TfToken _sourceType;
385 std::string _definitionURI;
386 std::string _implementationURI;
387 SdrShaderPropertyUniquePtrVec _properties;
388 SdrTokenMap _legacyMetadata;
389 SdrShaderNodeMetadata _metadata;
390 std::string _sourceCode;
391
392 SdrShaderPropertyMap _inputs;
393 SdrTokenVec _inputNames;
394 SdrShaderPropertyMap _outputs;
395 SdrTokenVec _outputNames;
396
397 // Stored metadata to support getter API on SdrShaderNode that
398 // returns const ref.
399 TfToken _label;
400 TfToken _category;
401 SdrTokenVec _departments;
402 SdrTokenVec _openPages;
403 SdrTokenMap _pagesShownIf;
404
405 // Processed primvar metadata. `_primvars` contains the names of primvars
406 // consumed by this node, whereas `_primvarNamingProperties` contains the
407 // names of string input properties whose values provide the names of
408 // additional primvars consumed by this node.
409 SdrTokenVec _primvars;
410 SdrTokenVec _primvarNamingProperties;
411
412 // Aggregated pages data, from examining SdrShaderProperty's page metadata
413 SdrTokenVec _pages;
414
415private:
416 // Initializes `_primvars` and `_primvarNamingProperties`
417 void _InitializePrimvars();
418
419 // Determines which pages are present on the node's properties
420 SdrTokenVec _ComputePages() const;
421};
422
423PXR_NAMESPACE_CLOSE_SCOPE
424
425#endif // PXR_USD_SDR_SHADER_NODE_H
Represents a node that holds shading information.
Definition: shaderNode.h:40
SDR_API const SdrTokenMap & GetMetadata() const
All metadata that came from the parse process.
SDR_API const SdrTokenVec & GetPrimvars() const
The list of primvars this node knows it requires / uses.
Definition: shaderNode.h:281
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:290
const SdrIdentifier & GetIdentifier() const
Return the identifier of the node.
Definition: shaderNode.h:73
SDR_API const TfToken & GetLabel() const
The label assigned to this node, if any.
Definition: shaderNode.h:226
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:83
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:233
const std::string & GetName() const
Gets the name of the node.
Definition: shaderNode.h:79
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 TfToken GetRole() const
Returns the role of this node.
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 SdrShaderNodeMetadata &metadata=SdrShaderNodeMetadata(), const std::string &sourceCode=std::string())
Constructor.
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:260
const TfToken & GetContext() const
Gets the context of the shader node.
Definition: shaderNode.h:97
SDR_API const SdrTokenVec & GetDepartments() const
The departments this node is associated with, if any.
Definition: shaderNode.h:252
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:125
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:76
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:268
SDR_API const SdrTokenVec & GetOpenPages() const
Gets the pages which should be opened or expanded by default.
Definition: shaderNode.h:264
const std::string & GetSourceCode() const
Returns the source code for this node.
Definition: shaderNode.h:140
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:111
SDR_API bool IsValid() const
Whether or not this node is valid.
Definition: shaderNode.h:151
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:118
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
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...