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 HDST_MATERIAL_H
25 #define HDST_MATERIAL_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdSt/api.h"
29 #include "pxr/imaging/hd/material.h"
30 #include "pxr/imaging/hf/perfLog.h"
31 
32 #include <boost/shared_ptr.hpp>
33 
34 PXR_NAMESPACE_OPEN_SCOPE
35 
36 typedef boost::shared_ptr<class HdStShaderCode> HdStShaderCodeSharedPtr;
37 typedef boost::shared_ptr<class HdStSurfaceShader> HdStSurfaceShaderSharedPtr;
38 typedef boost::shared_ptr<class HdStTextureResource> HdStTextureResourceSharedPtr;
39 typedef boost::shared_ptr<class HdStTextureResourceHandle> HdStTextureResourceHandleSharedPtr;
40 typedef std::vector<HdStTextureResourceHandleSharedPtr>
41  HdStTextureResourceHandleSharedPtrVector;
42 
43 class HioGlslfx;
44 
45 class HdStMaterial final: public HdMaterial {
46 public:
47  HF_MALLOC_TAG_NEW("new HdStMaterial");
48 
49  HDST_API
50  HdStMaterial(SdfPath const& id);
51  HDST_API
52  virtual ~HdStMaterial();
53 
55  HDST_API
56  virtual void Sync(HdSceneDelegate *sceneDelegate,
57  HdRenderParam *renderParam,
58  HdDirtyBits *dirtyBits) override;
59 
63  HDST_API
64  virtual HdDirtyBits GetInitialDirtyBitsMask() const override;
65 
67  HDST_API
68  virtual void Reload() override;
69 
71  HDST_API
72  HdStShaderCodeSharedPtr GetShaderCode() const;
73 
76  inline std::string GetSurfaceShaderSource(
77  HdSceneDelegate* sceneDelegate) const;
78 
81  inline std::string GetDisplacementShaderSource(
82  HdSceneDelegate* sceneDelegate) const;
83 
86  inline HdMaterialParamVector GetMaterialParams(
87  HdSceneDelegate* sceneDelegate) const;
88 
91  inline VtValue GetMaterialParamValue(HdSceneDelegate* sceneDelegate,
92  TfToken const &paramName) const;
93 
95  inline VtDictionary GetMaterialMetadata(
96  HdSceneDelegate* sceneDelegate) const;
97 
100  inline HdTextureResource::ID GetTextureResourceID(
101  HdSceneDelegate* sceneDelegate,
102  SdfPath const& textureId) const;
103 
108  inline bool HasPtex() const;
109 
111  inline bool HasLimitSurfaceEvaluation() const;
112 
113  // Returns true if the material has a displacement terminal.
114  inline bool HasDisplacement() const;
115 
116  // Returns the material's render pass tag.
117  inline const TfToken& GetMaterialTag() const;
118 
122  HDST_API
123  void SetSurfaceShader(HdStSurfaceShaderSharedPtr &shaderCode);
124 
125 private:
126  HdStTextureResourceHandleSharedPtr
127  _GetTextureResourceHandle(HdSceneDelegate *sceneDelegate,
128  HdMaterialParam const &param);
129 
130  bool
131  _GetHasLimitSurfaceEvaluation(VtDictionary const & metadata) const;
132 
133  TfToken _GetMaterialTagDeprecated(VtDictionary const & metadata) const;
134 
135  void _InitFallbackShader();
136 
137  // Obtain the material network resources of this material.
138  HdMaterialNetworkMap const& _GetMaterialResource(
139  HdSceneDelegate* sceneDelegate) const;
140 
141  static HioGlslfx *_fallbackSurfaceShader;
142 
143  HdStSurfaceShaderSharedPtr _surfaceShader;
144  HdStTextureResourceHandleSharedPtrVector _fallbackTextureResourceHandles;
145 
146  bool _isInitialized : 1;
147  bool _hasPtex : 1;
148  bool _hasLimitSurfaceEvaluation : 1;
149  bool _hasDisplacement : 1;
150 
151  TfToken _materialTag;
152 };
153 
154 inline std::string
155 HdStMaterial::GetSurfaceShaderSource(HdSceneDelegate* sceneDelegate) const
156 {
157  return sceneDelegate->GetSurfaceShaderSource(GetId());
158 }
159 
160 inline std::string
161 HdStMaterial::GetDisplacementShaderSource(HdSceneDelegate* sceneDelegate) const
162 {
163  return sceneDelegate->GetDisplacementShaderSource(GetId());
164 }
165 
166 inline HdMaterialParamVector
167 HdStMaterial::GetMaterialParams(HdSceneDelegate* sceneDelegate) const
168 {
169  return sceneDelegate->GetMaterialParams(GetId());
170 }
171 
172 inline VtValue
173 HdStMaterial::GetMaterialParamValue(HdSceneDelegate* sceneDelegate,
174  TfToken const &paramName) const
175 {
176  return sceneDelegate->GetMaterialParamValue(GetId(), paramName);
177 }
178 
179 inline VtDictionary
180 HdStMaterial::GetMaterialMetadata(HdSceneDelegate* sceneDelegate) const
181 {
182  return sceneDelegate->GetMaterialMetadata(GetId());
183 }
184 
185 inline HdTextureResource::ID
186 HdStMaterial::GetTextureResourceID(HdSceneDelegate* sceneDelegate,
187  SdfPath const& textureId) const
188 {
189  return sceneDelegate->GetTextureResourceID(textureId);
190 }
191 
192 inline bool HdStMaterial::HasPtex() const
193 {
194  return _hasPtex;
195 }
196 
197 inline bool HdStMaterial::HasLimitSurfaceEvaluation() const
198 {
199  return _hasLimitSurfaceEvaluation;
200 }
201 
202 inline bool HdStMaterial::HasDisplacement() const
203 {
204  return _hasDisplacement;
205 }
206 
207 inline const TfToken& HdStMaterial::GetMaterialTag() const
208 {
209  return _materialTag;
210 }
211 
212 PXR_NAMESPACE_CLOSE_SCOPE
213 
214 #endif // HDST_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 HD_API std::string GetSurfaceShaderSource(SdfPath const &materialId)
Returns the surface shader source code for the given material ID.
virtual HD_API HdMaterialParamVector GetMaterialParams(SdfPath const &materialId)
Returns the material params for the given material ID.
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:61
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:89
Adapter class providing data exchange with the client scene graph.
virtual HD_API std::string GetDisplacementShaderSource(SdfPath const &materialId)
Returns the displacement shader source code for the given material ID.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
A class representing the config and shader source of a glslfx file.
Definition: glslfx.h:125
virtual HD_API VtValue GetMaterialParamValue(SdfPath const &materialId, TfToken const &paramName)
Returns a single value for the given material and named parameter.
virtual HD_API HdTextureResource::ID GetTextureResourceID(SdfPath const &textureId)
Returns the texture resource ID for a given texture ID.
virtual void Reload()=0
Causes the shader to be reloaded.
Hydra Schema for a material object.
Definition: material.h:37
Describes a map from network type to network.
Definition: material.h:129
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:182