HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
material.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 USDSHADE_GENERATED_MATERIAL_H
8 #define USDSHADE_GENERATED_MATERIAL_H
9 
10 /// \file usdShade/material.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/usdShade/api.h"
15 #include "pxr/usd/usd/prim.h"
16 #include "pxr/usd/usd/stage.h"
18 
20 #include "pxr/usd/usdGeom/subset.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 // MATERIAL //
38 // -------------------------------------------------------------------------- //
39 
40 /// \class UsdShadeMaterial
41 ///
42 /// A Material provides a container into which multiple "render contexts"
43 /// can add data that defines a "shading material" for a renderer. Typically
44 /// this consists of one or more UsdShadeOutput properties connected to outputs
45 /// of nested Shader prims - though a context/client is free to add
46 /// any data that is suitable. We <b>strongly advise</b> that all contexts
47 /// adopt the convention that all properties be prefixed with a namespace
48 /// that identifies the context e.g. "token outputs:ri:surface.connect =
49 /// </MyselfMaterial/previewSurface.outputs:surface".
50 ///
51 /// ## Binding Materials
52 ///
53 /// In the UsdShading model, geometry expresses a binding to a single Material or
54 /// to a set of Materials partitioned by UsdGeomSubsets defined beneath the
55 /// geometry; it is legal to bind a Material at the root (or other sub-prim) of
56 /// a model, and then bind a different Material to individual gprims, but the
57 /// meaning of inheritance and "ancestral overriding" of Material bindings is
58 /// left to each render-target to determine. Since UsdGeom has no concept of
59 /// shading, we provide the API for binding and unbinding geometry on the API
60 /// schema UsdShadeMaterialBindingAPI.
61 ///
62 /// ## Material Variation
63 ///
64 /// The entire power of USD VariantSets and all the other composition
65 /// operators can leveraged when encoding shading variation.
66 /// UsdShadeMaterial provides facilities for a particular way of building
67 /// "Material variants" in which neither the identity of the Materials themselves
68 /// nor the geometry Material-bindings need to change - instead we vary the
69 /// targeted networks, interface values, and even parameter values within
70 /// a single variantSet.
71 /// See \ref UsdShadeMaterial_Variations "Authoring Material Variations"
72 /// for more details.
73 ///
74 /// ## Materials Encapsulate their Networks in Namespace
75 ///
76 /// UsdShade requires that all of the shaders that "belong" to the Material
77 /// live under the Material in namespace. This supports powerful, easy reuse
78 /// of Materials, because it allows us to *reference* a Material from one
79 /// asset (the asset might be a library of Materials) into another asset: USD
80 /// references compose all descendant prims of the reference target into the
81 /// referencer's namespace, which means that all of the referenced Material's
82 /// shader networks will come along with the Material. When referenced in this
83 /// way, Materials can also be [instanced](http://openusd.org/docs/USD-Glossary.html#USDGlossary-Instancing), for ease of deduplication and compactness.
84 /// Finally, Material encapsulation also allows us to
85 /// \ref UsdShadeMaterial_BaseMaterial "specialize" child materials from
86 /// parent materials.
87 ///
88 ///
89 ///
90 /// For any described attribute \em Fallback \em Value or \em Allowed \em Values below
91 /// that are text/tokens, the actual token is published and defined in \ref UsdShadeTokens.
92 /// So to set an attribute to the value "rightHanded", use UsdShadeTokens->rightHanded
93 /// as the value.
94 ///
96 {
97 public:
98  /// Compile time constant representing what kind of schema this class is.
99  ///
100  /// \sa UsdSchemaKind
102 
103  /// Construct a UsdShadeMaterial on UsdPrim \p prim .
104  /// Equivalent to UsdShadeMaterial::Get(prim.GetStage(), prim.GetPath())
105  /// for a \em valid \p prim, but will not immediately throw an error for
106  /// an invalid \p prim
107  explicit UsdShadeMaterial(const UsdPrim& prim=UsdPrim())
108  : UsdShadeNodeGraph(prim)
109  {
110  }
111 
112  /// Construct a UsdShadeMaterial on the prim held by \p schemaObj .
113  /// Should be preferred over UsdShadeMaterial(schemaObj.GetPrim()),
114  /// as it preserves SchemaBase state.
115  explicit UsdShadeMaterial(const UsdSchemaBase& schemaObj)
116  : UsdShadeNodeGraph(schemaObj)
117  {
118  }
119 
120  /// Destructor.
122  virtual ~UsdShadeMaterial();
123 
124  /// Return a vector of names of all pre-declared attributes for this schema
125  /// class and all its ancestor classes. Does not include attributes that
126  /// may be authored by custom/extended methods of the schemas involved.
128  static const TfTokenVector &
129  GetSchemaAttributeNames(bool includeInherited=true);
130 
131  /// Return a UsdShadeMaterial holding the prim adhering to this
132  /// schema at \p path on \p stage. If no prim exists at \p path on
133  /// \p stage, or if the prim at that path does not adhere to this schema,
134  /// return an invalid schema object. This is shorthand for the following:
135  ///
136  /// \code
137  /// UsdShadeMaterial(stage->GetPrimAtPath(path));
138  /// \endcode
139  ///
141  static UsdShadeMaterial
142  Get(const UsdStagePtr &stage, const SdfPath &path);
143 
144  /// Attempt to ensure a \a UsdPrim adhering to this schema at \p path
145  /// is defined (according to UsdPrim::IsDefined()) on this stage.
146  ///
147  /// If a prim adhering to this schema at \p path is already defined on this
148  /// stage, return that prim. Otherwise author an \a SdfPrimSpec with
149  /// \a specifier == \a SdfSpecifierDef and this schema's prim type name for
150  /// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s
151  /// with \p specifier == \a SdfSpecifierDef and empty typeName at the
152  /// current EditTarget for any nonexistent, or existing but not \a Defined
153  /// ancestors.
154  ///
155  /// The given \a path must be an absolute prim path that does not contain
156  /// any variant selections.
157  ///
158  /// If it is impossible to author any of the necessary PrimSpecs, (for
159  /// example, in case \a path cannot map to the current UsdEditTarget's
160  /// namespace) issue an error and return an invalid \a UsdPrim.
161  ///
162  /// Note that this method may return a defined prim whose typeName does not
163  /// specify this schema class, in case a stronger typeName opinion overrides
164  /// the opinion at the current EditTarget.
165  ///
167  static UsdShadeMaterial
168  Define(const UsdStagePtr &stage, const SdfPath &path);
169 
170 protected:
171  /// Returns the kind of schema this class belongs to.
172  ///
173  /// \sa UsdSchemaKind
175  UsdSchemaKind _GetSchemaKind() const override;
176 
177 private:
178  // needs to invoke _GetStaticTfType.
179  friend class UsdSchemaRegistry;
181  static const TfType &_GetStaticTfType();
182 
183  static bool _IsTypedSchema();
184 
185  // override SchemaBase virtuals.
187  const TfType &_GetTfType() const override;
188 
189 public:
190  // --------------------------------------------------------------------- //
191  // SURFACE
192  // --------------------------------------------------------------------- //
193  /// Represents the universal "surface" output terminal of a
194  /// material.
195  ///
196  /// | ||
197  /// | -- | -- |
198  /// | Declaration | `token outputs:surface` |
199  /// | C++ Type | TfToken |
200  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token |
203 
204  /// See GetSurfaceAttr(), and also
205  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
206  /// If specified, author \p defaultValue as the attribute's default,
207  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
208  /// the default for \p writeSparsely is \c false.
210  UsdAttribute CreateSurfaceAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
211 
212 public:
213  // --------------------------------------------------------------------- //
214  // DISPLACEMENT
215  // --------------------------------------------------------------------- //
216  /// Represents the universal "displacement" output terminal of a
217  /// material.
218  ///
219  /// | ||
220  /// | -- | -- |
221  /// | Declaration | `token outputs:displacement` |
222  /// | C++ Type | TfToken |
223  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token |
226 
227  /// See GetDisplacementAttr(), and also
228  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
229  /// If specified, author \p defaultValue as the attribute's default,
230  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
231  /// the default for \p writeSparsely is \c false.
233  UsdAttribute CreateDisplacementAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
234 
235 public:
236  // --------------------------------------------------------------------- //
237  // VOLUME
238  // --------------------------------------------------------------------- //
239  /// Represents the universal "volume" output terminal of a
240  /// material.
241  ///
242  /// | ||
243  /// | -- | -- |
244  /// | Declaration | `token outputs:volume` |
245  /// | C++ Type | TfToken |
246  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token |
248  UsdAttribute GetVolumeAttr() const;
249 
250  /// See GetVolumeAttr(), and also
251  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
252  /// If specified, author \p defaultValue as the attribute's default,
253  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
254  /// the default for \p writeSparsely is \c false.
256  UsdAttribute CreateVolumeAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
257 
258 public:
259  // ===================================================================== //
260  // Feel free to add custom code below this line, it will be preserved by
261  // the code generator.
262  //
263  // Just remember to:
264  // - Close the class declaration with };
265  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
266  // - Close the include guard with #endif
267  // ===================================================================== //
268  // --(BEGIN CUSTOM CODE)--
269 
270  // --------------------------------------------------------------------- //
271  /// \name Helpful Types
272  /// @{
273  // --------------------------------------------------------------------- //
274 
275  /// A function type that takes a path and returns a bool.
276  typedef std::function<bool (const SdfPath &)> PathPredicate;
277 
278  /// @}
279 
280 
281  // --------------------------------------------------------------------- //
282  /// \anchor UsdShadeMaterial_Outputs
283  /// \name Standard Material Terminal Outputs
284  /// A UsdShadeMaterial can have any number of "terminal" outputs. These
285  /// outputs are generally used to point to outputs of shader prims or
286  /// NodeGraphs that describe certain properties of the material that a
287  /// renderer might wish to consume. There are three standard output
288  /// terminals that are supported by the core API: <b>surface</b>,
289  /// <b>displacement</b> and <b>volume</b>.
290  ///
291  /// Each terminal output can further be qualified by a token-valued
292  /// <b>renderContext</b>. When a non-empty renderContext value is specified
293  /// to the API, the output is considered to have a specific or restricted
294  /// renderContext. If the renderContext value is empty (i.e. equal to
295  /// UsdShadeTokens->universalRenderContext), then the output is considered
296  /// to be a "universal", meaning it could apply to any render contexts.
297  /// Render context token values is typically driven by the rendering backend
298  /// consuming the terminal output (eg, RI or glslfx).
299  /// @{
300 
301  /// Creates and returns the "surface" output on this material for the
302  /// specified \p renderContext.
303  ///
304  /// If the output already exists on the material, it is returned and no
305  /// authoring is performed. The returned output will always have the
306  /// requested renderContext.
307  USDSHADE_API
308  UsdShadeOutput CreateSurfaceOutput(const TfToken &renderContext
309  =UsdShadeTokens->universalRenderContext) const;
310 
311  /// Returns the "surface" output of this material for the specified
312  /// \p renderContext. The returned output will always have the requested
313  /// renderContext.
314  ///
315  /// An invalid output is returned if an output corresponding to the
316  /// requested specific-renderContext does not exist.
317  ///
318  /// \sa UsdShadeMaterial::ComputeSurfaceSource()
320  UsdShadeOutput GetSurfaceOutput(const TfToken &renderContext
321  =UsdShadeTokens->universalRenderContext) const;
322 
323  /// Returns the "surface" outputs of this material for all available
324  /// renderContexts.
325  ///
326  /// The returned vector will include all authored "surface" outputs with
327  /// the <i>universal</i> renderContext output first, if present. Outputs
328  /// are returned regardless of whether they are connected to a valid
329  /// source.
331  std::vector<UsdShadeOutput> GetSurfaceOutputs() const;
332 
333  /// \deprecated Use the form that takes a TfTokenVector or renderContexts.
336  const TfToken &renderContext,
337  TfToken *sourceName=nullptr,
338  UsdShadeAttributeType *sourceType=nullptr) const;
339 
340  /// Computes the resolved "surface" output source for the given
341  /// \p contextVector. Using the earliest renderContext in the contextVector
342  /// that produces a valid Shader object.
343  ///
344  /// If a "surface" output corresponding to each of the renderContexts
345  /// does not exist <b>or</b> is not connected to a valid source, then this
346  /// checks the <i>universal</i> surface output.
347  ///
348  /// Returns an empty Shader object if there is no valid <i>surface</i>
349  /// output source for any of the renderContexts in the \p contextVector.
350  /// The python version of this method returns a tuple containing three
351  /// elements (the source surface shader, sourceName, sourceType).
354  const TfTokenVector &contextVector={UsdShadeTokens->universalRenderContext},
355  TfToken *sourceName=nullptr,
356  UsdShadeAttributeType *sourceType=nullptr) const;
357 
358  /// Creates and returns the "displacement" output on this material for the
359  /// specified \p renderContext.
360  ///
361  /// If the output already exists on the material, it is returned and no
362  /// authoring is performed. The returned output will always have the
363  /// requested renderContext.
364  USDSHADE_API
365  UsdShadeOutput CreateDisplacementOutput(const TfToken &renderContext
366  =UsdShadeTokens->universalRenderContext) const;
367 
368  /// Returns the "displacement" output of this material for the specified
369  /// renderContext. The returned output will always have the requested
370  /// renderContext.
371  ///
372  /// An invalid output is returned if an output corresponding to the
373  /// requested specific-renderContext does not exist.
374  ///
375  /// \sa UsdShadeMaterial::ComputeDisplacementSource()
376  USDSHADE_API
377  UsdShadeOutput GetDisplacementOutput(const TfToken &renderContext
378  =UsdShadeTokens->universalRenderContext) const;
379 
380  /// Returns the "displacement" outputs of this material for all available
381  /// renderContexts.
382  ///
383  /// The returned vector will include all authored "displacement" outputs
384  /// with the <i>universal</i> renderContext output first, if present.
385  /// Outputs are returned regardless of whether they are connected to a
386  /// valid source.
388  std::vector<UsdShadeOutput> GetDisplacementOutputs() const;
389 
390  /// \deprecated Use the form that takes a TfTokenVector or renderContexts
393  const TfToken &renderContext,
394  TfToken *sourceName=nullptr,
395  UsdShadeAttributeType *sourceType=nullptr) const;
396 
397  /// Computes the resolved "displacement" output source for the given
398  /// \p contextVector. Using the earliest renderContext in the contextVector
399  /// that produces a valid Shader object.
400  ///
401  /// If a "displacement" output corresponding to each of the renderContexts
402  /// does not exist <b>or</b> is not connected to a valid source, then this
403  /// checks the <i>universal</i> displacement output.
404  ///
405  /// Returns an empty Shader object if there is no valid <i>displacement</i>
406  /// output source for any of the renderContexts in the \p contextVector.
407  /// The python version of this method returns a tuple containing three
408  /// elements (the source displacement shader, sourceName, sourceType).
411  const TfTokenVector &contextVector={UsdShadeTokens->universalRenderContext},
412  TfToken *sourceName=nullptr,
413  UsdShadeAttributeType *sourceType=nullptr) const;
414 
415  /// Creates and returns the "volume" output on this material for the
416  /// specified \p renderContext.
417  ///
418  /// If the output already exists on the material, it is returned and no
419  /// authoring is performed. The returned output will always have the
420  /// requested renderContext.
421  USDSHADE_API
422  UsdShadeOutput CreateVolumeOutput(const TfToken &renderContext
423  =UsdShadeTokens->universalRenderContext) const;
424 
425  /// Returns the "volume" output of this material for the specified
426  /// renderContext. The returned output will always have the requested
427  /// renderContext.
428  ///
429  /// An invalid output is returned if an output corresponding to the
430  /// requested specific-renderContext does not exist.
431  ///
432  /// \sa UsdShadeMaterial::ComputeVolumeSource()
433  USDSHADE_API
434  UsdShadeOutput GetVolumeOutput(const TfToken &renderContext
435  =UsdShadeTokens->universalRenderContext) const;
436 
437  /// Returns the "volume" outputs of this material for all available
438  /// renderContexts.
439  ///
440  /// The returned vector will include all authored "volume" outputs with the
441  /// <i>universal</i> renderContext output first, if present. Outputs are
442  /// returned regardless of whether they are connected to a valid source.
444  std::vector<UsdShadeOutput> GetVolumeOutputs() const;
445 
446  /// \deprecated Use the form that takes a TfTokenVector or renderContexts
449  const TfToken &renderContext,
450  TfToken *sourceName=nullptr,
451  UsdShadeAttributeType *sourceType=nullptr) const;
452 
453  /// Computes the resolved "volume" output source for the given
454  /// \p contextVector. Using the earliest renderContext in the contextVector
455  /// that produces a valid Shader object.
456  ///
457  /// If a "volume" output corresponding to each of the renderContexts
458  /// does not exist <b>or</b> is not connected to a valid source, then this
459  /// checks the <i>universal</i> volume output.
460  ///
461  /// Returns an empty Shader object if there is no valid <i>volume</i> output
462  /// output source for any of the renderContexts in the \p contextVector.
463  /// The python version of this method returns a tuple containing three
464  /// elements (the source volume shader, sourceName, sourceType).
467  const TfTokenVector &contextVector={UsdShadeTokens->universalRenderContext},
468  TfToken *sourceName=nullptr,
469  UsdShadeAttributeType *sourceType=nullptr) const;
470 
471  /// @}
472 
473 private:
474  // Helper method to compute the sources of a given output, identified by its
475  // baseName, for the renderContexts in the specified contextVector.
476  UsdShadeAttributeVector _ComputeNamedOutputSources(
477  const TfToken &baseName,
478  const TfTokenVector &contextVector) const;
479 
480  // Helper method to compute the source shader of a given output, identified
481  // by its baseName, for the renderContexts in the specified contextVector.
482  UsdShadeShader _ComputeNamedOutputShader(
483  const TfToken &baseName,
484  const TfTokenVector &contextVector,
485  TfToken *sourceName,
486  UsdShadeAttributeType *sourceType) const;
487 
488  // Helper method to retrieve outputs in all renderContexts that match the
489  // given terminalName.
490  std::vector<UsdShadeOutput> _GetOutputsForTerminalName(
491  const TfToken& terminalName) const;
492 
493 public:
494  // --------------------------------------------------------------------- //
495  /// \anchor UsdShadeMaterial_Variations
496  /// \name Authoring Material Variations
497  /// Each UsdShadeMaterial prim can host data for any number of render targets
498  /// (such as Renderman RIS, Arnold, or glslfx).
499  ///
500  /// A single UsdShadeMaterial group can, however, encode variations on
501  /// appearance, varying any data authored on the material and its contents.
502  /// For example, we might have a logo'd baseball cap that
503  /// comes in denim, nylon, and corduroy variations.
504  ///
505  /// We provide methods to aid in authoring such variations on individual
506  /// Material prims, and also a facility for creating a "master" look
507  /// variant on another prim (e.g. a model's root prim, or another common
508  /// ancestor of all Material prims in a model) that will be able to modify
509  /// Materials, bindings, connections and values at once.
510  ///
511  /// <b>Note on variant vs "direct" opinions.</b>
512  /// For any given prim's spec in a layer, opinions expressed inside a
513  /// variant of a variantSet will be /weaker/ than any opinions expressed
514  /// "directly" at the location, outside of any layer.
515  ///
516  /// Therefore, if you intend to author a default variant that is weaker than
517  /// more explicit variants, you will need to have those opinions be weaker
518  /// by setting them across a reference arc such as the following:
519  ///
520  /// \code
521  /// def "MyMaterial" (
522  /// add references = </MyMaterial_defaultShadingVariant>
523  /// variants = {
524  /// string materialVariant = "SomeVariant"
525  /// }
526  /// add variantSets = "materialVariant"
527  /// )
528  /// {
529  /// float strongerThanVariantOpinion
530  ///
531  /// variantSet "materialVariant" = {
532  /// "SomeVariant" {
533  /// float variantOpinion
534  /// }
535  /// }
536  /// }
537  ///
538  /// over "MyMaterial_defaultShadingVariant"
539  /// {
540  /// float weakerThanVariantOpinion
541  /// }
542  /// \endcode
543  ///
544  /// @{
545  ///
546  // --------------------------------------------------------------------- //
547  /// Helper function for configuring a UsdStage's UsdEditTarget to author
548  /// Material variations. Takes care of creating the Material variantSet and
549  /// specified variant, if necessary.
550  ///
551  /// Let's assume that we are authoring Materials into the Stage's current
552  /// UsdEditTarget, and that we are iterating over the variations of a
553  /// UsdShadeMaterial \em clothMaterial, and \em currVariant is the variant we are
554  /// processing (e.g. "denim").
555  ///
556  /// In C++, then, we would use the following pattern:
557  /// \code
558  /// {
559  /// UsdEditContext ctxt(clothMaterial.GetEditContextForVariant(currVariant));
560  ///
561  /// // All USD mutation of the UsdStage on which clothMaterial sits will
562  /// // now go "inside" the currVariant of the "MaterialVariant" variantSet
563  /// }
564  /// \endcode
565  ///
566  /// In python, the pattern is:
567  /// \code{.py}
568  /// with clothMaterial.GetEditContextForVariant(currVariant):
569  /// # Now sending mutations to currVariant
570  /// \endcode
571  ///
572  /// If \p layer is specified, then we will use it, rather than the stage's
573  /// current UsdEditTarget's layer as the destination layer for the
574  /// edit context we are building. If \p layer does not actually contribute
575  /// to the Material prim's definition, any editing will have no effect on this
576  /// Material.
577  ///
578  /// <b>Note:</b> As just stated, using this method involves authoring
579  /// a selection for the MaterialVariant in the stage's current EditTarget.
580  /// When client is done authoring variations on this prim, they will likely
581  /// want to either UsdVariantSet::SetVariantSelection() to the appropriate
582  /// default selection, or possibly UsdVariantSet::ClearVariantSelection()
583  /// on the UsdShadeMaterial::GetMaterialVariant() UsdVariantSet.
584  /// \sa UsdVariantSet::GetVariantEditContext()
586  std::pair<UsdStagePtr, UsdEditTarget>
587  GetEditContextForVariant(const TfToken &MaterialVariantName,
588  const SdfLayerHandle &layer = SdfLayerHandle()) const;
589 
590  /// Return a UsdVariantSet object for interacting with the Material variant
591  /// variantSet
594 
595  /// Create a variantSet on \p masterPrim that will set the MaterialVariant on
596  /// each of the given \em MaterialPrims.
597  ///
598  /// The variantSet, whose name can be specified with \p
599  /// masterVariantSetName and defaults to the same MaterialVariant name
600  /// created on Materials by GetEditContextForVariant(), will have the same
601  /// variants as the Materials, and each Master variant will set every
602  /// \p MaterialPrims' MaterialVariant selection to the same variant as the
603  /// master. Thus, it allows all Materials to be switched with a single
604  /// variant selection, on \p masterPrim.
605  ///
606  /// If \p masterPrim is an ancestor of any given member of \p MaterialPrims,
607  /// then we will author variant selections directly on the MaterialPrims.
608  /// However, it is often preferable to create a master MaterialVariant in
609  /// a separately rooted tree from the MaterialPrims, so that it can be
610  /// layered more strongly on top of the Materials. Therefore, for any MaterialPrim
611  /// in a different tree than masterPrim, we will create "overs" as children
612  /// of masterPrim that recreate the path to the MaterialPrim, substituting
613  /// masterPrim's full path for the MaterialPrim's root path component.
614  ///
615  /// Upon successful completion, the new variantSet we created on
616  /// \p masterPrim will have its variant selection authored to the
617  /// "last" variant (determined lexicographically). It is up to the
618  /// calling client to either UsdVariantSet::ClearVariantSelection()
619  /// on \p masterPrim, or set the selection to the desired default setting.
620  ///
621  /// Return \c true on success. It is an error if any of \p Materials
622  /// have a different set of variants for the MaterialVariant than the others.
624  static bool CreateMasterMaterialVariant(
625  const UsdPrim &masterPrim,
626  const std::vector<UsdPrim> &MaterialPrims,
627  const TfToken &masterVariantSetName = TfToken());
628 
629  /// @}
630 
631  // --------------------------------------------------------------------- //
632  /// \anchor UsdShadeMaterial_BaseMaterial
633  /// \name BaseMaterial
634  /// A specialize arc describes child/parent inheritance.
635  /// A Material that derives from a BaseMaterial will retain a live
636  /// composition relationship to its BaseMaterial
637  ///
638  /// @{
639  // --------------------------------------------------------------------- //
640 
641  /// Get the path to the base Material of this Material.
642  /// If there is no base Material, an empty Material is returned
645 
646  /// Get the base Material of this Material.
647  /// If there is no base Material, an empty path is returned
650 
651  /// Given a PcpPrimIndex, searches it for an arc to a parent material.
652  ///
653  /// This is a public static function to support applications that use
654  /// Pcp but not Usd. Most clients should call \ref GetBaseMaterialPath,
655  /// which uses this function when appropriate.
658  const PcpPrimIndex & primIndex,
659  const PathPredicate & pathIsMaterialPredicate);
660 
661  /// Set the base Material of this Material.
662  /// An empty Material is equivalent to clearing the base Material.
664  void SetBaseMaterial(const UsdShadeMaterial& baseMaterial) const;
665 
666  /// Set the path to the base Material of this Material.
667  /// An empty path is equivalent to clearing the base Material.
669  void SetBaseMaterialPath(const SdfPath& baseMaterialPath) const;
670 
671  /// Clear the base Material of this Material.
673  void ClearBaseMaterial() const;
674 
675  // Check if this Material has a base Material
677  bool HasBaseMaterial() const;
678 
679  /// @}
680 
681 };
682 
684 
685 #endif
USDSHADE_API UsdShadeOutput CreateSurfaceOutput(const TfToken &renderContext=UsdShadeTokens->universalRenderContext) const
USDSHADE_API UsdShadeOutput GetVolumeOutput(const TfToken &renderContext=UsdShadeTokens->universalRenderContext) const
#define USDSHADE_API
Definition: api.h:23
static USDSHADE_API SdfPath FindBaseMaterialPathInPrimIndex(const PcpPrimIndex &primIndex, const PathPredicate &pathIsMaterialPredicate)
USDSHADE_API UsdAttribute CreateDisplacementAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USDSHADE_API TfStaticData< UsdShadeTokensType > UsdShadeTokens
USDSHADE_API UsdShadeOutput GetDisplacementOutput(const TfToken &renderContext=UsdShadeTokens->universalRenderContext) const
virtual USDSHADE_API ~UsdShadeMaterial()
Destructor.
USDSHADE_API std::vector< UsdShadeOutput > GetVolumeOutputs() const
static USDSHADE_API UsdShadeMaterial Get(const UsdStagePtr &stage, const SdfPath &path)
USDSHADE_API UsdAttribute CreateSurfaceAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
USDSHADE_API UsdAttribute GetDisplacementAttr() const
static USDSHADE_API bool CreateMasterMaterialVariant(const UsdPrim &masterPrim, const std::vector< UsdPrim > &MaterialPrims, const TfToken &masterVariantSetName=TfToken())
USDSHADE_API void ClearBaseMaterial() const
Clear the base Material of this Material.
USDSHADE_API UsdShadeMaterial GetBaseMaterial() const
USDSHADE_API UsdShadeOutput CreateDisplacementOutput(const TfToken &renderContext=UsdShadeTokens->universalRenderContext) const
GLenum GLuint GLint GLint layer
Definition: glcorearb.h:1299
USDSHADE_API UsdAttribute GetVolumeAttr() const
USDSHADE_API UsdAttribute CreateVolumeAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
Definition: token.h:70
Represents a concrete typed schema.
static const UsdSchemaKind schemaKind
Definition: material.h:101
USDSHADE_API SdfPath GetBaseMaterialPath() const
USDSHADE_API void SetBaseMaterialPath(const SdfPath &baseMaterialPath) const
USDSHADE_API UsdShadeShader ComputeVolumeSource(const TfToken &renderContext, TfToken *sourceName=nullptr, UsdShadeAttributeType *sourceType=nullptr) const
USDSHADE_API std::pair< UsdStagePtr, UsdEditTarget > GetEditContextForVariant(const TfToken &MaterialVariantName, const SdfLayerHandle &layer=SdfLayerHandle()) const
UsdShadeMaterial(const UsdPrim &prim=UsdPrim())
Definition: material.h:107
USDSHADE_API bool HasBaseMaterial() const
UsdShadeMaterial(const UsdSchemaBase &schemaObj)
Definition: material.h:115
Definition: prim.h:116
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
Definition: path.h:273
USDSHADE_API std::vector< UsdShadeOutput > GetSurfaceOutputs() const
USDSHADE_API UsdShadeOutput CreateVolumeOutput(const TfToken &renderContext=UsdShadeTokens->universalRenderContext) const
static USDSHADE_API UsdShadeMaterial Define(const UsdStagePtr &stage, const SdfPath &path)
USDSHADE_API std::vector< UsdShadeOutput > GetDisplacementOutputs() const
UsdSchemaKind
Definition: common.h:112
USDSHADE_API UsdShadeShader ComputeSurfaceSource(const TfToken &renderContext, TfToken *sourceName=nullptr, UsdShadeAttributeType *sourceType=nullptr) const
USDSHADE_API UsdShadeOutput GetSurfaceOutput(const TfToken &renderContext=UsdShadeTokens->universalRenderContext) const
USDSHADE_API void SetBaseMaterial(const UsdShadeMaterial &baseMaterial) const
USDSHADE_API UsdSchemaKind _GetSchemaKind() const override
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
USDSHADE_API UsdVariantSet GetMaterialVariant() const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
Definition: type.h:47
std::function< bool(const SdfPath &)> PathPredicate
A function type that takes a path and returns a bool.
Definition: material.h:276
USDSHADE_API UsdShadeShader ComputeDisplacementSource(const TfToken &renderContext, TfToken *sourceName=nullptr, UsdShadeAttributeType *sourceType=nullptr) const
static USDSHADE_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
USDSHADE_API UsdAttribute GetSurfaceAttr() const
Definition: value.h:146
UsdShadeAttributeType
Definition: types.h:22