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#include "pxr/usd/sdr/shaderPropertyMetadata.h"
24
25PXR_NAMESPACE_OPEN_SCOPE
26
27// If additional types are added here, it's also worth trying to add a mapping
28// to the equivalent Sdf type in the implementation file.
29#define SDR_PROPERTY_TYPE_TOKENS \
30 ((Int, "int")) \
31 ((String, "string")) \
32 ((Float, "float")) \
33 ((Color, "color")) \
34 ((Color4, "color4")) \
35 ((Point, "point")) \
36 ((Normal, "normal")) \
37 ((Vector, "vector")) \
38 ((Matrix, "matrix")) \
39 ((Struct, "struct")) \
40 ((Terminal, "terminal")) \
41 ((Vstruct, "vstruct")) \
42 ((Unknown, "unknown"))
43
44TF_DECLARE_PUBLIC_TOKENS(SdrPropertyTypes, SDR_API, SDR_PROPERTY_TYPE_TOKENS);
57{
58public:
68 SDR_API
70 const TfToken& name,
71 const TfToken& type,
72 const VtValue& defaultValue,
73 bool isOutput,
74 size_t arraySize,
75 const SdrShaderPropertyMetadata& metadata,
76 const SdrTokenMap& hints,
77 const SdrOptionVec& options
78 );
79
81 SDR_API
83
86
88 SDR_API
89 const TfToken& GetName() const { return _name; }
90
92 SDR_API
93 const TfToken& GetType() const { return _type; }
94
99 SDR_API
100 const VtValue& GetDefaultValue() const { return _defaultValue; }
101
103 SDR_API
104 bool IsOutput() const { return _isOutput; }
105
107 SDR_API
108 bool IsArray() const { return (_arraySize > 0) || _isDynamicArray; }
109
111 SDR_API
112 bool IsDynamicArray() const { return _isDynamicArray; };
113
122 SDR_API
123 int GetArraySize() const { return _arraySize; }
124
134 SDR_API
135 int GetTupleSize() const { return _tupleSize; }
136
139 SDR_API
140 std::string GetInfoString() const;
141
143
150
160 const SdrTokenMap& GetMetadata() const { return _legacyMetadata; }
161
164 return _metadata;
165 }
166
170 SDR_API
171 const TfToken& GetLabel() const { return _label; }
172
174 SDR_API
175 std::string GetHelp() const;
176
180 SDR_API
181 const TfToken& GetPage() const { return _page; }
182
186 SDR_API
187 const TfToken& GetWidget() const { return _widget; }
188
191 SDR_API
192 const SdrTokenMap& GetHints() const { return _hints; }
193
197 SDR_API
198 const SdrOptionVec& GetOptions() const { return _options; }
199
207 SDR_API
208 std::string GetImplementationName() const;
209
218 SDR_API
219 std::string GetShownIf() const;
220
222
223
226
228 SDR_API
230 return _vstructMemberOf;
231 }
232
234 SDR_API
236 return _vstructMemberName;
237 }
238
240 SDR_API
241 bool IsVStructMember() const;
242
244 SDR_API
245 bool IsVStruct() const;
246
247
249 SDR_API
251 return _vstructConditionalExpr;
252 }
253
255
256
259
267 SDR_API
268 bool IsConnectable() const { return _isConnectable; }
269
274 SDR_API
275 const SdrTokenVec& GetValidConnectionTypes() const {
276 return _validConnectionTypes;
277 }
278
280 SDR_API
281 bool CanConnectTo(const SdrShaderProperty& other) const;
282
284
285
288
301 SDR_API
303
311 SDR_API
313 return _sdfTypeDefaultValue;
314 }
315
322 SDR_API
323 bool IsAssetIdentifier() const;
324
327 SDR_API
328 bool IsDefaultInput() const;
329
331
332protected:
333 SdrShaderProperty& operator=(const SdrShaderProperty&) = delete;
334
335 // Allow the shader's post process function to access the property's
336 // internals. Some property information can only be determined after parse
337 // time.
338 friend void SdrShaderNode::_PostProcessProperties();
339
340 // Set the USD encoding version to something other than the default.
341 // This can be set in SdrShaderNode::_PostProcessProperties for all the
342 // properties on a shader node.
343 void _SetUsdEncodingVersion(int usdEncodingVersion);
344
345 // Convert this property to a VStruct, which has a special type and a
346 // different default value
347 void _ConvertToVStruct();
348
349 // If a shownIf expression is not provided, attempt to synthesize one from
350 // other conditional visibility metadata.
351 void _ConvertExpressions(const SdrShaderPropertyUniquePtrVec& properties,
352 SdrShaderNodeConstPtr shader);
353
354 // This function is called by SdrShaderNode::_PostProcessProperties once all
355 // information is locked in and won't be changed anymore. This allows each
356 // property to take some extra steps once all information is available.
357 void _FinalizeProperty();
358
359 TfToken _name;
360 TfToken _type;
361 VtValue _defaultValue;
362 bool _isOutput;
363 size_t _arraySize;
364 size_t _tupleSize;
365 bool _isDynamicArray;
366 bool _isConnectable;
367 SdrTokenMap _legacyMetadata;
369
370 // Some metadata values cannot be returned by reference from the main
371 // metadata dictionary because they need additional parsing.
372 const SdrTokenMap _hints;
373 const SdrOptionVec _options;
374
375 // Tokenized metadata
376 SdrTokenVec _validConnectionTypes;
377 TfToken _label;
378 TfToken _page;
379 TfToken _widget;
380 TfToken _vstructMemberOf;
381 TfToken _vstructMemberName;
382 TfToken _vstructConditionalExpr;
383
384 VtValue _sdfTypeDefaultValue;
385
386 // Metadatum to control the behavior of GetTypeAsSdfType and indirectly
387 // CanConnectTo
388 int _usdEncodingVersion;
389};
390
391PXR_NAMESPACE_CLOSE_SCOPE
392
393#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 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 SdrShaderProperty(const TfToken &name, const TfToken &type, const VtValue &defaultValue, bool isOutput, size_t arraySize, const SdrShaderPropertyMetadata &metadata, const SdrTokenMap &hints, const SdrOptionVec &options)
Constructor.
const SdrShaderPropertyMetadata & GetMetadataObject() const
All of the metadata that came from the parse process.
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.
const SdrTokenMap & GetMetadata() const
All of the metadata that came from the parse process.
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.
SdrShaderPropertyMetadata contains generic and named metadata for SdrShaderProperty.
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:90
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...