All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
material.h
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 PXR_IMAGING_HD_ST_MATERIAL_H
25 #define PXR_IMAGING_HD_ST_MATERIAL_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdSt/api.h"
29 #include "pxr/imaging/hdSt/materialNetwork.h"
30 #include "pxr/imaging/hdSt/shaderCode.h"
31 #include "pxr/imaging/hd/material.h"
32 #include "pxr/imaging/hf/perfLog.h"
33 
34 #include <memory>
35 
36 PXR_NAMESPACE_OPEN_SCOPE
37 
38 using HdStSurfaceShaderSharedPtr = std::shared_ptr<class HdStSurfaceShader>;
39 
40 class HioGlslfx;
41 
42 class HdStMaterial final: public HdMaterial
43 {
44 public:
45  HF_MALLOC_TAG_NEW("new HdStMaterial");
46 
47  HDST_API
48  HdStMaterial(SdfPath const& id);
49  HDST_API
50  ~HdStMaterial() override;
51 
53  HDST_API
54  void Sync(HdSceneDelegate *sceneDelegate,
55  HdRenderParam *renderParam,
56  HdDirtyBits *dirtyBits) override;
57 
58  HDST_API
59  void Finalize(HdRenderParam *renderParam) override;
60 
64  HDST_API
65  HdDirtyBits GetInitialDirtyBitsMask() const override;
66 
68  HDST_API
69  HdStShaderCodeSharedPtr GetShaderCode() const;
70 
75  inline bool HasPtex() const;
76 
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 
89  HDST_API
90  void SetSurfaceShader(HdStSurfaceShaderSharedPtr &shaderCode);
91 
92 private:
93  // Processes the texture descriptors from a material network to
94  // create textures using the Storm texture system.
95  //
96  // Adds buffer specs/sources necessary for textures, e.g., bindless
97  // handles or sampling transform for field textures.
98  void _ProcessTextureDescriptors(
99  HdSceneDelegate * sceneDelegate,
100  HdStResourceRegistrySharedPtr const& resourceRegistry,
101  std::weak_ptr<HdStShaderCode> const &shaderCode,
102  HdStMaterialNetwork::TextureDescriptorVector const &descs,
103  HdStShaderCode::NamedTextureHandleVector * texturesFromStorm,
104  HdBufferSpecVector * specs,
105  HdBufferSourceSharedPtrVector * sources);
106 
107  bool
108  _GetHasLimitSurfaceEvaluation(VtDictionary const & metadata) const;
109 
110  void _InitFallbackShader();
111 
112  static HioGlslfx *_fallbackGlslfx;
113 
114  HdStSurfaceShaderSharedPtr _surfaceShader;
115 
116  bool _isInitialized : 1;
117  bool _hasPtex : 1;
118  bool _hasLimitSurfaceEvaluation : 1;
119  bool _hasDisplacement : 1;
120 
121  TfToken _materialTag;
122  size_t _textureHash;
123 
124  HdStMaterialNetwork _networkProcessor;
125 };
126 
127 inline bool HdStMaterial::HasPtex() const
128 {
129  return _hasPtex;
130 }
131 
132 inline bool HdStMaterial::HasLimitSurfaceEvaluation() const
133 {
134  return _hasLimitSurfaceEvaluation;
135 }
136 
137 inline bool HdStMaterial::HasDisplacement() const
138 {
139  return _hasDisplacement;
140 }
141 
142 inline const TfToken& HdStMaterial::GetMaterialTag() const
143 {
144  return _materialTag;
145 }
146 
147 PXR_NAMESPACE_CLOSE_SCOPE
148 
149 #endif // PXR_IMAGING_HD_ST_MATERIAL_H
virtual HdDirtyBits GetInitialDirtyBitsMask() const =0
Returns the minimal set of dirty bits to place in the change tracker for use in the first sync of thi...
virtual void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits)=0
Synchronizes state from the delegate to this object.
A map with string keys and VtValue values.
Definition: dictionary.h:63
Helps HdStMaterial process a Hydra material network into shader source code and parameters values...
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
Adapter class providing data exchange with the client scene graph.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:288
A class representing the config and shader source of a glslfx file.
Definition: glslfx.h:148
virtual HD_API void Finalize(HdRenderParam *renderParam)
Finalizes object resources.
Hydra Schema for a material object.
Definition: material.h:37