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  ((ValidConnectionTypes, "validConnectionTypes")) \
73  ((VstructMemberOf, "vstructMemberOf")) \
74  ((VstructMemberName, "vstructMemberName")) \
75  ((VstructConditionalExpr, "vstructConditionalExpr"))\
76  ((IsAssetIdentifier, "__SDR__isAssetIdentifier"))\
77  ((ImplementationName, "__SDR__implementationName"))\
78  ((SdrUsdDefinitionType, "sdrUsdDefinitionType"))\
79  ((DefaultInput, "__SDR__defaultinput")) \
80  ((Target, "__SDR__target")) \
81  ((Colorspace, "__SDR__colorspace"))
82 
83 
84 // The following tokens are valid values for the metadata "role"
85 #define SDR_PROPERTY_ROLE_TOKENS \
86  ((None, "none"))
87 
88 #define SDR_PROPERTY_TOKENS \
89  ((PageDelimiter, ":"))
90 
91 TF_DECLARE_PUBLIC_TOKENS(SdrPropertyTypes, SDR_API, SDR_PROPERTY_TYPE_TOKENS);
92 TF_DECLARE_PUBLIC_TOKENS(SdrPropertyMetadata, SDR_API,
93  SDR_PROPERTY_METADATA_TOKENS);
94 TF_DECLARE_PUBLIC_TOKENS(SdrPropertyRole, SDR_API,
95  SDR_PROPERTY_ROLE_TOKENS);
96 TF_DECLARE_PUBLIC_TOKENS(SdrPropertyTokens, SDR_API, SDR_PROPERTY_TOKENS);
97 
103 {
104 public:
105  // Constructor.
106  SDR_API
108  const TfToken& name,
109  const TfToken& type,
110  const VtValue& defaultValue,
111  bool isOutput,
112  size_t arraySize,
113  const NdrTokenMap& metadata,
114  const NdrTokenMap& hints,
115  const NdrOptionVec& options
116  );
117 
124 
128  SDR_API
129  const TfToken& GetLabel() const { return _label; }
130 
132  SDR_API
133  std::string GetHelp() const;
134 
138  SDR_API
139  const TfToken& GetPage() const { return _page; }
140 
144  SDR_API
145  const TfToken& GetWidget() const { return _widget; }
146 
149  SDR_API
150  const NdrTokenMap& GetHints() const { return _hints; }
151 
155  SDR_API
156  const NdrOptionVec& GetOptions() const { return _options; }
157 
165  SDR_API
166  std::string GetImplementationName() const;
167 
169 
170 
173 
175  SDR_API
176  const TfToken& GetVStructMemberOf() const {
177  return _vstructMemberOf;
178  }
179 
181  SDR_API
182  const TfToken& GetVStructMemberName() const {
183  return _vstructMemberName;
184  }
185 
187  SDR_API
188  bool IsVStructMember() const;
189 
191  SDR_API
192  bool IsVStruct() const;
193 
194 
196  SDR_API
198  return _vstructConditionalExpr;
199  }
200 
202 
203 
206 
210  SDR_API
211  bool IsConnectable() const override { return _isConnectable; }
212 
217  SDR_API
218  const NdrTokenVec& GetValidConnectionTypes() const {
219  return _validConnectionTypes;
220  }
221 
223  SDR_API
224  bool CanConnectTo(const NdrProperty& other) const override;
225 
227 
228 
231 
242  SDR_API
243  const NdrSdfTypeIndicator GetTypeAsSdfType() const override;
244 
252  SDR_API
253  const VtValue& GetDefaultValueAsSdfType() const override {
254  return _sdfTypeDefaultValue;
255  }
256 
263  SDR_API
264  bool IsAssetIdentifier() const;
265 
268  SDR_API
269  bool IsDefaultInput() const;
270 
272 
273 protected:
274  SdrShaderProperty& operator=(const SdrShaderProperty&) = delete;
275 
276  // Allow the shader's post process function to access the property's
277  // internals. Some property information can only be determined after parse
278  // time.
279  friend void SdrShaderNode::_PostProcessProperties();
280 
281  // Set the USD encoding version to something other than the default.
282  // This can be set in SdrShaderNode::_PostProcessProperties for all the
283  // properties on a shader node.
284  void _SetUsdEncodingVersion(int usdEncodingVersion);
285 
286  // Convert this property to a VStruct, which has a special type and a
287  // different default value
288  void _ConvertToVStruct();
289 
290  // This function is called by SdrShaderNode::_PostProcessProperties once all
291  // information is locked in and won't be changed anymore. This allows each
292  // property to take some extra steps once all information is available.
293  void _FinalizeProperty();
294 
295  // Some metadata values cannot be returned by reference from the main
296  // metadata dictionary because they need additional parsing.
297  const NdrTokenMap _hints;
298  const NdrOptionVec _options;
299 
300  // Tokenized metadata
301  NdrTokenVec _validConnectionTypes;
302  TfToken _label;
303  TfToken _page;
304  TfToken _widget;
305  TfToken _vstructMemberOf;
306  TfToken _vstructMemberName;
307  TfToken _vstructConditionalExpr;
308 
309  VtValue _sdfTypeDefaultValue;
310 
311  // Metadatum to control the behavior of GetTypeAsSdfType and indirectly
312  // CanConnectTo
313  int _usdEncodingVersion;
314 };
315 
316 PXR_NAMESPACE_CLOSE_SCOPE
317 
318 #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.