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"
14#include "pxr/usd/sdr/api.h"
16#include "pxr/base/tf/token.h"
18#include "pxr/base/vt/value.h"
21
22PXR_NAMESPACE_OPEN_SCOPE
23
24// If additional types are added here, it's also worth trying to add a mapping
25// to the equivalent Sdf type in the implementation file.
26#define SDR_PROPERTY_TYPE_TOKENS \
27 ((Int, "int")) \
28 ((String, "string")) \
29 ((Float, "float")) \
30 ((Color, "color")) \
31 ((Color4, "color4")) \
32 ((Point, "point")) \
33 ((Normal, "normal")) \
34 ((Vector, "vector")) \
35 ((Matrix, "matrix")) \
36 ((Struct, "struct")) \
37 ((Terminal, "terminal")) \
38 ((Vstruct, "vstruct")) \
39 ((Unknown, "unknown"))
40
41// Note: Metadata keys that are generated by parsers should start with
42// "__SDR__" to reduce the risk of collision with metadata actually in the
43// shader.
44#define SDR_PROPERTY_METADATA_TOKENS \
45 ((Label, "label")) \
46 ((Help, "help")) \
47 ((Page, "page")) \
48 ((RenderType, "renderType")) \
49 ((Role, "role")) \
50 ((Widget, "widget")) \
51 ((Hints, "hints")) \
52 ((Options, "options")) \
53 ((IsDynamicArray, "isDynamicArray")) \
54 ((Connectable, "connectable")) \
55 ((Tag, "tag")) \
56 ((ValidConnectionTypes, "validConnectionTypes")) \
57 ((VstructMemberOf, "vstructMemberOf")) \
58 ((VstructMemberName, "vstructMemberName")) \
59 ((VstructConditionalExpr, "vstructConditionalExpr"))\
60 ((IsAssetIdentifier, "__SDR__isAssetIdentifier"))\
61 ((ImplementationName, "__SDR__implementationName"))\
62 ((SdrUsdDefinitionType, "sdrUsdDefinitionType"))\
63 ((DefaultInput, "__SDR__defaultinput")) \
64 ((Target, "__SDR__target")) \
65 ((Colorspace, "__SDR__colorspace"))
66
67
68// The following tokens are valid values for the metadata "role"
69#define SDR_PROPERTY_ROLE_TOKENS \
70 ((None, "none"))
71
72#define SDR_PROPERTY_TOKENS \
73 ((PageDelimiter, ":"))
74
75TF_DECLARE_PUBLIC_TOKENS(SdrPropertyTypes, SDR_API, SDR_PROPERTY_TYPE_TOKENS);
76TF_DECLARE_PUBLIC_TOKENS(SdrPropertyMetadata, SDR_API,
77 SDR_PROPERTY_METADATA_TOKENS);
78TF_DECLARE_PUBLIC_TOKENS(SdrPropertyRole, SDR_API,
79 SDR_PROPERTY_ROLE_TOKENS);
80TF_DECLARE_PUBLIC_TOKENS(SdrPropertyTokens, SDR_API, SDR_PROPERTY_TOKENS);
81
87{
88public:
89 // Constructor.
90 SDR_API
92 const TfToken& name,
93 const TfToken& type,
94 const VtValue& defaultValue,
95 bool isOutput,
96 size_t arraySize,
97 const NdrTokenMap& metadata,
98 const NdrTokenMap& hints,
99 const NdrOptionVec& options
100 );
101
108
112 SDR_API
113 const TfToken& GetLabel() const { return _label; }
114
116 SDR_API
117 std::string GetHelp() const;
118
122 SDR_API
123 const TfToken& GetPage() const { return _page; }
124
128 SDR_API
129 const TfToken& GetWidget() const { return _widget; }
130
133 SDR_API
134 const NdrTokenMap& GetHints() const { return _hints; }
135
139 SDR_API
140 const NdrOptionVec& GetOptions() const { return _options; }
141
149 SDR_API
150 std::string GetImplementationName() const;
151
153
154
157
159 SDR_API
161 return _vstructMemberOf;
162 }
163
165 SDR_API
167 return _vstructMemberName;
168 }
169
171 SDR_API
172 bool IsVStructMember() const;
173
175 SDR_API
176 bool IsVStruct() const;
177
178
180 SDR_API
182 return _vstructConditionalExpr;
183 }
184
186
187
190
194 SDR_API
195 bool IsConnectable() const override { return _isConnectable; }
196
201 SDR_API
202 const NdrTokenVec& GetValidConnectionTypes() const {
203 return _validConnectionTypes;
204 }
205
207 SDR_API
208 bool CanConnectTo(const NdrProperty& other) const override;
209
211
212
215
226 SDR_API
227 const NdrSdfTypeIndicator GetTypeAsSdfType() const override;
228
236 SDR_API
237 const VtValue& GetDefaultValueAsSdfType() const override {
238 return _sdfTypeDefaultValue;
239 }
240
247 SDR_API
248 bool IsAssetIdentifier() const;
249
252 SDR_API
253 bool IsDefaultInput() const;
254
256
257protected:
258 SdrShaderProperty& operator=(const SdrShaderProperty&) = delete;
259
260 // Allow the shader's post process function to access the property's
261 // internals. Some property information can only be determined after parse
262 // time.
263 friend void SdrShaderNode::_PostProcessProperties();
264
265 // Set the USD encoding version to something other than the default.
266 // This can be set in SdrShaderNode::_PostProcessProperties for all the
267 // properties on a shader node.
268 void _SetUsdEncodingVersion(int usdEncodingVersion);
269
270 // Convert this property to a VStruct, which has a special type and a
271 // different default value
272 void _ConvertToVStruct();
273
274 // This function is called by SdrShaderNode::_PostProcessProperties once all
275 // information is locked in and won't be changed anymore. This allows each
276 // property to take some extra steps once all information is available.
277 void _FinalizeProperty();
278
279 // Some metadata values cannot be returned by reference from the main
280 // metadata dictionary because they need additional parsing.
281 const NdrTokenMap _hints;
282 const NdrOptionVec _options;
283
284 // Tokenized metadata
285 NdrTokenVec _validConnectionTypes;
286 TfToken _label;
287 TfToken _page;
288 TfToken _widget;
289 TfToken _vstructMemberOf;
290 TfToken _vstructMemberName;
291 TfToken _vstructConditionalExpr;
292
293 VtValue _sdfTypeDefaultValue;
294
295 // Metadatum to control the behavior of GetTypeAsSdfType and indirectly
296 // CanConnectTo
297 int _usdEncodingVersion;
298};
299
300PXR_NAMESPACE_CLOSE_SCOPE
301
302#endif // PXR_USD_SDR_SHADER_PROPERTY_H
Represents a property (input or output) that is part of a NdrNode instance.
Definition: property.h:34
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 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 NdrSdfTypeIndicator GetTypeAsSdfType() const override
Converts the property's type from GetType() into a SdfValueTypeName.
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...