All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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/version.h"
32 
35 
36 #include <memory>
37 #include <string>
38 
39 PXR_NAMESPACE_OPEN_SCOPE
40 
41 class HdSceneDelegate;
42 using HdStSimpleLightingShaderSharedPtr =
43  std::shared_ptr<class HdStSimpleLightingShader>;
44 TF_DECLARE_REF_PTRS(GlfBindingMap);
45 
51 {
52 public:
53  HDST_API
55  HDST_API
56  ~HdStSimpleLightingShader() override;
57 
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 
76  HDST_API
77  void AddResourcesFromTextures(ResourceContext &ctx) const override;
78 
80  HDST_API
81  HdSt_MaterialParamVector const& GetParams() const override;
82 
84  HDST_API
85  void SetCamera(
86  GfMatrix4d const &worldToViewMatrix,
87  GfMatrix4d const &projectionMatrix) override;
88  HDST_API
89  void SetLightingStateFromOpenGL();
90  HDST_API
91  void SetLightingState(GlfSimpleLightingContextPtr const &lightingContext);
92 
93  GlfSimpleLightingContextRefPtr GetLightingContext() const {
94  return _lightingContext;
95  };
96 
102  HDST_API
103  void AllocateTextureHandles(HdSceneDelegate *delegate);
104 
107  const HdStTextureHandleSharedPtr &
109  return _domeLightEnvironmentTextureHandle;
110  }
111 
114  HDST_API
115  NamedTextureHandleVector const &GetNamedTextureHandles() const override;
116 
119  HDST_API
120  const HdStTextureHandleSharedPtr &GetTextureHandle(
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 
142 PXR_NAMESPACE_CLOSE_SCOPE
143 
144 #endif // PXR_IMAGING_HDST_SIMPLE_LIGHTING_SHADER_H
Standard pointer typedefs.
HDST_API void BindResources(int program, HdSt_ResourceBinder const &binder, HdRenderPassState const &state) override
Binds shader-specific resources to program XXX: this interface is meant to be used for bridging the G...
A set of rendering parameters used among render passes.
A shader that supports simple lighting functionality.
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.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
const HdStTextureHandleSharedPtr & GetDomeLightEnvironmentTextureHandle() const
The dome light environment map used as source for the other dome light textures.
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
HDST_API void UnbindResources(int program, HdSt_ResourceBinder const &binder, HdRenderPassState const &state) override
Unbinds shader-specific resources.
Adapter class providing data exchange with the client scene graph.
HDST_API ID ComputeHash() const override
HdShader overrides.
HDST_API void SetCamera(GfMatrix4d const &worldToViewMatrix, GfMatrix4d const &projectionMatrix) override
HdStLightingShader overrides.
The context available in implementations of AddResourcesFromTextures.
Definition: shaderCode.h:196
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.
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 void AllocateTextureHandles(HdSceneDelegate *delegate)
Allocates texture handles (texture loading happens later during commit) needed for lights...
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)