shaderProperty.h
Go to the documentation of this file.
1 //
2 // Copyright 2018 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 
25 #ifndef PXR_USD_SDR_SHADER_PROPERTY_H
26 #define PXR_USD_SDR_SHADER_PROPERTY_H
27 
29 
30 #include "pxr/pxr.h"
31 #include "pxr/usd/sdr/api.h"
33 #include "pxr/base/tf/token.h"
34 #include "pxr/base/tf/weakBase.h"
35 #include "pxr/base/vt/value.h"
36 #include "pxr/usd/ndr/property.h"
37 #include "pxr/usd/sdr/shaderNode.h"
38 
39 PXR_NAMESPACE_OPEN_SCOPE
40 
41 // If additional types are added here, it's also worth trying to add a mapping
42 // to the equivalent Sdf type in the implementation file.
43 #define SDR_PROPERTY_TYPE_TOKENS \
44  ((Int, "int")) \
45  ((String, "string")) \
46  ((Float, "float")) \
47  ((Color, "color")) \
48  ((Color4, "color4")) \
49  ((Point, "point")) \
50  ((Normal, "normal")) \
51  ((Vector, "vector")) \
52  ((Matrix, "matrix")) \
53  ((Struct, "struct")) \
54  ((Terminal, "terminal")) \
55  ((Vstruct, "vstruct")) \
56  ((Unknown, "unknown"))
57 
58 // Note: Metadata keys that are generated by parsers should start with
59 // "__SDR__" to reduce the risk of collision with metadata actually in the
60 // shader.
61 #define SDR_PROPERTY_METADATA_TOKENS \
62  ((Label, "label")) \
63  ((Help, "help")) \
64  ((Page, "page")) \
65  ((RenderType, "renderType")) \
66  ((Role, "role")) \
67  ((Widget, "widget")) \
68  ((Hints, "hints")) \
69  ((Options, "options")) \
70  ((IsDynamicArray, "isDynamicArray")) \
71  ((Connectable, "connectable")) \
72  ((Tag, "tag")) \
73  ((ValidConnectionTypes, "validConnectionTypes")) \
74  ((VstructMemberOf, "vstructMemberOf")) \
75  ((VstructMemberName, "vstructMemberName")) \
76  ((VstructConditionalExpr, "vstructConditionalExpr"))\
77  ((IsAssetIdentifier, "__SDR__isAssetIdentifier"))\
78  ((ImplementationName, "__SDR__implementationName"))\
79  ((SdrUsdDefinitionType, "sdrUsdDefinitionType"))\
80  ((DefaultInput, "__SDR__defaultinput")) \
81  ((Target, "__SDR__target")) \
82  ((Colorspace, "__SDR__colorspace"))
83 
84 
85 // The following tokens are valid values for the metadata "role"
86 #define SDR_PROPERTY_ROLE_TOKENS \
87  ((None, "none"))
88 
89 #define SDR_PROPERTY_TOKENS \
90  ((PageDelimiter, ":"))
91 
92 TF_DECLARE_PUBLIC_TOKENS(SdrPropertyTypes, SDR_API, SDR_PROPERTY_TYPE_TOKENS);
93 TF_DECLARE_PUBLIC_TOKENS(SdrPropertyMetadata, SDR_API,
94  SDR_PROPERTY_METADATA_TOKENS);
95 TF_DECLARE_PUBLIC_TOKENS(SdrPropertyRole, SDR_API,
96  SDR_PROPERTY_ROLE_TOKENS);
97 TF_DECLARE_PUBLIC_TOKENS(SdrPropertyTokens, SDR_API, SDR_PROPERTY_TOKENS);
98 
104 {
105 public:
106  // Constructor.
107  SDR_API
109  const TfToken& name,
110  const TfToken& type,
111  const VtValue& defaultValue,
112  bool isOutput,
113  size_t arraySize,
114  const NdrTokenMap& metadata,
115  const NdrTokenMap& hints,
116  const NdrOptionVec& options
117  );
118 
125 
129  SDR_API
130  const TfToken& GetLabel() const { return _label; }
131 
133  SDR_API
134  std::string GetHelp() const;
135 
139  SDR_API
140  const TfToken& GetPage() const { return _page; }
141 
145  SDR_API
146  const TfToken& GetWidget() const { return _widget; }
147 
150  SDR_API
151  const NdrTokenMap& GetHints() const { return _hints; }
152 
156  SDR_API
157  const NdrOptionVec& GetOptions() const { return _options; }
158 
166  SDR_API
167  std::string GetImplementationName() const;
168 
170 
171 
174 
176  SDR_API
177  const TfToken& GetVStructMemberOf() const {
178  return _vstructMemberOf;
179  }
180 
182  SDR_API
183  const TfToken& GetVStructMemberName() const {
184  return _vstructMemberName;
185  }
186 
188  SDR_API
189  bool IsVStructMember() const;
190 
192  SDR_API
193  bool IsVStruct() const;
194 
195 
197  SDR_API
199  return _vstructConditionalExpr;
200  }
201 
203 
204 
207 
211  SDR_API
212  bool IsConnectable() const override { return _isConnectable; }
213 
218  SDR_API
219  const NdrTokenVec& GetValidConnectionTypes() const {
220  return _validConnectionTypes;
221  }
222 
224  SDR_API
225  bool CanConnectTo(const NdrProperty& other) const override;
226 
228 
229 
232 
243  SDR_API
244  const NdrSdfTypeIndicator GetTypeAsSdfType() const override;
245 
253  SDR_API
254  const VtValue& GetDefaultValueAsSdfType() const override {
255  return _sdfTypeDefaultValue;
256  }
257 
264  SDR_API
265  bool IsAssetIdentifier() const;
266 
269  SDR_API
270  bool IsDefaultInput() const;
271 
273 
274 protected:
275  SdrShaderProperty& operator=(const SdrShaderProperty&) = delete;
276 
277  // Allow the shader's post process function to access the property's
278  // internals. Some property information can only be determined after parse
279  // time.
280  friend void SdrShaderNode::_PostProcessProperties();
281 
282  // Set the USD encoding version to something other than the default.
283  // This can be set in SdrShaderNode::_PostProcessProperties for all the
284  // properties on a shader node.
285  void _SetUsdEncodingVersion(int usdEncodingVersion);
286 
287  // Convert this property to a VStruct, which has a special type and a
288  // different default value
289  void _ConvertToVStruct();
290 
291  // This function is called by SdrShaderNode::_PostProcessProperties once all
292  // information is locked in and won't be changed anymore. This allows each
293  // property to take some extra steps once all information is available.
294  void _FinalizeProperty();
295 
296  // Some metadata values cannot be returned by reference from the main
297  // metadata dictionary because they need additional parsing.
298  const NdrTokenMap _hints;
299  const NdrOptionVec _options;
300 
301  // Tokenized metadata
302  NdrTokenVec _validConnectionTypes;
303  TfToken _label;
304  TfToken _page;
305  TfToken _widget;
306  TfToken _vstructMemberOf;
307  TfToken _vstructMemberName;
308  TfToken _vstructConditionalExpr;
309 
310  VtValue _sdfTypeDefaultValue;
311 
312  // Metadatum to control the behavior of GetTypeAsSdfType and indirectly
313  // CanConnectTo
314  int _usdEncodingVersion;
315 };
316 
317 PXR_NAMESPACE_CLOSE_SCOPE
318 
319 #endif // PXR_USD_SDR_SHADER_PROPERTY_H
SDR_API const NdrTokenVec & GetValidConnectionTypes() const
Gets the list of valid connection types for this property.
SDR_API const TfToken & GetVStructMemberOf() const
If this field is part of a vstruct, this is the name of the struct.
SDR_API bool IsVStructMember() const
Returns true if this field is part of a vstruct.
SDR_API bool IsVStruct() const
Returns true if the field is the head of a vstruct.
SDR_API const TfToken & GetLabel() const
The label assigned to this property, if any.
SDR_API std::string GetHelp() const
The help message assigned to this property, if any.
A specialized version of NdrProperty which holds shading information.
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 TfToken & GetPage() const
The page (group), eg "Advanced", this property appears on, 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 bool CanConnectTo(const NdrProperty &other) const override
Determines if this property can be connected to the specified property.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
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.
Represents a property (input or output) that is part of a NdrNode instance.
Definition: property.h:50
SDR_API const NdrSdfTypeIndicator GetTypeAsSdfType() const override
Converts the property's type from GetType() into a SdfValueTypeName.
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:118
SDR_API bool IsAssetIdentifier() const
Determines if the value held by this property is an asset identifier (eg, a file path); the logic for...
This file defines some macros that are useful for declaring and using static TfTokens.
SDR_API bool IsDefaultInput() const
Determines if the value held by this property is the default input for this node.
SDR_API const VtValue & GetDefaultValueAsSdfType() const override
Accessor for default value corresponding to the SdfValueTypeName returned by GetTypeAsSdfType.
SDR_API bool IsConnectable() const override
Whether this property can be connected to other properties.
SDR_API std::string GetImplementationName() const
Returns the implementation name of this property.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:166
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
SDR_API const TfToken & GetVStructMemberName() const
If this field is part of a vstruct, this is its name in the struct.