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  // Returns the material's render pass tag.
84  inline const TfToken& GetMaterialTag() const;
85 
86  /// Replaces the shader code object with an externally created one
87  /// Used to set the fallback shader for prim.
88  /// This class takes ownership of the passed in object.
89  HDST_API
92 
93 private:
94  // Processes the texture descriptors from a material network to
95  // create textures using the Storm texture system.
96  //
97  // Adds buffer specs/sources necessary for textures, e.g., bindless
98  // handles or sampling transform for field textures.
99  void _ProcessTextureDescriptors(
100  HdSceneDelegate * sceneDelegate,
101  HdStResourceRegistrySharedPtr const& resourceRegistry,
102  std::weak_ptr<HdStShaderCode> const &shaderCode,
104  HdStShaderCode::NamedTextureHandleVector * texturesFromStorm,
105  HdBufferSpecVector * specs,
107 
108  bool
109  _GetHasLimitSurfaceEvaluation(VtDictionary const & metadata) const;
110 
111  void _InitFallbackShader();
112 
113  static HioGlslfx *_fallbackGlslfx;
114 
115  HdSt_MaterialNetworkShaderSharedPtr _materialNetworkShader;
116  VolumeMaterialData _volumeMaterialData;
117 
118  bool _isInitialized : 1;
119  bool _hasPtex : 1;
120  bool _hasLimitSurfaceEvaluation : 1;
121  bool _hasDisplacement : 1;
122 
123  TfToken _materialTag;
124  size_t _textureHash;
125 
126  HdStMaterialNetwork _networkProcessor;
127 };
128 
129 inline bool HdStMaterial::HasPtex() const
130 {
131  return _hasPtex;
132 }
133 
135 {
136  return _hasLimitSurfaceEvaluation;
137 }
138 
139 inline bool HdStMaterial::HasDisplacement() const
140 {
141  return _hasDisplacement;
142 }
143 
145 {
146  return _materialTag;
147 }
148 
151  return _volumeMaterialData;
152 }
153 
154 
156 
157 #endif // PXR_IMAGING_HD_ST_MATERIAL_H
uint32_t HdDirtyBits
Definition: types.h:143
std::shared_ptr< class HdSt_MaterialNetworkShader > HdSt_MaterialNetworkShaderSharedPtr
Definition: drawItem.h:21
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:139
HF_MALLOC_TAG_NEW("new HdStMaterial")
HDST_API HdDirtyBits GetInitialDirtyBitsMask() const override
const VolumeMaterialData & GetVolumeMaterialData() const
Definition: material.h:150
const TfToken & GetMaterialTag() const
Definition: material.h:144
GLsizei GLenum * sources
Definition: glcorearb.h:2542
Definition: token.h:70
bool HasPtex() const
Definition: material.h:129
HDST_API void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) override
Synchronizes state from the delegate to this object.
Definition: path.h:273
std::vector< struct HdBufferSpec > HdBufferSpecVector
bool HasLimitSurfaceEvaluation() const
Returns true if the material specifies limit surface evaluation.
Definition: material.h:134
std::string source
glslfx source code for volume
Definition: material.h:38
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
std::vector< NamedTextureHandle > NamedTextureHandleVector
Definition: shaderCode.h:144
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