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/hd/material.h"
31 #include "pxr/imaging/hf/perfLog.h"
32 
33 #include <boost/shared_ptr.hpp>
34 
35 PXR_NAMESPACE_OPEN_SCOPE
36 
37 typedef boost::shared_ptr<class HdStShaderCode> HdStShaderCodeSharedPtr;
38 typedef boost::shared_ptr<class HdStSurfaceShader> HdStSurfaceShaderSharedPtr;
39 typedef boost::shared_ptr<class HdStTextureResource> HdStTextureResourceSharedPtr;
40 typedef boost::shared_ptr<class HdStTextureResourceHandle> HdStTextureResourceHandleSharedPtr;
41 typedef std::vector<HdStTextureResourceHandleSharedPtr>
42  HdStTextureResourceHandleSharedPtrVector;
43 
44 class HioGlslfx;
45 
46 class HdStMaterial final: public HdMaterial {
47 public:
48  HF_MALLOC_TAG_NEW("new HdStMaterial");
49 
50  HDST_API
51  HdStMaterial(SdfPath const& id);
52  HDST_API
53  virtual ~HdStMaterial();
54 
56  HDST_API
57  virtual void Sync(HdSceneDelegate *sceneDelegate,
58  HdRenderParam *renderParam,
59  HdDirtyBits *dirtyBits) override;
60 
64  HDST_API
65  virtual HdDirtyBits GetInitialDirtyBitsMask() const override;
66 
68  HDST_API
69  virtual void Reload() override;
70 
72  HDST_API
73  HdStShaderCodeSharedPtr GetShaderCode() const;
74 
77  inline HdTextureResource::ID GetTextureResourceID(
78  HdSceneDelegate* sceneDelegate,
79  SdfPath const& textureId) const;
80 
85  inline bool HasPtex() const;
86 
88  inline bool HasLimitSurfaceEvaluation() const;
89 
90  // Returns true if the material has a displacement terminal.
91  inline bool HasDisplacement() const;
92 
93  // Returns the material's render pass tag.
94  inline const TfToken& GetMaterialTag() const;
95 
99  HDST_API
100  void SetSurfaceShader(HdStSurfaceShaderSharedPtr &shaderCode);
101 
102 private:
103  HdStTextureResourceHandleSharedPtr
104  _GetTextureResourceHandle(HdSceneDelegate *sceneDelegate,
105  HdMaterialParam const &param);
106 
107  bool
108  _GetHasLimitSurfaceEvaluation(VtDictionary const & metadata) const;
109 
110  void _InitFallbackShader();
111 
112  static HioGlslfx *_fallbackGlslfx;
113 
114  HdStSurfaceShaderSharedPtr _surfaceShader;
115 
116  // Holds fallback textures if a texture cannot be found, but also holds
117  // texture we discovered inside a material network that could not be found
118  // in the resource registry (no Bprim inserted).
119  HdStTextureResourceHandleSharedPtrVector _internalTextureResourceHandles;
120 
121  bool _isInitialized : 1;
122  bool _hasPtex : 1;
123  bool _hasLimitSurfaceEvaluation : 1;
124  bool _hasDisplacement : 1;
125 
126  TfToken _materialTag;
127 
128  HdStMaterialNetwork _networkProcessor;
129 };
130 
131 inline HdTextureResource::ID
132 HdStMaterial::GetTextureResourceID(HdSceneDelegate* sceneDelegate,
133  SdfPath const& textureId) const
134 {
135  return sceneDelegate->GetTextureResourceID(textureId);
136 }
137 
138 inline bool HdStMaterial::HasPtex() const
139 {
140  return _hasPtex;
141 }
142 
143 inline bool HdStMaterial::HasLimitSurfaceEvaluation() const
144 {
145  return _hasLimitSurfaceEvaluation;
146 }
147 
148 inline bool HdStMaterial::HasDisplacement() const
149 {
150  return _hasDisplacement;
151 }
152 
153 inline const TfToken& HdStMaterial::GetMaterialTag() const
154 {
155  return _materialTag;
156 }
157 
158 PXR_NAMESPACE_CLOSE_SCOPE
159 
160 #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:61
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:89
Adapter class providing data exchange with the client scene graph.
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:139
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