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
12
13#include "pxr/pxr.h"
15#include "pxr/base/tf/token.h"
17#include "pxr/base/vt/value.h"
18#include "pxr/usd/sdf/booleanExpression.h"
19#include "pxr/usd/sdr/api.h"
20#include "pxr/usd/sdr/declare.h"
23
24PXR_NAMESPACE_OPEN_SCOPE
25
26// If additional types are added here, it's also worth trying to add a mapping
27// to the equivalent Sdf type in the implementation file.
28#define SDR_PROPERTY_TYPE_TOKENS \
29 ((Int, "int")) \
30 ((String, "string")) \
31 ((Float, "float")) \
32 ((Color, "color")) \
33 ((Color4, "color4")) \
34 ((Point, "point")) \
35 ((Normal, "normal")) \
36 ((Vector, "vector")) \
37 ((Matrix, "matrix")) \
38 ((Struct, "struct")) \
39 ((Terminal, "terminal")) \
40 ((Vstruct, "vstruct")) \
41 ((Unknown, "unknown"))
42
43// Note: Metadata keys that are generated by parsers should start with
44// "__SDR__" to reduce the risk of collision with metadata actually in the
45// shader.
46#define SDR_PROPERTY_METADATA_TOKENS \
47 ((Label, "label")) \
48 ((Help, "help")) \
49 ((Page, "page")) \
50 ((RenderType, "renderType")) \
51 ((Role, "role")) \
52 ((Widget, "widget")) \
53 ((Hints, "hints")) \
54 ((Options, "options")) \
55 ((IsDynamicArray, "isDynamicArray")) \
56 ((TupleSize, "tupleSize")) \
57 ((Connectable, "connectable")) \
58 ((Tag, "tag")) \
59 ((ShownIf, "shownIf")) \
60 ((ValidConnectionTypes, "validConnectionTypes")) \
61 ((VstructMemberOf, "vstructMemberOf")) \
62 ((VstructMemberName, "vstructMemberName")) \
63 ((VstructConditionalExpr, "vstructConditionalExpr"))\
64 ((IsAssetIdentifier, "__SDR__isAssetIdentifier"))\
65 ((ImplementationName, "__SDR__implementationName"))\
66 ((SdrUsdDefinitionType, "sdrUsdDefinitionType"))\
67 ((DefaultInput, "__SDR__defaultinput")) \
68 ((Target, "__SDR__target")) \
69 ((Colorspace, "__SDR__colorspace"))
70
71
72// The following tokens are valid values for the metadata "role"
73#define SDR_PROPERTY_ROLE_TOKENS \
74 ((None, "none"))
75
76#define SDR_PROPERTY_TOKENS \
77 ((PageDelimiter, ":"))
78
79TF_DECLARE_PUBLIC_TOKENS(SdrPropertyTypes, SDR_API, SDR_PROPERTY_TYPE_TOKENS);
80TF_DECLARE_PUBLIC_TOKENS(SdrPropertyMetadata, SDR_API,
81 SDR_PROPERTY_METADATA_TOKENS);
82TF_DECLARE_PUBLIC_TOKENS(SdrPropertyRole, SDR_API,
83 SDR_PROPERTY_ROLE_TOKENS);
84TF_DECLARE_PUBLIC_TOKENS(SdrPropertyTokens, SDR_API, SDR_PROPERTY_TOKENS);
85
96{
97public:
98 // Constructor.
99 SDR_API
101 const TfToken& name,
102 const TfToken& type,
103 const VtValue& defaultValue,
104 bool isOutput,
105 size_t arraySize,
106 const SdrTokenMap& metadata,
107 const SdrTokenMap& hints,
108 const SdrOptionVec& options
109 );
110
112 SDR_API
114
117
119 SDR_API
120 const TfToken& GetName() const { return _name; }
121
123 SDR_API
124 const TfToken& GetType() const { return _type; }
125
130 SDR_API
131 const VtValue& GetDefaultValue() const { return _defaultValue; }
132
134 SDR_API
135 bool IsOutput() const { return _isOutput; }
136
138 SDR_API
139 bool IsArray() const { return (_arraySize > 0) || _isDynamicArray; }
140
142 SDR_API
143 bool IsDynamicArray() const { return _isDynamicArray; };
144
153 SDR_API
154 int GetArraySize() const { return _arraySize; }
155
165 SDR_API
166 int GetTupleSize() const { return _tupleSize; }
167
170 SDR_API
171 std::string GetInfoString() const;
172
174
181
183 SDR_API
184 const SdrTokenMap& GetMetadata() const { return _metadata; }
185
189 SDR_API
190 const TfToken& GetLabel() const { return _label; }
191
193 SDR_API
194 std::string GetHelp() const;
195
199 SDR_API
200 const TfToken& GetPage() const { return _page; }
201
205 SDR_API
206 const TfToken& GetWidget() const { return _widget; }
207
210 SDR_API
211 const SdrTokenMap& GetHints() const { return _hints; }
212
216 SDR_API
217 const SdrOptionVec& GetOptions() const { return _options; }
218
226 SDR_API
227 std::string GetImplementationName() const;
228
237 SDR_API
238 std::string GetShownIf() const;
239
241
242
245
247 SDR_API
249 return _vstructMemberOf;
250 }
251
253 SDR_API
255 return _vstructMemberName;
256 }
257
259 SDR_API
260 bool IsVStructMember() const;
261
263 SDR_API
264 bool IsVStruct() const;
265
266
268 SDR_API
270 return _vstructConditionalExpr;
271 }
272
274
275
278
282 SDR_API
283 bool IsConnectable() const { return _isConnectable; }
284
289 SDR_API
290 const SdrTokenVec& GetValidConnectionTypes() const {
291 return _validConnectionTypes;
292 }
293
295 SDR_API
296 bool CanConnectTo(const SdrShaderProperty& other) const;
297
299
300
303
316 SDR_API
318
326 SDR_API
328 return _sdfTypeDefaultValue;
329 }
330
337 SDR_API
338 bool IsAssetIdentifier() const;
339
342 SDR_API
343 bool IsDefaultInput() const;
344
346
347protected:
348 SdrShaderProperty& operator=(const SdrShaderProperty&) = delete;
349
350 // Allow the shader's post process function to access the property's
351 // internals. Some property information can only be determined after parse
352 // time.
353 friend void SdrShaderNode::_PostProcessProperties();
354
355 // Set the USD encoding version to something other than the default.
356 // This can be set in SdrShaderNode::_PostProcessProperties for all the
357 // properties on a shader node.
358 void _SetUsdEncodingVersion(int usdEncodingVersion);
359
360 // Convert this property to a VStruct, which has a special type and a
361 // different default value
362 void _ConvertToVStruct();
363
364 // If a shownIf expression is not provided, attempt to synthesize one from
365 // other conditional visibility metadata.
366 void _ConvertExpressions(const SdrShaderPropertyUniquePtrVec& properties,
367 SdrShaderNodeConstPtr shader);
368
369 // This function is called by SdrShaderNode::_PostProcessProperties once all
370 // information is locked in and won't be changed anymore. This allows each
371 // property to take some extra steps once all information is available.
372 void _FinalizeProperty();
373
374 TfToken _name;
375 TfToken _type;
376 VtValue _defaultValue;
377 bool _isOutput;
378 size_t _arraySize;
379 size_t _tupleSize;
380 bool _isDynamicArray;
381 bool _isConnectable;
382 SdrTokenMap _metadata;
383
384 // Some metadata values cannot be returned by reference from the main
385 // metadata dictionary because they need additional parsing.
386 const SdrTokenMap _hints;
387 const SdrOptionVec _options;
388
389 // Tokenized metadata
390 SdrTokenVec _validConnectionTypes;
391 TfToken _label;
392 TfToken _page;
393 TfToken _widget;
394 TfToken _vstructMemberOf;
395 TfToken _vstructMemberName;
396 TfToken _vstructConditionalExpr;
397
398 VtValue _sdfTypeDefaultValue;
399
400 // Metadatum to control the behavior of GetTypeAsSdfType and indirectly
401 // CanConnectTo
402 int _usdEncodingVersion;
403};
404
405PXR_NAMESPACE_CLOSE_SCOPE
406
407#endif // PXR_USD_SDR_SHADER_PROPERTY_H
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 const SdrTokenMap & GetMetadata() const
All of the metadata that came from the parse process.
SDR_API const VtValue & GetDefaultValueAsSdfType() const
Accessor for default value corresponding to the SdfValueTypeName returned by GetTypeAsSdfType.
SDR_API bool CanConnectTo(const SdrShaderProperty &other) const
Determines if this property can be connected to the specified property.
SDR_API bool IsOutput() const
Whether this property is an output.
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 const VtValue & GetDefaultValue() const
Gets this property's default value associated with the type of the property.
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 int GetArraySize() const
Gets this property's array size.
SDR_API const TfToken & GetType() const
Gets the type of the property.
SDR_API const TfToken & GetVStructMemberName() const
If this field is part of a vstruct, this is its name in the struct.
SDR_API const SdrTokenMap & GetHints() const
Any UI "hints" that are associated with this property.
SDR_API bool IsDynamicArray() const
Whether this property's array type is dynamically-sized.
SDR_API int GetTupleSize() const
Gets this property's tuple size.
SDR_API std::string GetHelp() const
The help message assigned to this property, if any.
SDR_API std::string GetShownIf() const
A boolean expression (SdfBooleanExpression) that determines if the property should be shown in the UI...
SDR_API SdrSdfTypeIndicator GetTypeAsSdfType() const
Converts the property's type from GetType() into a SdrSdfTypeIndicator.
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.
virtual SDR_API ~SdrShaderProperty()
Destructor.
SDR_API bool IsArray() const
Whether this property's type is an array type.
SDR_API const TfToken & GetName() const
Gets the name of the property.
SDR_API bool IsDefaultInput() const
Determines if the value held by this property is the default input for this node.
SDR_API bool IsConnectable() const
Whether this property can be connected to other properties.
SDR_API std::string GetInfoString() const
Gets a string with basic information about this property.
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:152
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
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...