Loading...
Searching...
No Matches
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
17
18#include "pxr/pxr.h"
20#include "pxr/base/tf/token.h"
22#include "pxr/base/vt/value.h"
24#include "pxr/usd/sdr/api.h"
25#include "pxr/usd/sdr/declare.h"
28
29PXR_NAMESPACE_OPEN_SCOPE
30
31// If additional types are added here, it's also worth trying to add a mapping
32// to the equivalent Sdf type in the implementation file.
33#define SDR_PROPERTY_TYPE_TOKENS \
34 ((Int, "int")) \
35 ((String, "string")) \
36 ((Float, "float")) \
37 ((Color, "color")) \
38 ((Color4, "color4")) \
39 ((Point, "point")) \
40 ((Normal, "normal")) \
41 ((Vector, "vector")) \
42 ((Matrix, "matrix")) \
43 ((Struct, "struct")) \
44 ((Terminal, "terminal")) \
45 ((Vstruct, "vstruct")) \
46 ((Unknown, "unknown"))
47
48// Note: Metadata keys that are generated by parsers should start with
49// "__SDR__" to reduce the risk of collision with metadata actually in the
50// shader.
51#define SDR_PROPERTY_METADATA_TOKENS \
52 ((Label, "label")) \
53 ((Help, "help")) \
54 ((Page, "page")) \
55 ((RenderType, "renderType")) \
56 ((Role, "role")) \
57 ((Widget, "widget")) \
58 ((Hints, "hints")) \
59 ((Options, "options")) \
60 ((IsDynamicArray, "isDynamicArray")) \
61 ((Connectable, "connectable")) \
62 ((Tag, "tag")) \
63 ((ValidConnectionTypes, "validConnectionTypes")) \
64 ((VstructMemberOf, "vstructMemberOf")) \
65 ((VstructMemberName, "vstructMemberName")) \
66 ((VstructConditionalExpr, "vstructConditionalExpr"))\
67 ((IsAssetIdentifier, "__SDR__isAssetIdentifier"))\
68 ((ImplementationName, "__SDR__implementationName"))\
69 ((SdrUsdDefinitionType, "sdrUsdDefinitionType"))\
70 ((DefaultInput, "__SDR__defaultinput")) \
71 ((Target, "__SDR__target")) \
72 ((Colorspace, "__SDR__colorspace"))
73
74
75// The following tokens are valid values for the metadata "role"
76#define SDR_PROPERTY_ROLE_TOKENS \
77 ((None, "none"))
78
79#define SDR_PROPERTY_TOKENS \
80 ((PageDelimiter, ":"))
81
82TF_DECLARE_PUBLIC_TOKENS(SdrPropertyTypes, SDR_API, SDR_PROPERTY_TYPE_TOKENS);
83TF_DECLARE_PUBLIC_TOKENS(SdrPropertyMetadata, SDR_API,
84 SDR_PROPERTY_METADATA_TOKENS);
85TF_DECLARE_PUBLIC_TOKENS(SdrPropertyRole, SDR_API,
86 SDR_PROPERTY_ROLE_TOKENS);
87TF_DECLARE_PUBLIC_TOKENS(SdrPropertyTokens, SDR_API, SDR_PROPERTY_TOKENS);
88
99{
100public:
101 // Constructor.
102 SDR_API
104 const TfToken& name,
105 const TfToken& type,
106 const VtValue& defaultValue,
107 bool isOutput,
108 size_t arraySize,
109 const SdrTokenMap& metadata,
110 const SdrTokenMap& hints,
111 const SdrOptionVec& options
112 );
113
120
124 SDR_API
125 const TfToken& GetLabel() const { return _label; }
126
128 SDR_API
129 std::string GetHelp() const;
130
134 SDR_API
135 const TfToken& GetPage() const { return _page; }
136
140 SDR_API
141 const TfToken& GetWidget() const { return _widget; }
142
145 SDR_API
146 const SdrTokenMap& GetHints() const { return _hints; }
147
151 SDR_API
152 const SdrOptionVec& GetOptions() const { return _options; }
153
161 SDR_API
162 std::string GetImplementationName() const;
163
165
166
169
171 SDR_API
173 return _vstructMemberOf;
174 }
175
177 SDR_API
179 return _vstructMemberName;
180 }
181
183 SDR_API
184 bool IsVStructMember() const;
185
187 SDR_API
188 bool IsVStruct() const;
189
190
192 SDR_API
194 return _vstructConditionalExpr;
195 }
196
198
199
202
206 SDR_API
207 bool IsConnectable() const override { return _isConnectable; }
208
213 SDR_API
214 const SdrTokenVec& GetValidConnectionTypes() const {
215 return _validConnectionTypes;
216 }
217
223 SDR_API
224 bool CanConnectTo(const NdrProperty& other) const override;
225
227 SDR_API
228 bool CanConnectTo(const SdrShaderProperty& other) const;
229
231
232
235
246 SDR_API
248
256 SDR_API
257 const VtValue& GetDefaultValueAsSdfType() const override {
258 return _sdfTypeDefaultValue;
259 }
260
267 SDR_API
268 bool IsAssetIdentifier() const;
269
272 SDR_API
273 bool IsDefaultInput() const;
274
276
277protected:
278 SdrShaderProperty& operator=(const SdrShaderProperty&) = delete;
279
280 // Allow the shader's post process function to access the property's
281 // internals. Some property information can only be determined after parse
282 // time.
283 friend void SdrShaderNode::_PostProcessProperties();
284
285 // Set the USD encoding version to something other than the default.
286 // This can be set in SdrShaderNode::_PostProcessProperties for all the
287 // properties on a shader node.
288 void _SetUsdEncodingVersion(int usdEncodingVersion);
289
290 // Convert this property to a VStruct, which has a special type and a
291 // different default value
292 void _ConvertToVStruct();
293
294 // This function is called by SdrShaderNode::_PostProcessProperties once all
295 // information is locked in and won't be changed anymore. This allows each
296 // property to take some extra steps once all information is available.
297 void _FinalizeProperty();
298
299 // Some metadata values cannot be returned by reference from the main
300 // metadata dictionary because they need additional parsing.
301 const SdrTokenMap _hints;
302 const SdrOptionVec _options;
303
304 // Tokenized metadata
305 SdrTokenVec _validConnectionTypes;
306 TfToken _label;
307 TfToken _page;
308 TfToken _widget;
309 TfToken _vstructMemberOf;
310 TfToken _vstructMemberName;
311 TfToken _vstructConditionalExpr;
312
313 VtValue _sdfTypeDefaultValue;
314
315 // Metadatum to control the behavior of GetTypeAsSdfType and indirectly
316 // CanConnectTo
317 int _usdEncodingVersion;
318};
319
320PXR_NAMESPACE_CLOSE_SCOPE
321
322#endif // PXR_USD_SDR_SHADER_PROPERTY_H
Represents a property (input or output) that is part of a NdrNode instance.
Definition: property.h:42
Represents a mapping from an Sdr Property type to Sdf type.
Represents a property (input or output) that is part of a SdrShaderNode instance.
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 CanConnectTo(const SdrShaderProperty &other) const
Determines if this property can be connected to the specified property.
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 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 SdrSdfTypeIndicator GetTypeAsSdfType() const override
Converts the property's type from GetType() into a SdrSdfTypeIndicator.
SDR_API const SdrTokenMap & GetHints() const
Any UI "hints" that are associated with this property.
SDR_API std::string GetHelp() const
The help message assigned to this property, if any.
SDR_API const SdrOptionVec & GetOptions() const
If the property has a set of valid values that are pre-determined, this will return the valid option ...
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 TfToken & GetVStructConditionalExpr() const
If this field is part of a vstruct, this is the conditional expression.
SDR_API const SdrTokenVec & GetValidConnectionTypes() const
Gets the list of valid connection types for this property.
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...