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/usd/sdr/declare.h"
19
20#include <unordered_map>
21
22PXR_NAMESPACE_OPEN_SCOPE
23
24// Note: Metadata keys that are generated by parsers should start with
25// "__SDR__" to reduce the risk of collision with metadata actually in the
26// shader.
27#define SDR_NODE_METADATA_TOKENS \
28 ((Category, "category")) \
29 ((Role, "role")) \
30 ((Departments, "departments")) \
31 ((Help, "help")) \
32 ((Label, "label")) \
33 ((Pages, "pages")) \
34 ((OpenPages, "openPages")) \
35 ((Primvars, "primvars")) \
36 ((ImplementationName, "__SDR__implementationName"))\
37 ((Target, "__SDR__target")) \
38 ((SdrUsdEncodingVersion, "sdrUsdEncodingVersion")) \
39 ((SdrDefinitionNameFallbackPrefix, "sdrDefinitionNameFallbackPrefix"))
40
41// Note: The concept of context can be queried with the GetContext() method.
42// Sdr categorizes shaders by the context in which they are used inside of a
43// renderer. For instance during 'pattern' evaluation to feed into a surface
44// or volume shader. For BXDFs used in 'surface' and 'volume'
45// rendering situations.
46#define SDR_NODE_CONTEXT_TOKENS \
47 ((Pattern, "pattern")) \
48 ((Surface, "surface")) \
49 ((Volume, "volume")) \
50 ((Displacement, "displacement")) \
51 ((Light, "light")) \
52 ((DisplayFilter, "displayFilter")) \
53 ((LightFilter, "lightFilter")) \
54 ((PixelFilter, "pixelFilter")) \
55 ((SampleFilter, "sampleFilter"))
56
57#define SDR_NODE_ROLE_TOKENS \
58 ((Primvar, "primvar")) \
59 ((Texture, "texture")) \
60 ((Field, "field")) \
61 ((Math, "math")) \
62
63TF_DECLARE_PUBLIC_TOKENS(SdrNodeMetadata, SDR_API, SDR_NODE_METADATA_TOKENS);
64TF_DECLARE_PUBLIC_TOKENS(SdrNodeContext, SDR_API, SDR_NODE_CONTEXT_TOKENS);
65TF_DECLARE_PUBLIC_TOKENS(SdrNodeRole, SDR_API, SDR_NODE_ROLE_TOKENS);
66
73{
74public:
76 SDR_API
78 const SdrIdentifier& identifier,
79 const SdrVersion& version,
80 const std::string& name,
81 const TfToken& family,
82 const TfToken& context,
83 const TfToken& sourceType,
84 const std::string& definitionURI,
85 const std::string& implementationURI,
86 SdrShaderPropertyUniquePtrVec&& properties,
87 const SdrTokenMap& metadata = SdrTokenMap(),
88 const std::string &sourceCode = std::string());
89
91 SDR_API
92 virtual ~SdrShaderNode();
93
96
98 const SdrIdentifier& GetIdentifier() const { return _identifier; }
99
101 SdrVersion GetShaderVersion() const { return _version; }
102
104 const std::string& GetName() const { return _name; }
105
108 const TfToken& GetFamily() const { return _family; }
109
122 const TfToken& GetContext() const { return _context; }
123
136 const TfToken& GetSourceType() const { return _sourceType; }
137
143 const std::string& GetResolvedDefinitionURI() const { return _definitionURI; }
144
150 const std::string& GetResolvedImplementationURI() const {
151 return _implementationURI;
152 }
153
165 const std::string &GetSourceCode() const { return _sourceCode; }
166
175 SDR_API
176 bool IsValid() const { return _isValid; }
177
180 SDR_API
181 std::string GetInfoString() const;
182
184
188
190 SDR_API
191 const SdrTokenVec& GetShaderInputNames() const;
192
194 SDR_API
195 const SdrTokenVec& GetShaderOutputNames() const;
196
199 SDR_API
200 SdrShaderPropertyConstPtr GetShaderInput(const TfToken& inputName) const;
201
204 SDR_API
205 SdrShaderPropertyConstPtr GetShaderOutput(const TfToken& outputName) const;
206
209 SDR_API
210 SdrTokenVec GetAssetIdentifierInputNames() const;
211
216 SDR_API
217 SdrShaderPropertyConstPtr GetDefaultInput() const;
218
220
221
228
230 SDR_API
231 const SdrTokenMap& GetMetadata() const;
232
236 SDR_API
237 const TfToken& GetLabel() const { return _label; }
238
241 SDR_API
242 const TfToken& GetCategory() const { return _category; }
243
250 SDR_API
251 std::string GetRole() const;
252
254 SDR_API
255 std::string GetHelp() const;
256
258 SDR_API
259 const SdrTokenVec& GetDepartments() const { return _departments; }
260
266 SDR_API
267 const SdrTokenVec& GetPages() const { return _pages; };
268
270 SDR_API
271 const SdrTokenVec& GetOpenPages() const { return _openPages; };
272
279 SDR_API
280 const SdrTokenVec& GetPrimvars() const { return _primvars; }
281
288 SDR_API
289 const SdrTokenVec& GetAdditionalPrimvarProperties() const {
290 return _primvarNamingProperties;
291 }
292
300 SDR_API
301 std::string GetImplementationName() const;
302
304
305
308
312 SDR_API
313 SdrTokenVec GetPropertyNamesForPage(const std::string& pageName) const;
314
316 SDR_API
317 SdrTokenVec GetAllVstructNames() const;
318
320
321 // Stores the result of the compliance check of property names to
322 // sdrShaderNodeIdentifiers
323 using ComplianceResults = std::unordered_map<TfToken,
324 std::vector<SdrIdentifier>,
326
337 SDR_API
338 static
339 ComplianceResults CheckPropertyCompliance(
340 const std::vector<SdrShaderNodeConstPtr> &shaderNodes);
341
344
345 // Performs a post-process on properties to determine information that can
346 // only be determined after parsing or in aggregate. Clients SHOULD NOT
347 // need to call this.
348 void _PostProcessProperties();
349
351
352protected:
353 SdrShaderNode& operator=(const SdrShaderNode&) = delete;
354
355 bool _isValid;
356 SdrIdentifier _identifier;
357 SdrVersion _version;
358 std::string _name;
359 TfToken _family;
360 TfToken _context;
361 TfToken _sourceType;
362 std::string _definitionURI;
363 std::string _implementationURI;
364 SdrShaderPropertyUniquePtrVec _properties;
365 SdrTokenMap _metadata;
366 std::string _sourceCode;
367
368 SdrShaderPropertyMap _inputs;
369 SdrTokenVec _inputNames;
370 SdrShaderPropertyMap _outputs;
371 SdrTokenVec _outputNames;
372
373 // Processed primvar metadata. `_primvars` contains the names of primvars
374 // consumed by this node, whereas `_primvarNamingProperties` contains the
375 // names of string input properties whose values provide the names of
376 // additional primvars consumed by this node.
377 SdrTokenVec _primvars;
378 SdrTokenVec _primvarNamingProperties;
379
380 // Tokenized metadata
381 TfToken _label;
382 TfToken _category;
383 SdrTokenVec _departments;
384 SdrTokenVec _pages;
385 SdrTokenVec _openPages;
386
387private:
388 // Initializes `_primvars` and `_primvarNamingProperties`
389 void _InitializePrimvars();
390
391 // Determines which pages are present on the node's properties
392 SdrTokenVec _ComputePages() const;
393};
394
395PXR_NAMESPACE_CLOSE_SCOPE
396
397#endif // PXR_USD_SDR_SHADER_NODE_H
Represents a node that holds shading information.
Definition: shaderNode.h:73
SDR_API const SdrTokenMap & GetMetadata() const
All metadata that came from the parse process.
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.
SDR_API const SdrTokenVec & GetPrimvars() const
The list of primvars this node knows it requires / uses.
Definition: shaderNode.h:280
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:289
const SdrIdentifier & GetIdentifier() const
Return the identifier of the node.
Definition: shaderNode.h:98
SDR_API const TfToken & GetLabel() const
The label assigned to this node, if any.
Definition: shaderNode.h:237
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:108
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:242
const std::string & GetName() const
Gets the name of the node.
Definition: shaderNode.h:104
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 SdrShaderPropertyConstPtr GetShaderOutput(const TfToken &outputName) const
Get a shader output property by name.
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:267
const TfToken & GetContext() const
Gets the context of the shader node.
Definition: shaderNode.h:122
SDR_API const SdrTokenVec & GetDepartments() const
The departments this node is associated with, if any.
Definition: shaderNode.h:259
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:150
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:101
SDR_API const SdrTokenVec & GetOpenPages() const
Gets the pages which should be opened or expanded by default.
Definition: shaderNode.h:271
const std::string & GetSourceCode() const
Returns the source code for this node.
Definition: shaderNode.h:165
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:136
SDR_API bool IsValid() const
Whether or not this node is valid.
Definition: shaderNode.h:176
SDR_API std::string GetRole() const
Returns the role of this node.
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:143
SdrVersion.
Definition: declare.h:67
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
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...