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 PXR_IMAGING_HD_ST_MATERIAL_H
8 #define PXR_IMAGING_HD_ST_MATERIAL_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hdSt/api.h"
15 #include "pxr/imaging/hf/perfLog.h"
16 
17 #include <memory>
18 
20 
22  std::shared_ptr<class HdSt_MaterialNetworkShader>;
23 
24 class HioGlslfx;
25 
26 class HdStMaterial final: public HdMaterial
27 {
28 public:
29  HF_MALLOC_TAG_NEW("new HdStMaterial");
30 
31  /// For volumes, the corresponding draw items do not use the
32  /// HdStShaderCode produced by HdStMaterial. Instead HdStVolume is
33  /// using some data from the material to produce its own HdStShaderCode
34  /// based on the volume field bindings.
35  struct VolumeMaterialData final
36  {
37  /// glslfx source code for volume
38  std::string source;
40  };
41 
42  HDST_API
43  HdStMaterial(SdfPath const& id);
44  HDST_API
45  ~HdStMaterial() override;
46 
47  /// Synchronizes state from the delegate to this object.
48  HDST_API
49  void Sync(HdSceneDelegate *sceneDelegate,
50  HdRenderParam *renderParam,
51  HdDirtyBits *dirtyBits) override;
52 
53  HDST_API
54  void Finalize(HdRenderParam *renderParam) override;
55 
56  /// Returns the minimal set of dirty bits to place in the
57  /// change tracker for use in the first sync of this prim.
58  /// Typically this would be all dirty bits.
59  HDST_API
60  HdDirtyBits GetInitialDirtyBitsMask() const override;
61 
62  /// Obtains the GLSLFX code together with supporting information
63  /// such as material params and textures to render surfaces.
64  HDST_API
66 
67  /// Obtains the GLSLFLX code together with material params to
68  /// render volumes.
69  inline const VolumeMaterialData &GetVolumeMaterialData() const;
70 
71  /// Summary flag. Returns true if the material is bound to one or more
72  /// textures and any of those textures is a ptex texture.
73  /// If no textures are bound or all textures are uv textures, then
74  /// the method returns false.
75  inline bool HasPtex() const;
76 
77  /// Returns true if the material specifies limit surface evaluation.
78  inline bool HasLimitSurfaceEvaluation() const;
79 
80  // Returns true if the material has a displacement terminal.
81  inline bool HasDisplacement() const;
82 
83  inline bool IsUsingFallbackShader() const;
84 
85  // Returns the material's render pass tag.
86  inline const TfToken& GetMaterialTag() const;
87 
88  /// Replaces the shader code object with an externally created one
89  /// Used to set the fallback shader for prim.
90  /// This class takes ownership of the passed in object.
91  HDST_API
94 
95 private:
96  // Processes the texture descriptors from a material network to
97  // create textures using the Storm texture system.
98  //
99  // Adds buffer specs/sources necessary for textures, e.g., bindless
100  // handles or sampling transform for field textures.
101  void _ProcessTextureDescriptors(
102  HdSceneDelegate * sceneDelegate,
103  HdStResourceRegistrySharedPtr const& resourceRegistry,
104  std::weak_ptr<HdStShaderCode> const &shaderCode,
106  HdStShaderCode::NamedTextureHandleVector * texturesFromStorm,
107  HdBufferSpecVector * specs,
109 
110  bool
111  _GetHasLimitSurfaceEvaluation(VtDictionary const & metadata) const;
112 
113  void _InitFallbackShader();
114 
115  static HioGlslfx *_fallbackGlslfx;
116 
117  HdSt_MaterialNetworkShaderSharedPtr _materialNetworkShader;
118  VolumeMaterialData _volumeMaterialData;
119 
120  bool _isInitialized : 1;
121  bool _hasPtex : 1;
122  bool _hasLimitSurfaceEvaluation : 1;
123  bool _hasDisplacement : 1;
124  bool _isUsingFallbackShader : 1;
125 
126  TfToken _materialTag;
127  size_t _textureHash;
128 
129  HdStMaterialNetwork _networkProcessor;
130 };
131 
132 inline bool HdStMaterial::HasPtex() const
133 {
134  return _hasPtex;
135 }
136 
138 {
139  return _hasLimitSurfaceEvaluation;
140 }
141 
142 inline bool HdStMaterial::HasDisplacement() const
143 {
144  return _hasDisplacement;
145 }
146 
148 {
149  return _materialTag;
150 }
151 
153 {
154  return _isUsingFallbackShader;
155 }
156 
159  return _volumeMaterialData;
160 }
161 
162 
164 
165 #endif // PXR_IMAGING_HD_ST_MATERIAL_H
uint32_t HdDirtyBits
Definition: types.h:143
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
std::shared_ptr< class HdSt_MaterialNetworkShader > HdSt_MaterialNetworkShaderSharedPtr
Definition: drawItem.h:21
bool IsUsingFallbackShader() const
Definition: material.h:152
HDST_API HdStMaterial(SdfPath const &id)
HdSt_MaterialParamVector params
Definition: material.h:39
std::vector< HdBufferSourceSharedPtr > HdBufferSourceSharedPtrVector
Definition: bufferSource.h:27
bool HasDisplacement() const
Definition: material.h:142
HF_MALLOC_TAG_NEW("new HdStMaterial")
HDST_API HdDirtyBits GetInitialDirtyBitsMask() const override
const VolumeMaterialData & GetVolumeMaterialData() const
Definition: material.h:158
const TfToken & GetMaterialTag() const
Definition: material.h:147
GLsizei GLenum * sources
Definition: glcorearb.h:2542
Definition: token.h:70
bool HasPtex() const
Definition: material.h:132
HDST_API void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) override
Synchronizes state from the delegate to this object.
Definition: path.h:280
std::vector< struct HdBufferSpec > HdBufferSpecVector
bool HasLimitSurfaceEvaluation() const
Returns true if the material specifies limit surface evaluation.
Definition: material.h:137
std::string source
glslfx source code for volume
Definition: material.h:38
std::vector< NamedTextureHandle > NamedTextureHandleVector
Definition: shaderCode.h:145
HDST_API void SetMaterialNetworkShader(HdSt_MaterialNetworkShaderSharedPtr &shaderCode)
#define HDST_API
Definition: api.h:23
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HDST_API HdSt_MaterialNetworkShaderSharedPtr GetMaterialNetworkShader() const
HDST_API ~HdStMaterial() override
std::shared_ptr< class HdStResourceRegistry > HdStResourceRegistrySharedPtr
Definition: commandBuffer.h:30
std::vector< TextureDescriptor > TextureDescriptorVector
HDST_API void Finalize(HdRenderParam *renderParam) override
std::vector< class HdSt_MaterialParam > HdSt_MaterialParamVector