Loading...
Searching...
No Matches
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"
33#include "pxr/usd/ndr/node.h"
34#include "pxr/usd/sdr/declare.h"
35
36PXR_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 ((SdrUsdEncodingVersion, "sdrUsdEncodingVersion")) \
52 ((SdrDefinitionNameFallbackPrefix, "sdrDefinitionNameFallbackPrefix"))
53
54// Note: The concept of context is defined on NdrNode and can be queried with
55// the GetContext() method. Sdr categorizes shaders by the context in which they
56// are used inside of a renderer. For instance during 'pattern' evaluation to
57// feed into a surface or volume shader. For BXDFs used in 'surface' and
58// 'volume' rendering situations.
59#define SDR_NODE_CONTEXT_TOKENS \
60 ((Pattern, "pattern")) \
61 ((Surface, "surface")) \
62 ((Volume, "volume")) \
63 ((Displacement, "displacement")) \
64 ((Light, "light")) \
65 ((DisplayFilter, "displayFilter")) \
66 ((LightFilter, "lightFilter")) \
67 ((PixelFilter, "pixelFilter")) \
68 ((SampleFilter, "sampleFilter"))
69
70#define SDR_NODE_ROLE_TOKENS \
71 ((Primvar, "primvar")) \
72 ((Texture, "texture")) \
73 ((Field, "field")) \
74 ((Math, "math")) \
75
76TF_DECLARE_PUBLIC_TOKENS(SdrNodeMetadata, SDR_API, SDR_NODE_METADATA_TOKENS);
77TF_DECLARE_PUBLIC_TOKENS(SdrNodeContext, SDR_API, SDR_NODE_CONTEXT_TOKENS);
78TF_DECLARE_PUBLIC_TOKENS(SdrNodeRole, SDR_API, SDR_NODE_ROLE_TOKENS);
79
84class SdrShaderNode : public NdrNode
85{
86public:
88 SDR_API
89 SdrShaderNode(const NdrIdentifier& identifier,
90 const NdrVersion& version,
91 const std::string& name,
92 const TfToken& family,
93 const TfToken& context,
94 const TfToken& sourceType,
95 const std::string& definitionURI,
96 const std::string& implementationURI,
97 NdrPropertyUniquePtrVec&& properties,
98 const NdrTokenMap& metadata = NdrTokenMap(),
99 const std::string &sourceCode = std::string());
100
104
107 SDR_API
108 SdrShaderPropertyConstPtr GetShaderInput(const TfToken& inputName) const;
109
112 SDR_API
113 SdrShaderPropertyConstPtr GetShaderOutput(const TfToken& outputName) const;
114
117 SDR_API
118 NdrTokenVec GetAssetIdentifierInputNames() const;
119
124 SDR_API
125 SdrShaderPropertyConstPtr GetDefaultInput() const;
126
128
129
136
140 SDR_API
141 const TfToken& GetLabel() const { return _label; }
142
145 SDR_API
146 const TfToken& GetCategory() const { return _category; }
147
154 SDR_API
155 std::string GetRole() const;
156
158 SDR_API
159 std::string GetHelp() const;
160
162 SDR_API
163 const NdrTokenVec& GetDepartments() const { return _departments; }
164
170 SDR_API
171 const NdrTokenVec& GetPages() const { return _pages; };
172
179 SDR_API
180 const NdrTokenVec& GetPrimvars() const { return _primvars; }
181
188 SDR_API
189 const NdrTokenVec& GetAdditionalPrimvarProperties() const {
190 return _primvarNamingProperties;
191 }
192
200 SDR_API
201 std::string GetImplementationName() const;
202
204
205
208
212 SDR_API
213 NdrTokenVec GetPropertyNamesForPage(const std::string& pageName) const;
214
216 SDR_API
217 NdrTokenVec GetAllVstructNames() const;
218
220
221
224
225 // Performs a post-process on properties to determine information that can
226 // only be determined after parsing or in aggregate. Clients SHOULD NOT
227 // need to call this.
228 void _PostProcessProperties();
229
231
232protected:
233 // Processed primvar metadata. `_primvars` contains the names of primvars
234 // consumed by this node, whereas `_primvarNamingProperties` contains the
235 // names of string input properties whose values provide the names of
236 // additional primvars consumed by this node.
237 NdrTokenVec _primvars;
238 NdrTokenVec _primvarNamingProperties;
239
240 // Tokenized metadata
241 TfToken _label;
242 TfToken _category;
243 NdrTokenVec _departments;
244 NdrTokenVec _pages;
245
246 SdrPropertyMap _shaderInputs;
247 SdrPropertyMap _shaderOutputs;
248
249private:
250 // Initializes `_primvars` and `_primvarNamingProperties`
251 void _InitializePrimvars();
252
253 // Determines which pages are present on the node's properties
254 NdrTokenVec _ComputePages() const;
255};
256
257PXR_NAMESPACE_CLOSE_SCOPE
258
259#endif // PXR_USD_SDR_SHADER_NODE_H
Represents an abstract node.
Definition: node.h:49
A specialized version of NdrNode which holds shading information.
Definition: shaderNode.h:85
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:189
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:171
SDR_API const TfToken & GetLabel() const
The label assigned to this node, if any.
Definition: shaderNode.h:141
SDR_API SdrShaderPropertyConstPtr GetShaderInput(const TfToken &inputName) const
Get a shader input property by name.
SDR_API NdrTokenVec GetAssetIdentifierInputNames() const
Returns the list of all inputs that are tagged as asset identifier inputs.
SDR_API const TfToken & GetCategory() const
The category assigned to this node, if any.
Definition: shaderNode.h:146
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 &definitionURI, const std::string &implementationURI, NdrPropertyUniquePtrVec &&properties, const NdrTokenMap &metadata=NdrTokenMap(), const std::string &sourceCode=std::string())
Constructor.
SDR_API NdrTokenVec GetAllVstructNames() const
Gets all vstructs that are present in the shader.
SDR_API SdrShaderPropertyConstPtr GetShaderOutput(const TfToken &outputName) const
Get a shader output property by name.
SDR_API const NdrTokenVec & GetPrimvars() const
The list of primvars this node knows it requires / uses.
Definition: shaderNode.h:180
SDR_API std::string GetHelp() const
The help message assigned to this node, if any.
SDR_API const NdrTokenVec & GetDepartments() const
The departments this node is associated with, if any.
Definition: shaderNode.h:163
SDR_API std::string GetImplementationName() const
Returns the implementation name of this node.
SDR_API SdrShaderPropertyConstPtr GetDefaultInput() const
Returns the first shader input that is tagged as the default input.
SDR_API std::string GetRole() const
Returns the role of this node.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
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:98