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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_HDST_SIMPLE_LIGHTING_SHADER_H
8 #define PXR_IMAGING_HDST_SIMPLE_LIGHTING_SHADER_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hdSt/api.h"
14 
15 #include "pxr/imaging/hd/version.h"
16 
19 
20 #include <memory>
21 #include <string>
22 
24 
25 class HdRenderIndex;
26 class HdRenderParam;
27 class HdSceneDelegate;
28 class HdStRenderBuffer;
31  std::shared_ptr<class HdStSimpleLightingShader>;
32 using HdRenderPassAovBindingVector = std::vector<HdRenderPassAovBinding>;
33 
35 
36 /// \class HdStSimpleLightingShader
37 ///
38 /// A shader that supports simple lighting functionality.
39 ///
41 {
42 public:
43  HDST_API
45  HDST_API
46  ~HdStSimpleLightingShader() override;
47 
48  /// HdShader overrides
49  HDST_API
50  ID ComputeHash() const override;
51  HDST_API
52  std::string GetSource(TfToken const &shaderStageKey) const override;
53  HDST_API
54  void BindResources(int program,
55  HdSt_ResourceBinder const &binder) override;
56  HDST_API
57  void UnbindResources(int program,
58  HdSt_ResourceBinder const &binder) override;
59 
60  /// Add a custom binding request for use when this shader executes.
61  HDST_API
62  void AddBufferBinding(HdStBindingRequest const& req);
63 
64  /// Remove \p name from custom binding.
65  HDST_API
66  void RemoveBufferBinding(TfToken const &name);
67 
68  /// Clear all custom bindings associated with this shader.
69  HDST_API
70  void ClearBufferBindings();
71 
72  HDST_API
73  void AddBindings(HdStBindingRequestVector *customBindings) override;
74 
75  /// Adds computations to create the dome light textures that
76  /// are pre-calculated from the environment map texture.
77  HDST_API
78  void AddResourcesFromTextures(ResourceContext &ctx) const override;
79 
80  /// HdStShaderCode overrides
81  HDST_API
82  HdSt_MaterialParamVector const& GetParams() const override;
83 
84  /// HdStLightingShader overrides
85  HDST_API
86  void SetCamera(
87  GfMatrix4d const &worldToViewMatrix,
88  GfMatrix4d const &projectionMatrix) override;
89 
90  GlfSimpleLightingContextRefPtr GetLightingContext() const {
91  return _lightingContext;
92  };
93 
94  /// Allocates texture handles (texture loading happens later during commit)
95  /// needed for lights.
96  ///
97  /// Call after lighting context has been set or updated in Sync-phase.
98  ///
99  HDST_API
100  void AllocateTextureHandles(HdRenderIndex const &renderIndex);
101 
102  /// The dome light environment map used as source for the other
103  /// dome light textures.
106  return _domeLightEnvironmentTextureHandle;
107  }
108 
109  /// The textures computed from the dome light environment map that
110  /// the shader needs to bind for the dome light shading.
111  HDST_API
112  NamedTextureHandleVector const &GetNamedTextureHandles() const override;
113 
114  /// Get one of the textures that need to be computed from the dome
115  /// light environment map.
116  HDST_API
118  const TfToken &name) const;
119 
121  return _shadowAovBindings;
122  }
123 
124 private:
125  SdfPath _GetAovPath(TfToken const &aov, size_t shadowIndex) const;
126  void _ResizeOrCreateBufferForAov(size_t shadowIndex) const;
127  void _CleanupAovBindings();
128 
129  GlfSimpleLightingContextRefPtr _lightingContext;
130  bool _useLighting;
131  std::unique_ptr<class HioGlslfx> _glslfx;
132 
133  // Lexicographic ordering for stable output between runs.
134  std::map<TfToken, HdStBindingRequest> _customBuffers;
135 
136  // The environment map used as source for the dome light textures.
137  //
138  // Handle is allocated in AllocateTextureHandles. Actual loading
139  // happens during commit.
140  HdStTextureHandleSharedPtr _domeLightEnvironmentTextureHandle;
141 
142  // Other dome light textures.
143  NamedTextureHandleVector _namedTextureHandles;
144 
145  NamedTextureHandleVector _domeLightTextureHandles;
146  NamedTextureHandleVector _shadowTextureHandles;
147 
148  HdSt_MaterialParamVector _lightTextureParams;
149 
150  HdRenderParam *_renderParam;
151 
152  HdRenderPassAovBindingVector _shadowAovBindings;
153  std::vector<std::unique_ptr<HdStRenderBuffer>> _shadowAovBuffers;
154 };
155 
156 
158 
159 #endif // PXR_IMAGING_HDST_SIMPLE_LIGHTING_SHADER_H
const HdStTextureHandleSharedPtr & GetDomeLightEnvironmentTextureHandle() const
GlfSimpleLightingContextRefPtr GetLightingContext() const
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:23
HDST_API void BindResources(int program, HdSt_ResourceBinder const &binder) override
HDST_API ID ComputeHash() const override
HdShader overrides.
Definition: token.h:70
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:273
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:1425
std::vector< NamedTextureHandle > NamedTextureHandleVector
Definition: shaderCode.h:144
std::shared_ptr< class HdStTextureHandle > HdStTextureHandleSharedPtr
#define HDST_API
Definition: api.h:23
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:74
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:137
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()