All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
shaderNode.h
Go to the documentation of this file.
1 //
2 // Copyright 2018 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 
25 #ifndef PXR_USD_SDR_SHADER_NODE_H
26 #define PXR_USD_SDR_SHADER_NODE_H
27 
29 
30 #include "pxr/pxr.h"
31 #include "pxr/usd/sdr/api.h"
32 #include "pxr/base/tf/staticTokens.h"
33 #include "pxr/usd/ndr/node.h"
34 #include "pxr/usd/sdr/declare.h"
35 
36 PXR_NAMESPACE_OPEN_SCOPE
37 
38 // Note: Metadata keys that are generated by parsers should start with
39 // "__SDR__" to reduce the risk of collision with metadata actually in the
40 // shader.
41 #define SDR_NODE_METADATA_TOKENS \
42  ((Category, "category")) \
43  ((Role, "role")) \
44  ((Departments, "departments")) \
45  ((Help, "help")) \
46  ((Label, "label")) \
47  ((Pages, "pages")) \
48  ((Primvars, "primvars")) \
49  ((ImplementationName, "__SDR__implementationName"))\
50  ((Target, "__SDR__target"))
51 
52 // Note: The concept of context is defined on NdrNode and can be queried with
53 // the GetContext() method. Sdr categorizes shaders by the context in which they
54 // are used inside of a renderer. For instance during 'pattern' evaluation to
55 // feed into a surface or volume shader. For BXDFs used in 'surface' and
56 // 'volume' rendering situations.
57 #define SDR_NODE_CONTEXT_TOKENS \
58  ((Pattern, "pattern")) \
59  ((Surface, "surface")) \
60  ((Volume, "volume")) \
61  ((Displacement, "displacement")) \
62  ((Light, "light")) \
63  ((LightFilter, "lightFilter")) \
64  ((SampleFilter, "sampleFilter")) \
65  ((PixelFilter, "pixelFilter"))
66 
67 #define SDR_NODE_ROLE_TOKENS \
68  ((Primvar, "primvar")) \
69  ((Texture, "texture")) \
70  ((Field, "field"))
71 
72 TF_DECLARE_PUBLIC_TOKENS(SdrNodeMetadata, SDR_API, SDR_NODE_METADATA_TOKENS);
73 TF_DECLARE_PUBLIC_TOKENS(SdrNodeContext, SDR_API, SDR_NODE_CONTEXT_TOKENS);
74 TF_DECLARE_PUBLIC_TOKENS(SdrNodeRole, SDR_API, SDR_NODE_ROLE_TOKENS);
75 
80 class SdrShaderNode : public NdrNode
81 {
82 public:
84  SDR_API
85  SdrShaderNode(const NdrIdentifier& identifier,
86  const NdrVersion& version,
87  const std::string& name,
88  const TfToken& family,
89  const TfToken& context,
90  const TfToken& sourceType,
91  const std::string& uri,
92  const std::string& resolvedUri,
93  NdrPropertyUniquePtrVec&& properties,
94  const NdrTokenMap& metadata = NdrTokenMap(),
95  const std::string &sourceCode = std::string());
96 
100 
103  SDR_API
104  SdrShaderPropertyConstPtr GetShaderInput(const TfToken& inputName) const;
105 
108  SDR_API
109  SdrShaderPropertyConstPtr GetShaderOutput(const TfToken& outputName) const;
110 
113  SDR_API
114  NdrTokenVec GetAssetIdentifierInputNames() const;
115 
120  SDR_API
121  SdrShaderPropertyConstPtr GetDefaultInput() const;
122 
124 
125 
132 
136  SDR_API
137  const TfToken& GetLabel() const { return _label; }
138 
141  SDR_API
142  const TfToken& GetCategory() const { return _category; }
143 
150  SDR_API
151  const std::string &GetRole() const;
152 
154  SDR_API
155  const std::string& GetHelp() const;
156 
158  SDR_API
159  const NdrTokenVec& GetDepartments() const { return _departments; }
160 
166  SDR_API
167  const NdrTokenVec& GetPages() const { return _pages; };
168 
175  SDR_API
176  const NdrTokenVec& GetPrimvars() const { return _primvars; }
177 
184  SDR_API
185  const NdrTokenVec& GetAdditionalPrimvarProperties() const {
186  return _primvarNamingProperties;
187  }
188 
196  SDR_API
197  const std::string& GetImplementationName() const;
198 
200 
201 
204 
208  SDR_API
209  NdrTokenVec GetPropertyNamesForPage(const std::string& pageName) const;
210 
212  SDR_API
213  NdrTokenVec GetAllVstructNames() const;
214 
216 
217 
220 
221  // Performs a post-process on properties to determine information that can
222  // only be determined after parsing or in aggregate. Clients SHOULD NOT
223  // need to call this.
224  void _PostProcessProperties();
225 
227 
228 protected:
229  // Processed primvar metadata. `_primvars` contains the names of primvars
230  // consumed by this node, whereas `_primvarNamingProperties` contains the
231  // names of string input properties whose values provide the names of
232  // additional primvars consumed by this node.
233  NdrTokenVec _primvars;
234  NdrTokenVec _primvarNamingProperties;
235 
236  // Tokenized metadata
237  TfToken _label;
238  TfToken _category;
239  NdrTokenVec _departments;
240  NdrTokenVec _pages;
241 
242  SdrPropertyMap _shaderInputs;
243  SdrPropertyMap _shaderOutputs;
244 
245 private:
246  // Initializes `_primvars` and `_primvarNamingProperties`
247  void _InitializePrimvars();
248 
249  // Determines which pages are present on the node's properties
250  NdrTokenVec _ComputePages() const;
251 };
252 
253 PXR_NAMESPACE_CLOSE_SCOPE
254 
255 #endif // PXR_USD_SDR_SHADER_NODE_H
SDR_API const std::string & GetHelp() const
The help message assigned to this node, if any.
SDR_API NdrTokenVec GetAssetIdentifierInputNames() const
Returns the list of all inputs that are tagged as asset identifier inputs.
SDR_API const NdrTokenVec & GetDepartments() const
The departments this node is associated with, if any.
Definition: shaderNode.h:159
SDR_API const std::string & GetRole() const
Returns the role of this node.
SDR_API const NdrTokenVec & GetPages() const
Gets the pages on which the node's properties reside (an aggregate of the unique SdrShaderProperty::G...
Definition: shaderNode.h:167
SDR_API const NdrTokenVec & GetPrimvars() const
The list of primvars this node knows it requires / uses.
Definition: shaderNode.h:176
SDR_API const TfToken & GetCategory() const
The category assigned to this node, if any.
Definition: shaderNode.h:142
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
SDR_API const std::string & GetImplementationName() const
Returns the implementation name of this node.
Represents an abstract node.
Definition: node.h:48
SDR_API NdrTokenVec GetAllVstructNames() const
Gets all vstructs that are present in the shader.
SDR_API const NdrTokenVec & GetAdditionalPrimvarProperties() const
The list of string input properties whose values provide the names of additional primvars consumed by...
Definition: shaderNode.h:185
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:118
SDR_API SdrShaderPropertyConstPtr GetShaderOutput(const TfToken &outputName) const
Get a shader output property by name.
A specialized version of NdrNode which holds shading information.
Definition: shaderNode.h:80
SDR_API SdrShaderPropertyConstPtr GetShaderInput(const TfToken &inputName) const
Get a shader input property by name.
SDR_API SdrShaderPropertyConstPtr GetDefaultInput() const
Returns the first shader input that is tagged as the default input.
SDR_API NdrTokenVec 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 NdrIdentifier &identifier, const NdrVersion &version, const std::string &name, const TfToken &family, const TfToken &context, const TfToken &sourceType, const std::string &uri, const std::string &resolvedUri, NdrPropertyUniquePtrVec &&properties, const NdrTokenMap &metadata=NdrTokenMap(), const std::string &sourceCode=std::string())
Constructor.
SDR_API const TfToken & GetLabel() const
The label assigned to this node, if any.
Definition: shaderNode.h:137