simpleLightingShader.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_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"
29 #include "pxr/imaging/hdSt/lightingShader.h"
30 
31 #include "pxr/imaging/hd/binding.h"
32 #include "pxr/imaging/hd/version.h"
33 
36 
37 #include <memory>
38 #include <string>
39 
40 PXR_NAMESPACE_OPEN_SCOPE
41 
42 class HdRenderIndex;
43 class HdRenderParam;
44 class HdSceneDelegate;
45 class HdStRenderBuffer;
47 using HdStSimpleLightingShaderSharedPtr =
48  std::shared_ptr<class HdStSimpleLightingShader>;
49 using HdRenderPassAovBindingVector = std::vector<HdRenderPassAovBinding>;
50 
51 TF_DECLARE_REF_PTRS(GlfBindingMap);
52 
58 {
59 public:
60  HDST_API
62  HDST_API
63  ~HdStSimpleLightingShader() override;
64 
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 
78  HDST_API
79  void AddBufferBinding(HdBindingRequest const& req);
80 
82  HDST_API
83  void RemoveBufferBinding(TfToken const &name);
84 
86  HDST_API
87  void ClearBufferBindings();
88 
89  HDST_API
90  void AddBindings(HdBindingRequestVector *customBindings) override;
91 
94  HDST_API
95  void AddResourcesFromTextures(ResourceContext &ctx) const override;
96 
98  HDST_API
99  HdSt_MaterialParamVector const& GetParams() const override;
100 
102  HDST_API
103  void SetCamera(
104  GfMatrix4d const &worldToViewMatrix,
105  GfMatrix4d const &projectionMatrix) override;
106  HDST_API
107  void SetLightingStateFromOpenGL();
108  HDST_API
109  void SetLightingState(GlfSimpleLightingContextPtr const &lightingContext);
110 
111  GlfSimpleLightingContextRefPtr GetLightingContext() const {
112  return _lightingContext;
113  };
114 
120  HDST_API
121  void AllocateTextureHandles(HdRenderIndex const &renderIndex);
122 
125  const HdStTextureHandleSharedPtr &
127  return _domeLightEnvironmentTextureHandle;
128  }
129 
132  HDST_API
133  NamedTextureHandleVector const &GetNamedTextureHandles() const override;
134 
137  HDST_API
138  const HdStTextureHandleSharedPtr &GetTextureHandle(
139  const TfToken &name) const;
140 
141  HdRenderPassAovBindingVector const& GetShadowAovBindings() {
142  return _shadowAovBindings;
143  }
144 
145 private:
146  SdfPath _GetAovPath(TfToken const &aov, size_t shadowIndex) const;
147  void _ResizeOrCreateBufferForAov(size_t shadowIndex) const;
148  void _CleanupAovBindings();
149 
150  GlfSimpleLightingContextRefPtr _lightingContext;
151  bool _useLighting;
152  std::unique_ptr<class HioGlslfx> _glslfx;
153 
154  TfHashMap<TfToken, HdBindingRequest, TfToken::HashFunctor> _customBuffers;
155 
156  // The environment map used as source for the dome light textures.
157  //
158  // Handle is allocated in AllocateTextureHandles. Actual loading
159  // happens during commit.
160  HdStTextureHandleSharedPtr _domeLightEnvironmentTextureHandle;
161 
162  // Other dome light textures.
163  NamedTextureHandleVector _namedTextureHandles;
164 
165  NamedTextureHandleVector _domeLightTextureHandles;
166  NamedTextureHandleVector _shadowTextureHandles;
167 
168  HdSt_MaterialParamVector _lightTextureParams;
169 
170  HdRenderParam *_renderParam;
171 
172  HdRenderPassAovBindingVector _shadowAovBindings;
173  std::vector<std::unique_ptr<HdStRenderBuffer>> _shadowAovBuffers;
174 };
175 
176 
177 PXR_NAMESPACE_CLOSE_SCOPE
178 
179 #endif // PXR_IMAGING_HDST_SIMPLE_LIGHTING_SHADER_H
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:120
Standard pointer typedefs.
HDST_API void UnbindResources(int program, HdSt_ResourceBinder const &binder) override
Unbinds shader-specific resources.
HDST_API void AllocateTextureHandles(HdRenderIndex const &renderIndex)
Allocates texture handles (texture loading happens later during commit) needed for lights.
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
HDST_API void BindResources(int program, HdSt_ResourceBinder const &binder) override
Binds shader-specific resources to program XXX: this interface is meant to be used for bridging the G...
HDST_API void RemoveBufferBinding(TfToken const &name)
Remove name from custom binding.
const HdStTextureHandleSharedPtr & GetDomeLightEnvironmentTextureHandle() const
The dome light environment map used as source for the other dome light textures.
A shader that supports simple lighting functionality.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
HDST_API void AddBufferBinding(HdBindingRequest const &req)
Add a custom binding request for use when this shader executes.
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Adapter class providing data exchange with the client scene graph.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
HDST_API ID ComputeHash() const override
HdShader overrides.
A renderpass AOV represents a binding of some output of the rendering process to an output buffer.
Definition: aov.h:117
HDST_API void SetCamera(GfMatrix4d const &worldToViewMatrix, GfMatrix4d const &projectionMatrix) override
HdStLightingShader overrides.
HDST_API void ClearBufferBindings()
Clear all custom bindings associated with this shader.
The context available in implementations of AddResourcesFromTextures.
Definition: shaderCode.h:200
HDST_API const HdStTextureHandleSharedPtr & GetTextureHandle(const TfToken &name) const
Get one of the textures that need to be computed from the dome light environment map.
HDST_API std::string GetSource(TfToken const &shaderStageKey) const override
Returns the shader source provided by this shader for shaderStageKey.
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:75
A lighting shader base class.
BindingRequest allows externally allocated buffers to be bound at render time.
Definition: binding.h:127
HDST_API NamedTextureHandleVector const & GetNamedTextureHandles() const override
The textures computed from the dome light environment map that the shader needs to bind for the dome ...
HDST_API HdSt_MaterialParamVector const & GetParams() const override
HdStShaderCode overrides.
HDST_API void AddResourcesFromTextures(ResourceContext &ctx) const override
Adds computations to create the dome light textures that are pre-calculated from the environment map ...
HDST_API void AddBindings(HdBindingRequestVector *customBindings) override
Add custom bindings (used by codegen)