HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
lightFilter.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef USDLUX_GENERATED_LIGHTFILTER_H
8 #define USDLUX_GENERATED_LIGHTFILTER_H
9 
10 /// \file usdLux/lightFilter.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/usdLux/api.h"
15 #include "pxr/usd/usd/prim.h"
16 #include "pxr/usd/usd/stage.h"
17 #include "pxr/usd/usdLux/tokens.h"
18 
20 #include "pxr/usd/usdShade/input.h"
21 #include "pxr/usd/usdShade/output.h"
22 
23 #include "pxr/base/vt/value.h"
24 
25 #include "pxr/base/gf/vec3d.h"
26 #include "pxr/base/gf/vec3f.h"
27 #include "pxr/base/gf/matrix4d.h"
28 
29 #include "pxr/base/tf/token.h"
30 #include "pxr/base/tf/type.h"
31 
33 
34 class SdfAssetPath;
35 
36 // -------------------------------------------------------------------------- //
37 // LIGHTFILTER //
38 // -------------------------------------------------------------------------- //
39 
40 /// \class UsdLuxLightFilter
41 ///
42 /// A light filter modifies the effect of a light.
43 /// Lights refer to filters via relationships so that filters may be
44 /// shared.
45 ///
46 /// <b>Linking</b>
47 ///
48 /// Filters can be linked to geometry. Linking controls which geometry
49 /// a light-filter affects, when considering the light filters attached
50 /// to a light illuminating the geometry.
51 ///
52 /// Linking is specified as a collection (UsdCollectionAPI) which can
53 /// be accessed via GetFilterLinkCollection().
54 ///
55 /// <b>Encapsulation</b>
56 ///
57 /// UsdLuxLightFilter must not be parented under a UsdShadeMaterial.
58 /// See \ref usdLux_Encapsulation for more details.
59 ///
60 ///
61 /// For any described attribute \em Fallback \em Value or \em Allowed \em Values below
62 /// that are text/tokens, the actual token is published and defined in \ref UsdLuxTokens.
63 /// So to set an attribute to the value "rightHanded", use UsdLuxTokens->rightHanded
64 /// as the value.
65 ///
67 {
68 public:
69  /// Compile time constant representing what kind of schema this class is.
70  ///
71  /// \sa UsdSchemaKind
73 
74  /// Construct a UsdLuxLightFilter on UsdPrim \p prim .
75  /// Equivalent to UsdLuxLightFilter::Get(prim.GetStage(), prim.GetPath())
76  /// for a \em valid \p prim, but will not immediately throw an error for
77  /// an invalid \p prim
78  explicit UsdLuxLightFilter(const UsdPrim& prim=UsdPrim())
79  : UsdGeomXformable(prim)
80  {
81  }
82 
83  /// Construct a UsdLuxLightFilter on the prim held by \p schemaObj .
84  /// Should be preferred over UsdLuxLightFilter(schemaObj.GetPrim()),
85  /// as it preserves SchemaBase state.
86  explicit UsdLuxLightFilter(const UsdSchemaBase& schemaObj)
87  : UsdGeomXformable(schemaObj)
88  {
89  }
90 
91  /// Destructor.
93  virtual ~UsdLuxLightFilter();
94 
95  /// Return a vector of names of all pre-declared attributes for this schema
96  /// class and all its ancestor classes. Does not include attributes that
97  /// may be authored by custom/extended methods of the schemas involved.
99  static const TfTokenVector &
100  GetSchemaAttributeNames(bool includeInherited=true);
101 
102  /// Return a UsdLuxLightFilter holding the prim adhering to this
103  /// schema at \p path on \p stage. If no prim exists at \p path on
104  /// \p stage, or if the prim at that path does not adhere to this schema,
105  /// return an invalid schema object. This is shorthand for the following:
106  ///
107  /// \code
108  /// UsdLuxLightFilter(stage->GetPrimAtPath(path));
109  /// \endcode
110  ///
111  USDLUX_API
112  static UsdLuxLightFilter
113  Get(const UsdStagePtr &stage, const SdfPath &path);
114 
115  /// Attempt to ensure a \a UsdPrim adhering to this schema at \p path
116  /// is defined (according to UsdPrim::IsDefined()) on this stage.
117  ///
118  /// If a prim adhering to this schema at \p path is already defined on this
119  /// stage, return that prim. Otherwise author an \a SdfPrimSpec with
120  /// \a specifier == \a SdfSpecifierDef and this schema's prim type name for
121  /// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s
122  /// with \p specifier == \a SdfSpecifierDef and empty typeName at the
123  /// current EditTarget for any nonexistent, or existing but not \a Defined
124  /// ancestors.
125  ///
126  /// The given \a path must be an absolute prim path that does not contain
127  /// any variant selections.
128  ///
129  /// If it is impossible to author any of the necessary PrimSpecs, (for
130  /// example, in case \a path cannot map to the current UsdEditTarget's
131  /// namespace) issue an error and return an invalid \a UsdPrim.
132  ///
133  /// Note that this method may return a defined prim whose typeName does not
134  /// specify this schema class, in case a stronger typeName opinion overrides
135  /// the opinion at the current EditTarget.
136  ///
137  USDLUX_API
138  static UsdLuxLightFilter
139  Define(const UsdStagePtr &stage, const SdfPath &path);
140 
141 protected:
142  /// Returns the kind of schema this class belongs to.
143  ///
144  /// \sa UsdSchemaKind
145  USDLUX_API
146  UsdSchemaKind _GetSchemaKind() const override;
147 
148 private:
149  // needs to invoke _GetStaticTfType.
150  friend class UsdSchemaRegistry;
151  USDLUX_API
152  static const TfType &_GetStaticTfType();
153 
154  static bool _IsTypedSchema();
155 
156  // override SchemaBase virtuals.
157  USDLUX_API
158  const TfType &_GetTfType() const override;
159 
160 public:
161  // --------------------------------------------------------------------- //
162  // SHADERID
163  // --------------------------------------------------------------------- //
164  /// Default ID for the light filter's shader.
165  /// This defines the shader ID for this light filter when a render context
166  /// specific shader ID is not available.
167  ///
168  /// \see GetShaderId
169  /// \see GetShaderIdAttrForRenderContext
170  /// \see SdrRegistry::GetShaderNodeByIdentifier
171  /// \see SdrRegistry::GetShaderNodeByIdentifierAndType
172  ///
173  ///
174  /// | ||
175  /// | -- | -- |
176  /// | Declaration | `uniform token lightFilter:shaderId = ""` |
177  /// | C++ Type | TfToken |
178  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token |
179  /// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
180  USDLUX_API
182 
183  /// See GetShaderIdAttr(), and also
184  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
185  /// If specified, author \p defaultValue as the attribute's default,
186  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
187  /// the default for \p writeSparsely is \c false.
188  USDLUX_API
189  UsdAttribute CreateShaderIdAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
190 
191 public:
192  // ===================================================================== //
193  // Feel free to add custom code below this line, it will be preserved by
194  // the code generator.
195  //
196  // Just remember to:
197  // - Close the class declaration with };
198  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
199  // - Close the include guard with #endif
200  // ===================================================================== //
201  // --(BEGIN CUSTOM CODE)--
202 
203  // -------------------------------------------------------------------------
204  /// \name Conversion to and from UsdShadeConnectableAPI
205  ///
206  /// @{
207 
208  /// Constructor that takes a ConnectableAPI object.
209  /// Allow implicit conversion of UsdShadeConnectableAPI to
210  /// UsdLuxLightFilter.
211  USDLUX_API
212  UsdLuxLightFilter(const UsdShadeConnectableAPI &connectable);
213 
214  /// Contructs and returns a UsdShadeConnectableAPI object with this light
215  /// filter.
216  ///
217  /// Note that most tasks can be accomplished without explicitly constructing
218  /// a UsdShadeConnectable API, since connection-related API such as
219  /// UsdShadeConnectableAPI::ConnectToSource() are static methods, and
220  /// UsdLuxLightFilter will auto-convert to a UsdShadeConnectableAPI when
221  /// passed to functions that want to act generically on a connectable
222  /// UsdShadeConnectableAPI object.
223  USDLUX_API
225 
226  /// @}
227 
228  // -------------------------------------------------------------------------
229  /// \name Outputs API
230  ///
231  /// Outputs represent a typed attribute on a light filter whose value is
232  /// computed externally.
233  ///
234  /// @{
235 
236  /// Create an output which can either have a value or can be connected.
237  /// The attribute representing the output is created in the "outputs:"
238  /// namespace. Outputs on a light filter cannot be connected, as their
239  /// value is assumed to be computed externally.
240  ///
241  USDLUX_API
243  const SdfValueTypeName& typeName);
244 
245  /// Return the requested output if it exists.
246  ///
247  USDLUX_API
248  UsdShadeOutput GetOutput(const TfToken &name) const;
249 
250  /// Outputs are represented by attributes in the "outputs:" namespace.
251  /// If \p onlyAuthored is true (the default), then only return authored
252  /// attributes; otherwise, this also returns un-authored builtins.
253  ///
254  USDLUX_API
255  std::vector<UsdShadeOutput> GetOutputs(bool onlyAuthored=true) const;
256 
257  /// @}
258 
259  // -------------------------------------------------------------------------
260 
261  /// \name Inputs API
262  ///
263  /// Inputs are connectable attribute with a typed value.
264  ///
265  /// Light filter parameters are encoded as inputs.
266  ///
267  /// @{
268 
269  /// Create an input which can either have a value or can be connected.
270  /// The attribute representing the input is created in the "inputs:"
271  /// namespace. Inputs on light filters are connectable.
272  ///
273  USDLUX_API
275  const SdfValueTypeName& typeName);
276 
277  /// Return the requested input if it exists.
278  ///
279  USDLUX_API
280  UsdShadeInput GetInput(const TfToken &name) const;
281 
282  /// Inputs are represented by attributes in the "inputs:" namespace.
283  /// If \p onlyAuthored is true (the default), then only return authored
284  /// attributes; otherwise, this also returns un-authored builtins.
285  ///
286  USDLUX_API
287  std::vector<UsdShadeInput> GetInputs(bool onlyAuthored=true) const;
288 
289  /// @}
290 
291  /// Return the UsdCollectionAPI interface used for examining and
292  /// modifying the filter-linking of this light filter. Linking
293  /// controls which geometry this light filter affects.
294  USDLUX_API
296 
297  /// Returns the shader ID attribute for the given \p renderContext.
298  ///
299  /// If \p renderContext is non-empty, this will try to return an attribute
300  /// named _lightFilter:shaderId_ with the namespace prefix \p renderContext.
301  /// For example, if the passed in render context is "ri" then the attribute
302  /// returned by this function would have the following signature:
303  /// | ||
304  /// | -- | -- |
305  /// | Declaration | `token ri:lightFilter:shaderId` |
306  /// | C++ Type | TfToken |
307  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token |
308  ///
309  /// If the render context is empty, this will return the default shader ID
310  /// attribute as returned by GetShaderIdAttr().
311  USDLUX_API
313  const TfToken &renderContext) const;
314 
315  /// Creates the shader ID attribute for the given \p renderContext.
316  ///
317  /// See GetShaderIdAttrForRenderContext(), and also
318  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
319  /// If specified, author \p defaultValue as the attribute's default,
320  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
321  /// the default for \p writeSparsely is \c false.
322  USDLUX_API
324  const TfToken &renderContext,
325  VtValue const &defaultValue = VtValue(),
326  bool writeSparsely=false) const;
327 
328  /// Return the light filter's shader ID for the given list of available
329  /// \p renderContexts.
330  ///
331  /// The shader ID returned by this function is the identifier to use when
332  /// looking up the shader definition for this light filter in the
333  /// \ref SdrRegistry "shader registry".
334  ///
335  /// The render contexts are expected to be listed in priority order, so
336  /// for each render context provided, this will try to find the shader ID
337  /// attribute specific to that render context (see
338  /// GetShaderIdAttrForRenderContext()) and will return the
339  /// value of the first one found that has a non-empty value. If no shader ID
340  /// value can be found for any of the given render contexts or
341  /// \p renderContexts is empty, then this will return the value of the
342  /// default shader ID attribute (see GetShaderIdAttr()).
343  USDLUX_API
344  TfToken GetShaderId(const TfTokenVector &renderContexts) const;
345 
346 };
347 
349 
350 #endif
USDLUX_API TfToken GetShaderId(const TfTokenVector &renderContexts) const
USDLUX_API UsdShadeOutput CreateOutput(const TfToken &name, const SdfValueTypeName &typeName)
static USDLUX_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
USDLUX_API UsdShadeConnectableAPI ConnectableAPI() const
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
#define USDLUX_API
Definition: api.h:23
static USDLUX_API UsdLuxLightFilter Define(const UsdStagePtr &stage, const SdfPath &path)
Definition: token.h:70
UsdLuxLightFilter(const UsdPrim &prim=UsdPrim())
Definition: lightFilter.h:78
Represents a concrete typed schema.
static const UsdSchemaKind schemaKind
Definition: lightFilter.h:72
USDLUX_API UsdAttribute CreateShaderIdAttrForRenderContext(const TfToken &renderContext, VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
virtual USDLUX_API ~UsdLuxLightFilter()
Destructor.
Definition: prim.h:116
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
GLuint const GLchar * name
Definition: glcorearb.h:786
Definition: path.h:280
USDLUX_API UsdShadeInput CreateInput(const TfToken &name, const SdfValueTypeName &typeName)
UsdSchemaKind
Definition: common.h:112
USDLUX_API UsdCollectionAPI GetFilterLinkCollectionAPI() const
USDLUX_API std::vector< UsdShadeOutput > GetOutputs(bool onlyAuthored=true) const
USDLUX_API UsdShadeInput GetInput(const TfToken &name) const
USDLUX_API UsdAttribute GetShaderIdAttr() const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
USDLUX_API UsdAttribute GetShaderIdAttrForRenderContext(const TfToken &renderContext) const
USDLUX_API UsdSchemaKind _GetSchemaKind() const override
Definition: type.h:47
USDLUX_API UsdShadeOutput GetOutput(const TfToken &name) const
UsdLuxLightFilter(const UsdSchemaBase &schemaObj)
Definition: lightFilter.h:86
USDLUX_API UsdAttribute CreateShaderIdAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
Definition: value.h:89
USDLUX_API std::vector< UsdShadeInput > GetInputs(bool onlyAuthored=true) const
static USDLUX_API UsdLuxLightFilter Get(const UsdStagePtr &stage, const SdfPath &path)