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 /// For UsdShade schema domain any connectable child prim of UsdShadeMaterial
89 /// must be either UsdShadeShader derived or UsdShadeNodeGraph derived but not
90 /// UsdShadeMaterial, that is, UsdShadeMaterial can not be nested. It also must
91 /// not contain any imageable prims as its descendants (UsdGeomScope,
92 /// UsdGeomCamera, UsdGeomMesh etc).
93 ///
94 /// Other derived classes of UsdShadeNodeGraph from other schema domains may
95 /// define their own stricter rules.
96 ///
97 ///
98 /// For any described attribute \em Fallback \em Value or \em Allowed \em Values below
99 /// that are text/tokens, the actual token is published and defined in \ref UsdShadeTokens.
100 /// So to set an attribute to the value "rightHanded", use UsdShadeTokens->rightHanded
101 /// as the value.
102 ///
104 {
105 public:
106  /// Compile time constant representing what kind of schema this class is.
107  ///
108  /// \sa UsdSchemaKind
110 
111  /// Construct a UsdShadeMaterial on UsdPrim \p prim .
112  /// Equivalent to UsdShadeMaterial::Get(prim.GetStage(), prim.GetPath())
113  /// for a \em valid \p prim, but will not immediately throw an error for
114  /// an invalid \p prim
115  explicit UsdShadeMaterial(const UsdPrim& prim=UsdPrim())
116  : UsdShadeNodeGraph(prim)
117  {
118  }
119 
120  /// Construct a UsdShadeMaterial on the prim held by \p schemaObj .
121  /// Should be preferred over UsdShadeMaterial(schemaObj.GetPrim()),
122  /// as it preserves SchemaBase state.
123  explicit UsdShadeMaterial(const UsdSchemaBase& schemaObj)
124  : UsdShadeNodeGraph(schemaObj)
125  {
126  }
127 
128  /// Destructor.
130  virtual ~UsdShadeMaterial();
131 
132  /// Return a vector of names of all pre-declared attributes for this schema
133  /// class and all its ancestor classes. Does not include attributes that
134  /// may be authored by custom/extended methods of the schemas involved.
136  static const TfTokenVector &
137  GetSchemaAttributeNames(bool includeInherited=true);
138 
139  /// Return a UsdShadeMaterial holding the prim adhering to this
140  /// schema at \p path on \p stage. If no prim exists at \p path on
141  /// \p stage, or if the prim at that path does not adhere to this schema,
142  /// return an invalid schema object. This is shorthand for the following:
143  ///
144  /// \code
145  /// UsdShadeMaterial(stage->GetPrimAtPath(path));
146  /// \endcode
147  ///
149  static UsdShadeMaterial
150  Get(const UsdStagePtr &stage, const SdfPath &path);
151 
152  /// Attempt to ensure a \a UsdPrim adhering to this schema at \p path
153  /// is defined (according to UsdPrim::IsDefined()) on this stage.
154  ///
155  /// If a prim adhering to this schema at \p path is already defined on this
156  /// stage, return that prim. Otherwise author an \a SdfPrimSpec with
157  /// \a specifier == \a SdfSpecifierDef and this schema's prim type name for
158  /// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s
159  /// with \p specifier == \a SdfSpecifierDef and empty typeName at the
160  /// current EditTarget for any nonexistent, or existing but not \a Defined
161  /// ancestors.
162  ///
163  /// The given \a path must be an absolute prim path that does not contain
164  /// any variant selections.
165  ///
166  /// If it is impossible to author any of the necessary PrimSpecs, (for
167  /// example, in case \a path cannot map to the current UsdEditTarget's
168  /// namespace) issue an error and return an invalid \a UsdPrim.
169  ///
170  /// Note that this method may return a defined prim whose typeName does not
171  /// specify this schema class, in case a stronger typeName opinion overrides
172  /// the opinion at the current EditTarget.
173  ///
175  static UsdShadeMaterial
176  Define(const UsdStagePtr &stage, const SdfPath &path);
177 
178 protected:
179  /// Returns the kind of schema this class belongs to.
180  ///
181  /// \sa UsdSchemaKind
183  UsdSchemaKind _GetSchemaKind() const override;
184 
185 private:
186  // needs to invoke _GetStaticTfType.
187  friend class UsdSchemaRegistry;
189  static const TfType &_GetStaticTfType();
190 
191  static bool _IsTypedSchema();
192 
193  // override SchemaBase virtuals.
195  const TfType &_GetTfType() const override;
196 
197 public:
198  // --------------------------------------------------------------------- //
199  // SURFACE
200  // --------------------------------------------------------------------- //
201  /// Represents the universal "surface" output terminal of a
202  /// material.
203  ///
204  /// | ||
205  /// | -- | -- |
206  /// | Declaration | `token outputs:surface` |
207  /// | C++ Type | TfToken |
208  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token |
211 
212  /// See GetSurfaceAttr(), and also
213  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
214  /// If specified, author \p defaultValue as the attribute's default,
215  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
216  /// the default for \p writeSparsely is \c false.
218  UsdAttribute CreateSurfaceAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
219 
220 public:
221  // --------------------------------------------------------------------- //
222  // DISPLACEMENT
223  // --------------------------------------------------------------------- //
224  /// Represents the universal "displacement" output terminal of a
225  /// material.
226  ///
227  /// | ||
228  /// | -- | -- |
229  /// | Declaration | `token outputs:displacement` |
230  /// | C++ Type | TfToken |
231  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token |
234 
235  /// See GetDisplacementAttr(), and also
236  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
237  /// If specified, author \p defaultValue as the attribute's default,
238  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
239  /// the default for \p writeSparsely is \c false.
241  UsdAttribute CreateDisplacementAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
242 
243 public:
244  // --------------------------------------------------------------------- //
245  // VOLUME
246  // --------------------------------------------------------------------- //
247  /// Represents the universal "volume" output terminal of a
248  /// material.
249  ///
250  /// | ||
251  /// | -- | -- |
252  /// | Declaration | `token outputs:volume` |
253  /// | C++ Type | TfToken |
254  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token |
256  UsdAttribute GetVolumeAttr() const;
257 
258  /// See GetVolumeAttr(), and also
259  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
260  /// If specified, author \p defaultValue as the attribute's default,
261  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
262  /// the default for \p writeSparsely is \c false.
264  UsdAttribute CreateVolumeAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
265 
266 public:
267  // ===================================================================== //
268  // Feel free to add custom code below this line, it will be preserved by
269  // the code generator.
270  //
271  // Just remember to:
272  // - Close the class declaration with };
273  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
274  // - Close the include guard with #endif
275  // ===================================================================== //
276  // --(BEGIN CUSTOM CODE)--
277 
278  // --------------------------------------------------------------------- //
279  /// \name Helpful Types
280  /// @{
281  // --------------------------------------------------------------------- //
282 
283  /// A function type that takes a path and returns a bool.
284  typedef std::function<bool (const SdfPath &)> PathPredicate;
285 
286  /// @}
287 
288 
289  // --------------------------------------------------------------------- //
290  /// \anchor UsdShadeMaterial_Outputs
291  /// \name Standard Material Terminal Outputs
292  /// A UsdShadeMaterial can have any number of "terminal" outputs. These
293  /// outputs are generally used to point to outputs of shader prims or
294  /// NodeGraphs that describe certain properties of the material that a
295  /// renderer might wish to consume. There are three standard output
296  /// terminals that are supported by the core API: <b>surface</b>,
297  /// <b>displacement</b> and <b>volume</b>.
298  ///
299  /// Each terminal output can further be qualified by a token-valued
300  /// <b>renderContext</b>. When a non-empty renderContext value is specified
301  /// to the API, the output is considered to have a specific or restricted
302  /// renderContext. If the renderContext value is empty (i.e. equal to
303  /// UsdShadeTokens->universalRenderContext), then the output is considered
304  /// to be a "universal", meaning it could apply to any render contexts.
305  /// Render context token values is typically driven by the rendering backend
306  /// consuming the terminal output (eg, RI or glslfx).
307  /// @{
308 
309  /// Creates and returns the "surface" output on this material for the
310  /// specified \p renderContext.
311  ///
312  /// If the output already exists on the material, it is returned and no
313  /// authoring is performed. The returned output will always have the
314  /// requested renderContext.
315  USDSHADE_API
316  UsdShadeOutput CreateSurfaceOutput(const TfToken &renderContext
317  =UsdShadeTokens->universalRenderContext) const;
318 
319  /// Returns the "surface" output of this material for the specified
320  /// \p renderContext. The returned output will always have the requested
321  /// renderContext.
322  ///
323  /// An invalid output is returned if an output corresponding to the
324  /// requested specific-renderContext does not exist.
325  ///
326  /// \sa UsdShadeMaterial::ComputeSurfaceSource()
328  UsdShadeOutput GetSurfaceOutput(const TfToken &renderContext
329  =UsdShadeTokens->universalRenderContext) const;
330 
331  /// Returns the "surface" outputs of this material for all available
332  /// renderContexts.
333  ///
334  /// The returned vector will include all authored "surface" outputs with
335  /// the <i>universal</i> renderContext output first, if present. Outputs
336  /// are returned regardless of whether they are connected to a valid
337  /// source.
339  std::vector<UsdShadeOutput> GetSurfaceOutputs() const;
340 
341  /// \deprecated Use the form that takes a TfTokenVector or renderContexts.
344  const TfToken &renderContext,
345  TfToken *sourceName=nullptr,
346  UsdShadeAttributeType *sourceType=nullptr) const;
347 
348  /// Computes the resolved "surface" output source for the given
349  /// \p contextVector. Using the earliest renderContext in the contextVector
350  /// that produces a valid Shader object.
351  ///
352  /// If a "surface" output corresponding to each of the renderContexts
353  /// does not exist <b>or</b> is not connected to a valid source, then this
354  /// checks the <i>universal</i> surface output.
355  ///
356  /// Returns an empty Shader object if there is no valid <i>surface</i>
357  /// output source for any of the renderContexts in the \p contextVector.
358  /// The python version of this method returns a tuple containing three
359  /// elements (the source surface shader, sourceName, sourceType).
362  const TfTokenVector &contextVector={UsdShadeTokens->universalRenderContext},
363  TfToken *sourceName=nullptr,
364  UsdShadeAttributeType *sourceType=nullptr) const;
365 
366  /// Creates and returns the "displacement" output on this material for the
367  /// specified \p renderContext.
368  ///
369  /// If the output already exists on the material, it is returned and no
370  /// authoring is performed. The returned output will always have the
371  /// requested renderContext.
372  USDSHADE_API
373  UsdShadeOutput CreateDisplacementOutput(const TfToken &renderContext
374  =UsdShadeTokens->universalRenderContext) const;
375 
376  /// Returns the "displacement" output of this material for the specified
377  /// renderContext. The returned output will always have the requested
378  /// renderContext.
379  ///
380  /// An invalid output is returned if an output corresponding to the
381  /// requested specific-renderContext does not exist.
382  ///
383  /// \sa UsdShadeMaterial::ComputeDisplacementSource()
384  USDSHADE_API
385  UsdShadeOutput GetDisplacementOutput(const TfToken &renderContext
386  =UsdShadeTokens->universalRenderContext) const;
387 
388  /// Returns the "displacement" outputs of this material for all available
389  /// renderContexts.
390  ///
391  /// The returned vector will include all authored "displacement" outputs
392  /// with the <i>universal</i> renderContext output first, if present.
393  /// Outputs are returned regardless of whether they are connected to a
394  /// valid source.
396  std::vector<UsdShadeOutput> GetDisplacementOutputs() const;
397 
398  /// \deprecated Use the form that takes a TfTokenVector or renderContexts
401  const TfToken &renderContext,
402  TfToken *sourceName=nullptr,
403  UsdShadeAttributeType *sourceType=nullptr) const;
404 
405  /// Computes the resolved "displacement" output source for the given
406  /// \p contextVector. Using the earliest renderContext in the contextVector
407  /// that produces a valid Shader object.
408  ///
409  /// If a "displacement" output corresponding to each of the renderContexts
410  /// does not exist <b>or</b> is not connected to a valid source, then this
411  /// checks the <i>universal</i> displacement output.
412  ///
413  /// Returns an empty Shader object if there is no valid <i>displacement</i>
414  /// output source for any of the renderContexts in the \p contextVector.
415  /// The python version of this method returns a tuple containing three
416  /// elements (the source displacement shader, sourceName, sourceType).
419  const TfTokenVector &contextVector={UsdShadeTokens->universalRenderContext},
420  TfToken *sourceName=nullptr,
421  UsdShadeAttributeType *sourceType=nullptr) const;
422 
423  /// Creates and returns the "volume" output on this material for the
424  /// specified \p renderContext.
425  ///
426  /// If the output already exists on the material, it is returned and no
427  /// authoring is performed. The returned output will always have the
428  /// requested renderContext.
429  USDSHADE_API
430  UsdShadeOutput CreateVolumeOutput(const TfToken &renderContext
431  =UsdShadeTokens->universalRenderContext) const;
432 
433  /// Returns the "volume" output of this material for the specified
434  /// renderContext. The returned output will always have the requested
435  /// renderContext.
436  ///
437  /// An invalid output is returned if an output corresponding to the
438  /// requested specific-renderContext does not exist.
439  ///
440  /// \sa UsdShadeMaterial::ComputeVolumeSource()
441  USDSHADE_API
442  UsdShadeOutput GetVolumeOutput(const TfToken &renderContext
443  =UsdShadeTokens->universalRenderContext) const;
444 
445  /// Returns the "volume" outputs of this material for all available
446  /// renderContexts.
447  ///
448  /// The returned vector will include all authored "volume" outputs with the
449  /// <i>universal</i> renderContext output first, if present. Outputs are
450  /// returned regardless of whether they are connected to a valid source.
452  std::vector<UsdShadeOutput> GetVolumeOutputs() const;
453 
454  /// \deprecated Use the form that takes a TfTokenVector or renderContexts
457  const TfToken &renderContext,
458  TfToken *sourceName=nullptr,
459  UsdShadeAttributeType *sourceType=nullptr) const;
460 
461  /// Computes the resolved "volume" output source for the given
462  /// \p contextVector. Using the earliest renderContext in the contextVector
463  /// that produces a valid Shader object.
464  ///
465  /// If a "volume" output corresponding to each of the renderContexts
466  /// does not exist <b>or</b> is not connected to a valid source, then this
467  /// checks the <i>universal</i> volume output.
468  ///
469  /// Returns an empty Shader object if there is no valid <i>volume</i> output
470  /// output source for any of the renderContexts in the \p contextVector.
471  /// The python version of this method returns a tuple containing three
472  /// elements (the source volume shader, sourceName, sourceType).
475  const TfTokenVector &contextVector={UsdShadeTokens->universalRenderContext},
476  TfToken *sourceName=nullptr,
477  UsdShadeAttributeType *sourceType=nullptr) const;
478 
479  /// @}
480 
481 private:
482  // Helper method to compute the sources of a given output, identified by its
483  // baseName, for the renderContexts in the specified contextVector.
484  UsdShadeAttributeVector _ComputeNamedOutputSources(
485  const TfToken &baseName,
486  const TfTokenVector &contextVector) const;
487 
488  // Helper method to compute the source shader of a given output, identified
489  // by its baseName, for the renderContexts in the specified contextVector.
490  UsdShadeShader _ComputeNamedOutputShader(
491  const TfToken &baseName,
492  const TfTokenVector &contextVector,
493  TfToken *sourceName,
494  UsdShadeAttributeType *sourceType) const;
495 
496  // Helper method to retrieve outputs in all renderContexts that match the
497  // given terminalName.
498  std::vector<UsdShadeOutput> _GetOutputsForTerminalName(
499  const TfToken& terminalName) const;
500 
501 public:
502  // --------------------------------------------------------------------- //
503  /// \anchor UsdShadeMaterial_Variations
504  /// \name Authoring Material Variations
505  /// Each UsdShadeMaterial prim can host data for any number of render targets
506  /// (such as Renderman RIS, Arnold, or glslfx).
507  ///
508  /// A single UsdShadeMaterial group can, however, encode variations on
509  /// appearance, varying any data authored on the material and its contents.
510  /// For example, we might have a logo'd baseball cap that
511  /// comes in denim, nylon, and corduroy variations.
512  ///
513  /// We provide methods to aid in authoring such variations on individual
514  /// Material prims, and also a facility for creating a "master" look
515  /// variant on another prim (e.g. a model's root prim, or another common
516  /// ancestor of all Material prims in a model) that will be able to modify
517  /// Materials, bindings, connections and values at once.
518  ///
519  /// <b>Note on variant vs "direct" opinions.</b>
520  /// For any given prim's spec in a layer, opinions expressed inside a
521  /// variant of a variantSet will be /weaker/ than any opinions expressed
522  /// "directly" at the location, outside of any layer.
523  ///
524  /// Therefore, if you intend to author a default variant that is weaker than
525  /// more explicit variants, you will need to have those opinions be weaker
526  /// by setting them across a reference arc such as the following:
527  ///
528  /// \code
529  /// def "MyMaterial" (
530  /// add references = </MyMaterial_defaultShadingVariant>
531  /// variants = {
532  /// string materialVariant = "SomeVariant"
533  /// }
534  /// add variantSets = "materialVariant"
535  /// )
536  /// {
537  /// float strongerThanVariantOpinion
538  ///
539  /// variantSet "materialVariant" = {
540  /// "SomeVariant" {
541  /// float variantOpinion
542  /// }
543  /// }
544  /// }
545  ///
546  /// over "MyMaterial_defaultShadingVariant"
547  /// {
548  /// float weakerThanVariantOpinion
549  /// }
550  /// \endcode
551  ///
552  /// @{
553  ///
554  // --------------------------------------------------------------------- //
555  /// Helper function for configuring a UsdStage's UsdEditTarget to author
556  /// Material variations. Takes care of creating the Material variantSet and
557  /// specified variant, if necessary.
558  ///
559  /// Let's assume that we are authoring Materials into the Stage's current
560  /// UsdEditTarget, and that we are iterating over the variations of a
561  /// UsdShadeMaterial \em clothMaterial, and \em currVariant is the variant we are
562  /// processing (e.g. "denim").
563  ///
564  /// In C++, then, we would use the following pattern:
565  /// \code
566  /// {
567  /// UsdEditContext ctxt(clothMaterial.GetEditContextForVariant(currVariant));
568  ///
569  /// // All USD mutation of the UsdStage on which clothMaterial sits will
570  /// // now go "inside" the currVariant of the "MaterialVariant" variantSet
571  /// }
572  /// \endcode
573  ///
574  /// In python, the pattern is:
575  /// \code{.py}
576  /// with clothMaterial.GetEditContextForVariant(currVariant):
577  /// # Now sending mutations to currVariant
578  /// \endcode
579  ///
580  /// If \p layer is specified, then we will use it, rather than the stage's
581  /// current UsdEditTarget's layer as the destination layer for the
582  /// edit context we are building. If \p layer does not actually contribute
583  /// to the Material prim's definition, any editing will have no effect on this
584  /// Material.
585  ///
586  /// <b>Note:</b> As just stated, using this method involves authoring
587  /// a selection for the MaterialVariant in the stage's current EditTarget.
588  /// When client is done authoring variations on this prim, they will likely
589  /// want to either UsdVariantSet::SetVariantSelection() to the appropriate
590  /// default selection, or possibly UsdVariantSet::ClearVariantSelection()
591  /// on the UsdShadeMaterial::GetMaterialVariant() UsdVariantSet.
592  /// \sa UsdVariantSet::GetVariantEditContext()
594  std::pair<UsdStagePtr, UsdEditTarget>
595  GetEditContextForVariant(const TfToken &MaterialVariantName,
596  const SdfLayerHandle &layer = SdfLayerHandle()) const;
597 
598  /// Return a UsdVariantSet object for interacting with the Material variant
599  /// variantSet
602 
603  /// Create a variantSet on \p masterPrim that will set the MaterialVariant on
604  /// each of the given \em MaterialPrims.
605  ///
606  /// The variantSet, whose name can be specified with \p
607  /// masterVariantSetName and defaults to the same MaterialVariant name
608  /// created on Materials by GetEditContextForVariant(), will have the same
609  /// variants as the Materials, and each Master variant will set every
610  /// \p MaterialPrims' MaterialVariant selection to the same variant as the
611  /// master. Thus, it allows all Materials to be switched with a single
612  /// variant selection, on \p masterPrim.
613  ///
614  /// If \p masterPrim is an ancestor of any given member of \p MaterialPrims,
615  /// then we will author variant selections directly on the MaterialPrims.
616  /// However, it is often preferable to create a master MaterialVariant in
617  /// a separately rooted tree from the MaterialPrims, so that it can be
618  /// layered more strongly on top of the Materials. Therefore, for any MaterialPrim
619  /// in a different tree than masterPrim, we will create "overs" as children
620  /// of masterPrim that recreate the path to the MaterialPrim, substituting
621  /// masterPrim's full path for the MaterialPrim's root path component.
622  ///
623  /// Upon successful completion, the new variantSet we created on
624  /// \p masterPrim will have its variant selection authored to the
625  /// "last" variant (determined lexicographically). It is up to the
626  /// calling client to either UsdVariantSet::ClearVariantSelection()
627  /// on \p masterPrim, or set the selection to the desired default setting.
628  ///
629  /// Return \c true on success. It is an error if any of \p Materials
630  /// have a different set of variants for the MaterialVariant than the others.
632  static bool CreateMasterMaterialVariant(
633  const UsdPrim &masterPrim,
634  const std::vector<UsdPrim> &MaterialPrims,
635  const TfToken &masterVariantSetName = TfToken());
636 
637  /// @}
638 
639  // --------------------------------------------------------------------- //
640  /// \anchor UsdShadeMaterial_BaseMaterial
641  /// \name BaseMaterial
642  /// A specialize arc describes child/parent inheritance.
643  /// A Material that derives from a BaseMaterial will retain a live
644  /// composition relationship to its BaseMaterial
645  ///
646  /// @{
647  // --------------------------------------------------------------------- //
648 
649  /// Get the path to the base Material of this Material.
650  /// If there is no base Material, an empty Material is returned
653 
654  /// Get the base Material of this Material.
655  /// If there is no base Material, an empty path is returned
658 
659  /// Given a PcpPrimIndex, searches it for an arc to a parent material.
660  ///
661  /// This is a public static function to support applications that use
662  /// Pcp but not Usd. Most clients should call \ref GetBaseMaterialPath,
663  /// which uses this function when appropriate.
666  const PcpPrimIndex & primIndex,
667  const PathPredicate & pathIsMaterialPredicate);
668 
669  /// Set the base Material of this Material.
670  /// An empty Material is equivalent to clearing the base Material.
672  void SetBaseMaterial(const UsdShadeMaterial& baseMaterial) const;
673 
674  /// Set the path to the base Material of this Material.
675  /// An empty path is equivalent to clearing the base Material.
677  void SetBaseMaterialPath(const SdfPath& baseMaterialPath) const;
678 
679  /// Clear the base Material of this Material.
681  void ClearBaseMaterial() const;
682 
683  // Check if this Material has a base Material
685  bool HasBaseMaterial() const;
686 
687  /// @}
688 
689 };
690 
692 
693 #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)
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
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:109
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:115
USDSHADE_API bool HasBaseMaterial() const
UsdShadeMaterial(const UsdSchemaBase &schemaObj)
Definition: material.h:123
Definition: prim.h:116
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
Definition: path.h:280
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
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:284
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:89
UsdShadeAttributeType
Definition: types.h:22