All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
shader.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 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 #ifndef USDSHADE_GENERATED_SHADER_H
25 #define USDSHADE_GENERATED_SHADER_H
26 
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/usdShade/api.h"
31 #include "pxr/usd/usd/typed.h"
32 #include "pxr/usd/usd/prim.h"
33 #include "pxr/usd/usd/stage.h"
34 #include "pxr/usd/usdShade/tokens.h"
35 
36 #include "pxr/usd/usdShade/input.h"
37 #include "pxr/usd/usdShade/output.h"
38 #include "pxr/usd/ndr/declare.h"
39 #include "pxr/usd/sdr/shaderNode.h"
40 
41 #include "pxr/base/vt/value.h"
42 
43 #include "pxr/base/gf/vec3d.h"
44 #include "pxr/base/gf/vec3f.h"
45 #include "pxr/base/gf/matrix4d.h"
46 
47 #include "pxr/base/tf/token.h"
48 #include "pxr/base/tf/type.h"
49 
50 PXR_NAMESPACE_OPEN_SCOPE
51 
52 class SdfAssetPath;
53 
54 // -------------------------------------------------------------------------- //
55 // SHADER //
56 // -------------------------------------------------------------------------- //
57 
89 class UsdShadeShader : public UsdTyped
90 {
91 public:
96 
101  explicit UsdShadeShader(const UsdPrim& prim=UsdPrim())
102  : UsdTyped(prim)
103  {
104  }
105 
109  explicit UsdShadeShader(const UsdSchemaBase& schemaObj)
110  : UsdTyped(schemaObj)
111  {
112  }
113 
115  USDSHADE_API
116  virtual ~UsdShadeShader();
117 
121  USDSHADE_API
122  static const TfTokenVector &
123  GetSchemaAttributeNames(bool includeInherited=true);
124 
134  USDSHADE_API
135  static UsdShadeShader
136  Get(const UsdStagePtr &stage, const SdfPath &path);
137 
160  USDSHADE_API
161  static UsdShadeShader
162  Define(const UsdStagePtr &stage, const SdfPath &path);
163 
164 protected:
168  USDSHADE_API
169  UsdSchemaType _GetSchemaType() const override;
170 
171 private:
172  // needs to invoke _GetStaticTfType.
173  friend class UsdSchemaRegistry;
174  USDSHADE_API
175  static const TfType &_GetStaticTfType();
176 
177  static bool _IsTypedSchema();
178 
179  // override SchemaBase virtuals.
180  USDSHADE_API
181  const TfType &_GetTfType() const override;
182 
183 public:
184  // --------------------------------------------------------------------- //
185  // IMPLEMENTATIONSOURCE
186  // --------------------------------------------------------------------- //
210  USDSHADE_API
212 
218  USDSHADE_API
219  UsdAttribute CreateImplementationSourceAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
220 
221 public:
222  // --------------------------------------------------------------------- //
223  // ID
224  // --------------------------------------------------------------------- //
240  USDSHADE_API
241  UsdAttribute GetIdAttr() const;
242 
248  USDSHADE_API
249  UsdAttribute CreateIdAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
250 
251 public:
252  // ===================================================================== //
253  // Feel free to add custom code below this line, it will be preserved by
254  // the code generator.
255  //
256  // Just remember to:
257  // - Close the class declaration with };
258  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
259  // - Close the include guard with #endif
260  // ===================================================================== //
261  // --(BEGIN CUSTOM CODE)--
262 
267  USDSHADE_API
268  UsdShadeShader(const UsdShadeConnectableAPI &connectable);
269 
278  USDSHADE_API
280 
281  // -------------------------------------------------------------------------
291 
297  USDSHADE_API
298  UsdShadeOutput CreateOutput(const TfToken& name,
299  const SdfValueTypeName& typeName);
300 
303  USDSHADE_API
304  UsdShadeOutput GetOutput(const TfToken &name) const;
305 
308  USDSHADE_API
309  std::vector<UsdShadeOutput> GetOutputs() const;
310 
312 
313  // -------------------------------------------------------------------------
314 
323 
328  USDSHADE_API
329  UsdShadeInput CreateInput(const TfToken& name,
330  const SdfValueTypeName& typeName);
331 
334  USDSHADE_API
335  UsdShadeInput GetInput(const TfToken &name) const;
336 
339  USDSHADE_API
340  std::vector<UsdShadeInput> GetInputs() const;
341 
343 
344  // -------------------------------------------------------------------------
345 
353 
389  USDSHADE_API
391 
395  USDSHADE_API
396  bool SetShaderId(const TfToken &id) const;
397 
405  USDSHADE_API
406  bool GetShaderId(TfToken *id) const;
407 
413  USDSHADE_API
414  bool SetSourceAsset(
415  const SdfAssetPath &sourceAsset,
416  const TfToken &sourceType=UsdShadeTokens->universalSourceType) const;
417 
433  USDSHADE_API
434  bool GetSourceAsset(
435  SdfAssetPath *sourceAsset,
436  const TfToken &sourceType=UsdShadeTokens->universalSourceType) const;
437 
444  USDSHADE_API
446  const TfToken &subIdentifier,
447  const TfToken &sourceType=UsdShadeTokens->universalSourceType) const;
448 
463  USDSHADE_API
465  TfToken *subIdentifier,
466  const TfToken &sourceType=UsdShadeTokens->universalSourceType) const;
467 
473  USDSHADE_API
474  bool SetSourceCode(
475  const std::string &sourceCode,
476  const TfToken &sourceType=UsdShadeTokens->universalSourceType) const;
477 
493  USDSHADE_API
494  bool GetSourceCode(
495  std::string *sourceCode,
496  const TfToken &sourceType=UsdShadeTokens->universalSourceType) const;
497 
499 
500  // -------------------------------------------------------------------------
501 
519 
522  USDSHADE_API
523  NdrTokenMap GetSdrMetadata() const;
524 
527  USDSHADE_API
528  std::string GetSdrMetadataByKey(const TfToken &key) const;
529 
532  USDSHADE_API
533  void SetSdrMetadata(const NdrTokenMap &sdrMetadata) const;
534 
537  USDSHADE_API
538  void SetSdrMetadataByKey(
539  const TfToken &key,
540  const std::string &value) const;
541 
544  USDSHADE_API
545  bool HasSdrMetadata() const;
546 
549  USDSHADE_API
550  bool HasSdrMetadataByKey(const TfToken &key) const;
551 
554  USDSHADE_API
555  void ClearSdrMetadata() const;
556 
559  USDSHADE_API
560  void ClearSdrMetadataByKey(const TfToken &key) const;
561 
563 
568  USDSHADE_API
569  SdrShaderNodeConstPtr GetShaderNodeForSourceType(const TfToken &sourceType)
570  const;
571 
572 };
573 
574 PXR_NAMESPACE_CLOSE_SCOPE
575 
576 #endif
USDSHADE_API void ClearSdrMetadataByKey(const TfToken &key) const
Clears the entry corresponding to the given key in the &quot;sdrMetadata&quot; dictionary authored in the curre...
USDSHADE_API bool GetSourceAsset(SdfAssetPath *sourceAsset, const TfToken &sourceType=UsdShadeTokens->universalSourceType) const
Fetches the shader&#39;s source asset value for the specified sourceType value from the info:sourceType:s...
USDSHADE_API bool SetSourceAssetSubIdentifier(const TfToken &subIdentifier, const TfToken &sourceType=UsdShadeTokens->universalSourceType) const
Set a sub-identifier to be used with a source asset of the given source type.
USDSHADE_API UsdAttribute GetIdAttr() const
The id is an identifier for the type or purpose of the shader.
USDSHADE_API UsdAttribute GetImplementationSourceAttr() const
Specifies the attribute that should be consulted to get the shader&#39;s implementation or its source cod...
USDSHADE_API bool SetSourceAsset(const SdfAssetPath &sourceAsset, const TfToken &sourceType=UsdShadeTokens->universalSourceType) const
Sets the shader&#39;s source-asset path value to sourceAsset for the given source type, sourceType.
USDSHADE_API std::vector< UsdShadeInput > GetInputs() const
Inputs are represented by attributes in the &quot;inputs:&quot; namespace.
USDSHADE_API bool HasSdrMetadata() const
Returns true if the shader has a non-empty composed &quot;sdrMetadata&quot; dictionary value.
USDSHADE_API bool SetSourceCode(const std::string &sourceCode, const TfToken &sourceType=UsdShadeTokens->universalSourceType) const
Sets the shader&#39;s source-code value to sourceCode for the given source type, sourceType.
USDSHADE_API TfToken GetImplementationSource() const
Reads the value of info:implementationSource attribute and returns a token identifying the attribute ...
Represents a value type name, i.e.
Definition: valueTypeName.h:83
USDSHADE_API UsdShadeOutput CreateOutput(const TfToken &name, const SdfValueTypeName &typeName)
Create an output which can either have a value or can be connected.
Scenegraph object for authoring and retrieving numeric, string, and array valued data, sampled over time.
Definition: attribute.h:176
Represents a concrete typed schema.
UsdShadeShader(const UsdSchemaBase &schemaObj)
Construct a UsdShadeShader on the prim held by schemaObj .
Definition: shader.h:109
USDSHADE_API UsdShadeConnectableAPI ConnectableAPI() const
Contructs and returns a UsdShadeConnectableAPI object with this shader.
USDSHADE_API bool SetShaderId(const TfToken &id) const
Sets the shader&#39;s ID value.
static USDSHADE_API UsdShadeShader Define(const UsdStagePtr &stage, const SdfPath &path)
Attempt to ensure a UsdPrim adhering to this schema at path is defined (according to UsdPrim::IsDefin...
This class encapsulates a shader or node-graph input, which is a connectable property representing a ...
Definition: input.h:46
USDSHADE_API NdrTokenMap GetSdrMetadata() const
Returns this shader&#39;s composed &quot;sdrMetadata&quot; dictionary as a NdrTokenMap.
static const UsdSchemaType schemaType
Compile time constant representing what kind of schema this class is.
Definition: shader.h:95
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
USDSHADE_API TfStaticData< UsdShadeTokensType > UsdShadeTokens
A global variable with static, efficient TfTokens for use in all public USD API.
USDSHADE_API SdrShaderNodeConstPtr GetShaderNodeForSourceType(const TfToken &sourceType) const
This method attempts to ensure that there is a ShaderNode in the shader registry (i.e.
UsdShadeShader(const UsdPrim &prim=UsdPrim())
Construct a UsdShadeShader on UsdPrim prim .
Definition: shader.h:101
UsdShadeConnectableAPI is an API schema that provides a common interface for creating outputs and mak...
UsdSchemaType
An enum representing which type of schema a given schema class belongs to.
Definition: common.h:127
USDSHADE_API UsdShadeInput CreateInput(const TfToken &name, const SdfValueTypeName &typeName)
Create an input which can either have a value or can be connected.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a &quot;Prim&quot; as ...
Definition: prim.h:131
The base class for all typed schemas (those that can impart a typeName to a UsdPrim), and therefore the base class for all instantiable and &quot;IsA&quot; schemas.
Definition: typed.h:47
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:433
USDSHADE_API void ClearSdrMetadata() const
Clears any &quot;sdrMetadata&quot; value authored on the shader in the current EditTarget.
USDSHADE_API UsdSchemaType _GetSchemaType() const override
Returns the type of schema this class belongs to.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
USDSHADE_API void SetSdrMetadataByKey(const TfToken &key, const std::string &value) const
Sets the value corresponding to key to the given string value, in the shader&#39;s &quot;sdrMetadata&quot; dictiona...
USDSHADE_API UsdAttribute CreateIdAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
See GetIdAttr(), and also Create vs Get Property Methods for when to use Get vs Create.
USDSHADE_API std::vector< UsdShadeOutput > GetOutputs() const
Outputs are represented by attributes in the &quot;outputs:&quot; namespace.
static USDSHADE_API UsdShadeShader Get(const UsdStagePtr &stage, const SdfPath &path)
Return a UsdShadeShader holding the prim adhering to this schema at path on stage.
Contains an asset path and an optional resolved path.
Definition: assetPath.h:43
USDSHADE_API bool HasSdrMetadataByKey(const TfToken &key) const
Returns true if there is a value corresponding to the given key in the composed &quot;sdrMetadata&quot; diction...
USDSHADE_API std::string GetSdrMetadataByKey(const TfToken &key) const
Returns the value corresponding to key in the composed sdrMetadata dictionary.
USDSHADE_API UsdAttribute CreateImplementationSourceAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
See GetImplementationSourceAttr(), and also Create vs Get Property Methods for when to use Get vs Cre...
USDSHADE_API UsdShadeInput GetInput(const TfToken &name) const
Return the requested input if it exists.
Base class for all USD shaders.
Definition: shader.h:89
virtual USDSHADE_API ~UsdShadeShader()
Destructor.
TfType represents a dynamic runtime type.
Definition: type.h:70
Singleton registry that provides access to prim and property definition information for registered Us...
static USDSHADE_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
Return a vector of names of all pre-declared attributes for this schema class and all its ancestor cl...
USDSHADE_API bool GetSourceCode(std::string *sourceCode, const TfToken &sourceType=UsdShadeTokens->universalSourceType) const
Fetches the shader&#39;s source code for the specified sourceType value by reading the info:sourceType:so...
This class encapsulates a shader or node-graph output, which is a connectable property representing a...
Definition: output.h:47
The base class for all schema types in Usd.
Definition: schemaBase.h:56
USDSHADE_API UsdShadeOutput GetOutput(const TfToken &name) const
Return the requested output if it exists.
USDSHADE_API bool GetSourceAssetSubIdentifier(TfToken *subIdentifier, const TfToken &sourceType=UsdShadeTokens->universalSourceType) const
Fetches the shader&#39;s sub-identifier for the source asset with the specified sourceType value from the...
USDSHADE_API bool GetShaderId(TfToken *id) const
Fetches the shader&#39;s ID value from the info:id attribute, if the shader&#39;s info:implementationSource i...
USDSHADE_API void SetSdrMetadata(const NdrTokenMap &sdrMetadata) const
Authors the given sdrMetadata on this shader at the current EditTarget.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:182