This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
shaderProperty.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_PROPERTY_H
9#define PXR_USD_SDR_SHADER_PROPERTY_H
10
12
13#include "pxr/pxr.h"
14#include "pxr/usd/sdr/api.h"
16#include "pxr/base/tf/token.h"
18#include "pxr/base/vt/value.h"
22
23PXR_NAMESPACE_OPEN_SCOPE
24
25// If additional types are added here, it's also worth trying to add a mapping
26// to the equivalent Sdf type in the implementation file.
27#define SDR_PROPERTY_TYPE_TOKENS \
28 ((Int, "int")) \
29 ((String, "string")) \
30 ((Float, "float")) \
31 ((Color, "color")) \
32 ((Color4, "color4")) \
33 ((Point, "point")) \
34 ((Normal, "normal")) \
35 ((Vector, "vector")) \
36 ((Matrix, "matrix")) \
37 ((Struct, "struct")) \
38 ((Terminal, "terminal")) \
39 ((Vstruct, "vstruct")) \
40 ((Unknown, "unknown"))
41
42// Note: Metadata keys that are generated by parsers should start with
43// "__SDR__" to reduce the risk of collision with metadata actually in the
44// shader.
45#define SDR_PROPERTY_METADATA_TOKENS \
46 ((Label, "label")) \
47 ((Help, "help")) \
48 ((Page, "page")) \
49 ((RenderType, "renderType")) \
50 ((Role, "role")) \
51 ((Widget, "widget")) \
52 ((Hints, "hints")) \
53 ((Options, "options")) \
54 ((IsDynamicArray, "isDynamicArray")) \
55 ((Connectable, "connectable")) \
56 ((Tag, "tag")) \
57 ((ValidConnectionTypes, "validConnectionTypes")) \
58 ((VstructMemberOf, "vstructMemberOf")) \
59 ((VstructMemberName, "vstructMemberName")) \
60 ((VstructConditionalExpr, "vstructConditionalExpr"))\
61 ((IsAssetIdentifier, "__SDR__isAssetIdentifier"))\
62 ((ImplementationName, "__SDR__implementationName"))\
63 ((SdrUsdDefinitionType, "sdrUsdDefinitionType"))\
64 ((DefaultInput, "__SDR__defaultinput")) \
65 ((Target, "__SDR__target")) \
66 ((Colorspace, "__SDR__colorspace"))
67
68
69// The following tokens are valid values for the metadata "role"
70#define SDR_PROPERTY_ROLE_TOKENS \
71 ((None, "none"))
72
73#define SDR_PROPERTY_TOKENS \
74 ((PageDelimiter, ":"))
75
76TF_DECLARE_PUBLIC_TOKENS(SdrPropertyTypes, SDR_API, SDR_PROPERTY_TYPE_TOKENS);
77TF_DECLARE_PUBLIC_TOKENS(SdrPropertyMetadata, SDR_API,
78 SDR_PROPERTY_METADATA_TOKENS);
79TF_DECLARE_PUBLIC_TOKENS(SdrPropertyRole, SDR_API,
80 SDR_PROPERTY_ROLE_TOKENS);
81TF_DECLARE_PUBLIC_TOKENS(SdrPropertyTokens, SDR_API, SDR_PROPERTY_TOKENS);
82
88{
89public:
90 // Constructor.
91 SDR_API
93 const TfToken& name,
94 const TfToken& type,
95 const VtValue& defaultValue,
96 bool isOutput,
97 size_t arraySize,
98 const NdrTokenMap& metadata,
99 const NdrTokenMap& hints,
100 const NdrOptionVec& options
101 );
102
109
113 SDR_API
114 const TfToken& GetLabel() const { return _label; }
115
117 SDR_API
118 std::string GetHelp() const;
119
123 SDR_API
124 const TfToken& GetPage() const { return _page; }
125
129 SDR_API
130 const TfToken& GetWidget() const { return _widget; }
131
134 SDR_API
135 const NdrTokenMap& GetHints() const { return _hints; }
136
140 SDR_API
141 const NdrOptionVec& GetOptions() const { return _options; }
142
150 SDR_API
151 std::string GetImplementationName() const;
152
154
155
158
160 SDR_API
162 return _vstructMemberOf;
163 }
164
166 SDR_API
168 return _vstructMemberName;
169 }
170
172 SDR_API
173 bool IsVStructMember() const;
174
176 SDR_API
177 bool IsVStruct() const;
178
179
181 SDR_API
183 return _vstructConditionalExpr;
184 }
185
187
188
191
195 SDR_API
196 bool IsConnectable() const override { return _isConnectable; }
197
202 SDR_API
203 const NdrTokenVec& GetValidConnectionTypes() const {
204 return _validConnectionTypes;
205 }
206
208 SDR_API
209 bool CanConnectTo(const NdrProperty& other) const override;
210
212
213
216
227 SDR_API
229
237 SDR_API
238 const VtValue& GetDefaultValueAsSdfType() const override {
239 return _sdfTypeDefaultValue;
240 }
241
248 SDR_API
249 bool IsAssetIdentifier() const;
250
253 SDR_API
254 bool IsDefaultInput() const;
255
257
258protected:
259 SdrShaderProperty& operator=(const SdrShaderProperty&) = delete;
260
261 // Allow the shader's post process function to access the property's
262 // internals. Some property information can only be determined after parse
263 // time.
264 friend void SdrShaderNode::_PostProcessProperties();
265
266 // Set the USD encoding version to something other than the default.
267 // This can be set in SdrShaderNode::_PostProcessProperties for all the
268 // properties on a shader node.
269 void _SetUsdEncodingVersion(int usdEncodingVersion);
270
271 // Convert this property to a VStruct, which has a special type and a
272 // different default value
273 void _ConvertToVStruct();
274
275 // This function is called by SdrShaderNode::_PostProcessProperties once all
276 // information is locked in and won't be changed anymore. This allows each
277 // property to take some extra steps once all information is available.
278 void _FinalizeProperty();
279
280 // Some metadata values cannot be returned by reference from the main
281 // metadata dictionary because they need additional parsing.
282 const NdrTokenMap _hints;
283 const NdrOptionVec _options;
284
285 // Tokenized metadata
286 NdrTokenVec _validConnectionTypes;
287 TfToken _label;
288 TfToken _page;
289 TfToken _widget;
290 TfToken _vstructMemberOf;
291 TfToken _vstructMemberName;
292 TfToken _vstructConditionalExpr;
293
294 VtValue _sdfTypeDefaultValue;
295
296 // Metadatum to control the behavior of GetTypeAsSdfType and indirectly
297 // CanConnectTo
298 int _usdEncodingVersion;
299};
300
301PXR_NAMESPACE_CLOSE_SCOPE
302
303#endif // PXR_USD_SDR_SHADER_PROPERTY_H
Represents a property (input or output) that is part of a NdrNode instance.
Definition: property.h:35
Represents a mapping from an Ndr Property type to Sdf type.
A specialized version of NdrProperty which holds shading information.
SDR_API bool IsVStruct() const
Returns true if the field is the head of a vstruct.
SDR_API const TfToken & GetVStructMemberOf() const
If this field is part of a vstruct, this is the name of the struct.
SDR_API bool IsConnectable() const override
Whether this property can be connected to other properties.
SDR_API bool CanConnectTo(const NdrProperty &other) const override
Determines if this property can be connected to the specified property.
SDR_API const TfToken & GetLabel() const
The label assigned to this property, if any.
SDR_API const TfToken & GetPage() const
The page (group), eg "Advanced", this property appears on, if any.
SDR_API const TfToken & GetWidget() const
The widget "hint" that indicates the widget that can best display the type of data contained in this ...
SDR_API NdrSdfTypeIndicator GetTypeAsSdfType() const override
Converts the property's type from GetType() into a NdrSdfTypeIndicator.
SDR_API bool IsAssetIdentifier() const
Determines if the value held by this property is an asset identifier (eg, a file path); the logic for...
SDR_API const TfToken & GetVStructMemberName() const
If this field is part of a vstruct, this is its name in the struct.
SDR_API std::string GetHelp() const
The help message assigned to this property, if any.
SDR_API const NdrOptionVec & GetOptions() const
If the property has a set of valid values that are pre-determined, this will return the valid option ...
SDR_API const NdrTokenVec & GetValidConnectionTypes() const
Gets the list of valid connection types for this property.
SDR_API std::string GetImplementationName() const
Returns the implementation name of this property.
SDR_API const VtValue & GetDefaultValueAsSdfType() const override
Accessor for default value corresponding to the SdfValueTypeName returned by GetTypeAsSdfType.
SDR_API bool IsDefaultInput() const
Determines if the value held by this property is the default input for this node.
SDR_API bool IsVStructMember() const
Returns true if this field is part of a vstruct.
SDR_API const NdrTokenMap & GetHints() const
Any UI "hints" that are associated with this property.
SDR_API const TfToken & GetVStructConditionalExpr() const
If this field is part of a vstruct, this is the conditional expression.
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:147
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:81
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...