HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
simpleLightingShader.h
Go to the documentation of this file.
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_HDST_SIMPLE_LIGHTING_SHADER_H
25 #define PXR_IMAGING_HDST_SIMPLE_LIGHTING_SHADER_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdSt/api.h"
31 
32 #include "pxr/imaging/hd/version.h"
33 
36 
37 #include <memory>
38 #include <string>
39 
41 
42 class HdRenderIndex;
43 class HdRenderParam;
44 class HdSceneDelegate;
45 class HdStRenderBuffer;
48  std::shared_ptr<class HdStSimpleLightingShader>;
49 using HdRenderPassAovBindingVector = std::vector<HdRenderPassAovBinding>;
50 
52 
53 /// \class HdStSimpleLightingShader
54 ///
55 /// A shader that supports simple lighting functionality.
56 ///
58 {
59 public:
60  HDST_API
62  HDST_API
63  ~HdStSimpleLightingShader() override;
64 
65  /// HdShader overrides
66  HDST_API
67  ID ComputeHash() const override;
68  HDST_API
69  std::string GetSource(TfToken const &shaderStageKey) const override;
70  HDST_API
71  void BindResources(int program,
72  HdSt_ResourceBinder const &binder) override;
73  HDST_API
74  void UnbindResources(int program,
75  HdSt_ResourceBinder const &binder) override;
76 
77  /// Add a custom binding request for use when this shader executes.
78  HDST_API
79  void AddBufferBinding(HdStBindingRequest const& req);
80 
81  /// Remove \p name from custom binding.
82  HDST_API
83  void RemoveBufferBinding(TfToken const &name);
84 
85  /// Clear all custom bindings associated with this shader.
86  HDST_API
87  void ClearBufferBindings();
88 
89  HDST_API
90  void AddBindings(HdStBindingRequestVector *customBindings) override;
91 
92  /// Adds computations to create the dome light textures that
93  /// are pre-calculated from the environment map texture.
94  HDST_API
95  void AddResourcesFromTextures(ResourceContext &ctx) const override;
96 
97  /// HdStShaderCode overrides
98  HDST_API
99  HdSt_MaterialParamVector const& GetParams() const override;
100 
101  /// HdStLightingShader overrides
102  HDST_API
103  void SetCamera(
104  GfMatrix4d const &worldToViewMatrix,
105  GfMatrix4d const &projectionMatrix) override;
106 
107  GlfSimpleLightingContextRefPtr GetLightingContext() const {
108  return _lightingContext;
109  };
110 
111  /// Allocates texture handles (texture loading happens later during commit)
112  /// needed for lights.
113  ///
114  /// Call after lighting context has been set or updated in Sync-phase.
115  ///
116  HDST_API
117  void AllocateTextureHandles(HdRenderIndex const &renderIndex);
118 
119  /// The dome light environment map used as source for the other
120  /// dome light textures.
123  return _domeLightEnvironmentTextureHandle;
124  }
125 
126  /// The textures computed from the dome light environment map that
127  /// the shader needs to bind for the dome light shading.
128  HDST_API
129  NamedTextureHandleVector const &GetNamedTextureHandles() const override;
130 
131  /// Get one of the textures that need to be computed from the dome
132  /// light environment map.
133  HDST_API
135  const TfToken &name) const;
136 
138  return _shadowAovBindings;
139  }
140 
141 private:
142  SdfPath _GetAovPath(TfToken const &aov, size_t shadowIndex) const;
143  void _ResizeOrCreateBufferForAov(size_t shadowIndex) const;
144  void _CleanupAovBindings();
145 
146  GlfSimpleLightingContextRefPtr _lightingContext;
147  bool _useLighting;
148  std::unique_ptr<class HioGlslfx> _glslfx;
149 
150  // Lexicographic ordering for stable output between runs.
151  std::map<TfToken, HdStBindingRequest> _customBuffers;
152 
153  // The environment map used as source for the dome light textures.
154  //
155  // Handle is allocated in AllocateTextureHandles. Actual loading
156  // happens during commit.
157  HdStTextureHandleSharedPtr _domeLightEnvironmentTextureHandle;
158 
159  // Other dome light textures.
160  NamedTextureHandleVector _namedTextureHandles;
161 
162  NamedTextureHandleVector _domeLightTextureHandles;
163  NamedTextureHandleVector _shadowTextureHandles;
164 
165  HdSt_MaterialParamVector _lightTextureParams;
166 
167  HdRenderParam *_renderParam;
168 
169  HdRenderPassAovBindingVector _shadowAovBindings;
170  std::vector<std::unique_ptr<HdStRenderBuffer>> _shadowAovBuffers;
171 };
172 
173 
175 
176 #endif // PXR_IMAGING_HDST_SIMPLE_LIGHTING_SHADER_H
const HdStTextureHandleSharedPtr & GetDomeLightEnvironmentTextureHandle() const
GlfSimpleLightingContextRefPtr GetLightingContext() const
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
HDST_API void UnbindResources(int program, HdSt_ResourceBinder const &binder) override
Unbinds shader-specific resources.
HDST_API void AllocateTextureHandles(HdRenderIndex const &renderIndex)
std::vector< class HdStBindingRequest > HdStBindingRequestVector
Definition: binding.h:40
HDST_API void BindResources(int program, HdSt_ResourceBinder const &binder) override
HDST_API ID ComputeHash() const override
HdShader overrides.
Definition: token.h:87
HDST_API std::string GetSource(TfToken const &shaderStageKey) const override
HdRenderPassAovBindingVector const & GetShadowAovBindings()
HDST_API HdSt_MaterialParamVector const & GetParams() const override
HdStShaderCode overrides.
HDST_API NamedTextureHandleVector const & GetNamedTextureHandles() const override
GLuint const GLchar * name
Definition: glcorearb.h:786
Definition: path.h:290
std::shared_ptr< class HdStSimpleLightingShader > HdStSimpleLightingShaderSharedPtr
HDST_API void AddResourcesFromTextures(ResourceContext &ctx) const override
HDST_API void SetCamera(GfMatrix4d const &worldToViewMatrix, GfMatrix4d const &projectionMatrix) override
HdStLightingShader overrides.
HDST_API ~HdStSimpleLightingShader() override
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
std::vector< NamedTextureHandle > NamedTextureHandleVector
Definition: shaderCode.h:160
std::shared_ptr< class HdStTextureHandle > HdStTextureHandleSharedPtr
#define HDST_API
Definition: api.h:40
HDST_API void AddBufferBinding(HdStBindingRequest const &req)
Add a custom binding request for use when this shader executes.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
HDST_API const HdStTextureHandleSharedPtr & GetTextureHandle(const TfToken &name) const
HDST_API void RemoveBufferBinding(TfToken const &name)
Remove name from custom binding.
TF_DECLARE_REF_PTRS(GlfBindingMap)
HDST_API void ClearBufferBindings()
Clear all custom bindings associated with this shader.
std::vector< HdRenderPassAovBinding > HdRenderPassAovBindingVector
Definition: aov.h:154
GLbitfield GLuint program
Definition: glcorearb.h:1931
HDST_API void AddBindings(HdStBindingRequestVector *customBindings) override
Add custom bindings (used by codegen)
std::vector< class HdSt_MaterialParam > HdSt_MaterialParamVector
HDST_API HdStSimpleLightingShader()