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"
30 
31 #include "pxr/imaging/hd/version.h"
32 
35 
36 #include <memory>
37 #include <string>
38 
40 
41 class HdSceneDelegate;
43  std::shared_ptr<class HdStSimpleLightingShader>;
45 
46 /// \class HdStSimpleLightingShader
47 ///
48 /// A shader that supports simple lighting functionality.
49 ///
51 {
52 public:
53  HDST_API
55  HDST_API
56  ~HdStSimpleLightingShader() override;
57 
58  /// HdShader overrides
59  HDST_API
60  ID ComputeHash() const override;
61  HDST_API
62  std::string GetSource(TfToken const &shaderStageKey) const override;
63  HDST_API
64  void BindResources(int program,
65  HdSt_ResourceBinder const &binder,
66  HdRenderPassState const &state) override;
67  HDST_API
68  void UnbindResources(int program,
69  HdSt_ResourceBinder const &binder,
70  HdRenderPassState const &state) override;
71  HDST_API
72  void AddBindings(HdBindingRequestVector *customBindings) override;
73 
74  /// Adds computations to create the dome light textures that
75  /// are pre-calculated from the environment map texture.
76  HDST_API
77  void AddResourcesFromTextures(ResourceContext &ctx) const override;
78 
79  /// HdStShaderCode overrides
80  HDST_API
81  HdSt_MaterialParamVector const& GetParams() const override;
82 
83  /// HdStLightingShader overrides
84  HDST_API
85  void SetCamera(
86  GfMatrix4d const &worldToViewMatrix,
87  GfMatrix4d const &projectionMatrix) override;
88  HDST_API
90  HDST_API
91  void SetLightingState(GlfSimpleLightingContextPtr const &lightingContext);
92 
93  GlfSimpleLightingContextRefPtr GetLightingContext() const {
94  return _lightingContext;
95  };
96 
97  /// Allocates texture handles (texture loading happens later during commit)
98  /// needed for lights.
99  ///
100  /// Call after lighting context has been set or updated in Sync-phase.
101  ///
102  HDST_API
103  void AllocateTextureHandles(HdSceneDelegate *delegate);
104 
105  /// The dome light environment map used as source for the other
106  /// dome light textures.
109  return _domeLightEnvironmentTextureHandle;
110  }
111 
112  /// The textures computed from the dome light environment map that
113  /// the shader needs to bind for the dome light shading.
114  HDST_API
115  NamedTextureHandleVector const &GetNamedTextureHandles() const override;
116 
117  /// Get one of the textures that need to be computed from the dome
118  /// light environment map.
119  HDST_API
121  const TfToken &name) const;
122 
123 private:
124  GlfSimpleLightingContextRefPtr _lightingContext;
125  GlfBindingMapRefPtr _bindingMap;
126  bool _useLighting;
127  std::unique_ptr<class HioGlslfx> _glslfx;
128 
129  // The environment map used as source for the dome light textures.
130  //
131  // Handle is allocated in AllocateTextureHandles. Actual loading
132  // happens during commit.
133  HdStTextureHandleSharedPtr _domeLightEnvironmentTextureHandle;
134 
135  // Other dome light textures.
136  NamedTextureHandleVector _namedTextureHandles;
137 
138  HdSt_MaterialParamVector _lightTextureParams;
139 };
140 
141 
143 
144 #endif // PXR_IMAGING_HDST_SIMPLE_LIGHTING_SHADER_H
const HdStTextureHandleSharedPtr & GetDomeLightEnvironmentTextureHandle() const
HDST_API void SetLightingState(GlfSimpleLightingContextPtr const &lightingContext)
GLuint const GLchar * name
Definition: glew.h:1814
GlfSimpleLightingContextRefPtr GetLightingContext() const
HDST_API ID ComputeHash() const override
HdShader overrides.
Definition: token.h:87
HDST_API void BindResources(int program, HdSt_ResourceBinder const &binder, HdRenderPassState const &state) override
HDST_API std::string GetSource(TfToken const &shaderStageKey) const override
HDST_API HdSt_MaterialParamVector const & GetParams() const override
HdStShaderCode overrides.
HDST_API NamedTextureHandleVector const & GetNamedTextureHandles() const override
HDST_API void AllocateTextureHandles(HdSceneDelegate *delegate)
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
GLsizei const GLchar *const * string
Definition: glew.h:1844
HDST_API void UnbindResources(int program, HdSt_ResourceBinder const &binder, HdRenderPassState const &state) override
Unbinds shader-specific resources.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
std::vector< NamedTextureHandle > NamedTextureHandleVector
Definition: shaderCode.h:186
std::shared_ptr< class HdStTextureHandle > HdStTextureHandleSharedPtr
#define HDST_API
Definition: api.h:40
HDST_API void SetLightingStateFromOpenGL()
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
HDST_API const HdStTextureHandleSharedPtr & GetTextureHandle(const TfToken &name) const
TF_DECLARE_REF_PTRS(GlfBindingMap)
HDST_API void AddBindings(HdBindingRequestVector *customBindings) override
Add custom bindings (used by codegen)
GLuint program
Definition: glew.h:5881
std::vector< class HdSt_MaterialParam > HdSt_MaterialParamVector
HDST_API HdStSimpleLightingShader()
std::vector< class HdBindingRequest > HdBindingRequestVector
Definition: binding.h:39