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  ((Point, "point")) \
49  ((Normal, "normal")) \
50  ((Vector, "vector")) \
51  ((Matrix, "matrix")) \
52  ((Struct, "struct")) \
53  ((Terminal, "terminal")) \
54  ((Vstruct, "vstruct")) \
55  ((Unknown, "unknown"))
56 
57 // Note: Metadata keys that are generated by parsers should start with
58 // "__SDR__" to reduce the risk of collision with metadata actually in the
59 // shader.
60 #define SDR_PROPERTY_METADATA_TOKENS \
61  ((Label, "label")) \
62  ((Help, "help")) \
63  ((Page, "page")) \
64  ((RenderType, "renderType")) \
65  ((Role, "role")) \
66  ((Widget, "widget")) \
67  ((Hints, "hints")) \
68  ((Options, "options")) \
69  ((IsDynamicArray, "isDynamicArray")) \
70  ((Connectable, "connectable")) \
71  ((ValidConnectionTypes, "validConnectionTypes")) \
72  ((VstructMemberOf, "vstructMemberOf")) \
73  ((VstructMemberName, "vstructMemberName")) \
74  ((VstructConditionalExpr, "vstructConditionalExpr"))\
75  ((IsAssetIdentifier, "__SDR__isAssetIdentifier"))\
76  ((ImplementationName, "__SDR__implementationName"))\
77  ((SdrUsdDefinitionType, "sdrUsdDefinitionType"))\
78  ((DefaultInput, "__SDR__defaultinput")) \
79  ((Target, "__SDR__target")) \
80  ((Colorspace, "__SDR__colorspace"))
81 
82 
83 // The following tokens are valid values for the metadata "role"
84 #define SDR_PROPERTY_ROLE_TOKENS \
85  ((None, "none"))
86 
87 #define SDR_PROPERTY_TOKENS \
88  ((PageDelimiter, ":"))
89 
90 TF_DECLARE_PUBLIC_TOKENS(SdrPropertyTypes, SDR_API, SDR_PROPERTY_TYPE_TOKENS);
91 TF_DECLARE_PUBLIC_TOKENS(SdrPropertyMetadata, SDR_API,
92  SDR_PROPERTY_METADATA_TOKENS);
93 TF_DECLARE_PUBLIC_TOKENS(SdrPropertyRole, SDR_API,
94  SDR_PROPERTY_ROLE_TOKENS);
95 TF_DECLARE_PUBLIC_TOKENS(SdrPropertyTokens, SDR_API, SDR_PROPERTY_TOKENS);
96 
102 {
103 public:
104  // Constructor.
105  SDR_API
107  const TfToken& name,
108  const TfToken& type,
109  const VtValue& defaultValue,
110  bool isOutput,
111  size_t arraySize,
112  const NdrTokenMap& metadata,
113  const NdrTokenMap& hints,
114  const NdrOptionVec& options
115  );
116 
123 
127  SDR_API
128  const TfToken& GetLabel() const { return _label; }
129 
131  SDR_API
132  std::string GetHelp() const;
133 
137  SDR_API
138  const TfToken& GetPage() const { return _page; }
139 
143  SDR_API
144  const TfToken& GetWidget() const { return _widget; }
145 
148  SDR_API
149  const NdrTokenMap& GetHints() const { return _hints; }
150 
154  SDR_API
155  const NdrOptionVec& GetOptions() const { return _options; }
156 
164  SDR_API
165  std::string GetImplementationName() const;
166 
168 
169 
172 
174  SDR_API
175  const TfToken& GetVStructMemberOf() const {
176  return _vstructMemberOf;
177  }
178 
180  SDR_API
181  const TfToken& GetVStructMemberName() const {
182  return _vstructMemberName;
183  }
184 
186  SDR_API
187  bool IsVStructMember() const;
188 
190  SDR_API
191  bool IsVStruct() const;
192 
193 
195  SDR_API
197  return _vstructConditionalExpr;
198  }
199 
201 
202 
205 
209  SDR_API
210  bool IsConnectable() const override { return _isConnectable; }
211 
216  SDR_API
217  const NdrTokenVec& GetValidConnectionTypes() const {
218  return _validConnectionTypes;
219  }
220 
222  SDR_API
223  bool CanConnectTo(const NdrProperty& other) const override;
224 
226 
227 
230 
241  SDR_API
242  const NdrSdfTypeIndicator GetTypeAsSdfType() const override;
243 
251  SDR_API
252  const VtValue& GetDefaultValueAsSdfType() const override {
253  return _sdfTypeDefaultValue;
254  }
255 
262  SDR_API
263  bool IsAssetIdentifier() const;
264 
267  SDR_API
268  bool IsDefaultInput() const;
269 
271 
272 protected:
273  SdrShaderProperty& operator=(const SdrShaderProperty&) = delete;
274 
275  // Allow the shader's post process function to access the property's
276  // internals. Some property information can only be determined after parse
277  // time.
278  friend void SdrShaderNode::_PostProcessProperties();
279 
280  // Set the USD encoding version to something other than the default.
281  // This can be set in SdrShaderNode::_PostProcessProperties for all the
282  // properties on a shader node.
283  void _SetUsdEncodingVersion(int usdEncodingVersion);
284 
285  // Convert this property to a VStruct, which has a special type and a
286  // different default value
287  void _ConvertToVStruct();
288 
289  // This function is called by SdrShaderNode::_PostProcessProperties once all
290  // information is locked in and won't be changed anymore. This allows each
291  // property to take some extra steps once all information is available.
292  void _FinalizeProperty();
293 
294  // Some metadata values cannot be returned by reference from the main
295  // metadata dictionary because they need additional parsing.
296  const NdrTokenMap _hints;
297  const NdrOptionVec _options;
298 
299  // Tokenized metadata
300  NdrTokenVec _validConnectionTypes;
301  TfToken _label;
302  TfToken _page;
303  TfToken _widget;
304  TfToken _vstructMemberOf;
305  TfToken _vstructMemberName;
306  TfToken _vstructConditionalExpr;
307 
308  VtValue _sdfTypeDefaultValue;
309 
310  // Metadatum to control the behavior of GetTypeAsSdfType and indirectly
311  // CanConnectTo
312  int _usdEncodingVersion;
313 };
314 
315 PXR_NAMESPACE_CLOSE_SCOPE
316 
317 #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.