HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
simpleLightingContext.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_GLF_SIMPLE_LIGHTING_CONTEXT_H
8 #define PXR_IMAGING_GLF_SIMPLE_LIGHTING_CONTEXT_H
9 
10 /// \file glf/simpleLightingContext.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/imaging/glf/api.h"
17 
18 #include "pxr/base/gf/matrix4d.h"
19 #include "pxr/base/gf/vec4f.h"
20 
22 #include "pxr/base/tf/refBase.h"
23 #include "pxr/base/tf/weakBase.h"
24 #include "pxr/base/tf/token.h"
25 
26 #include <memory>
27 
29 
30 
35 
37 public:
39 
40  GLF_API
41  static GlfSimpleLightingContextRefPtr New();
42 
43  GLF_API
44  void SetLights(GlfSimpleLightVector const & lights);
45  GLF_API
46  GlfSimpleLightVector const & GetLights() const;
47 
48  // returns the effective number of lights taken into account
49  // in composable/compatible shader constraints
50  GLF_API
51  int GetNumLightsUsed() const;
52 
53  // returns the number of shadow maps needed, by summing shadow maps
54  // allocated to each light.
55  GLF_API
56  int ComputeNumShadowsUsed() const;
57 
58  GLF_API
59  void SetShadows(GlfSimpleShadowArrayRefPtr const & shadows);
60  GLF_API
61  GlfSimpleShadowArrayRefPtr const & GetShadows() const;
62 
63  GLF_API
64  void SetMaterial(GlfSimpleMaterial const & material);
65  GLF_API
66  GlfSimpleMaterial const & GetMaterial() const;
67 
68  GLF_API
69  void SetSceneAmbient(GfVec4f const & sceneAmbient);
70  GLF_API
71  GfVec4f const & GetSceneAmbient() const;
72 
73  GLF_API
74  void SetCamera(GfMatrix4d const &worldToViewMatrix,
75  GfMatrix4d const &projectionMatrix);
76 
77  GLF_API
78  void SetUseLighting(bool val);
79  GLF_API
80  bool GetUseLighting() const;
81 
82  // returns true if any light has shadow enabled.
83  GLF_API
84  bool GetUseShadows() const;
85 
86  GLF_API
88  GLF_API
89  bool GetUseColorMaterialDiffuse() const;
90 
91  GLF_API
92  void InitUniformBlockBindings(GlfBindingMapPtr const &bindingMap) const;
93  GLF_API
94  void InitSamplerUnitBindings(GlfBindingMapPtr const &bindingMap) const;
95 
96  GLF_API
97  void BindUniformBlocks(GlfBindingMapPtr const &bindingMap);
98  GLF_API
99  void BindSamplers(GlfBindingMapPtr const &bindingMap);
100 
101  GLF_API
102  void UnbindSamplers(GlfBindingMapPtr const &bindingMap);
103 
104  GLF_API
105  void SetStateFromOpenGL();
106 
107  /// \name Post Surface Lighting
108  ///
109  /// This context can provide additional shader source, currently
110  /// used to implement post surface lighting, along with a hash
111  /// to help de-duplicate use by client shader programs.
112  ///
113  /// @{
114 
115  GLF_API
116  size_t ComputeShaderSourceHash();
117 
118  GLF_API
119  std::string const & ComputeShaderSource(TfToken const &shaderStageKey);
120 
121  /// @}
122 
123 protected:
124  GLF_API
126  GLF_API
128 
130  void _BindPostSurfaceShaderParams(GlfBindingMapPtr const &bindingMap);
131 
132 private:
133  GlfSimpleLightVector _lights;
134  GlfSimpleShadowArrayRefPtr _shadows;
135 
136  GfMatrix4d _worldToViewMatrix;
137  GfMatrix4d _projectionMatrix;
138 
139  GlfSimpleMaterial _material;
140  GfVec4f _sceneAmbient;
141 
142  bool _useLighting;
143  bool _useShadows;
144  bool _useColorMaterialDiffuse;
145 
146  GlfUniformBlockRefPtr _lightingUniformBlock;
147  GlfUniformBlockRefPtr _shadowUniformBlock;
148  GlfUniformBlockRefPtr _materialUniformBlock;
149  GlfUniformBlockRefPtr _bindlessShadowlUniformBlock;
150 
151  class _PostSurfaceShaderState;
152  std::unique_ptr<_PostSurfaceShaderState> _postSurfaceShaderState;
153 
154  bool _lightingUniformBlockValid;
155  bool _shadowUniformBlockValid;
156  bool _materialUniformBlockValid;
157  bool _postSurfaceShaderStateValid;
158 };
159 
160 
162 
163 #endif
GLF_API bool GetUseColorMaterialDiffuse() const
#define GLF_API
Definition: api.h:23
GLF_API std::string const & ComputeShaderSource(TfToken const &shaderStageKey)
GLF_API void SetStateFromOpenGL()
GLF_API void BindSamplers(GlfBindingMapPtr const &bindingMap)
GLF_API void InitUniformBlockBindings(GlfBindingMapPtr const &bindingMap) const
GLF_API void SetLights(GlfSimpleLightVector const &lights)
GLF_API void SetMaterial(GlfSimpleMaterial const &material)
GLF_API void SetSceneAmbient(GfVec4f const &sceneAmbient)
GLF_API GfVec4f const & GetSceneAmbient() const
GLF_API int ComputeNumShadowsUsed() const
PXR_NAMESPACE_OPEN_SCOPE TF_DECLARE_WEAK_AND_REF_PTRS(GlfBindingMap)
Definition: token.h:70
GLF_API GlfSimpleLightingContext()
GLF_API size_t ComputeShaderSourceHash()
GlfSimpleLightingContext This
void _BindPostSurfaceShaderParams(GlfBindingMapPtr const &bindingMap)
GLF_API GlfSimpleLightVector const & GetLights() const
GLF_API GlfSimpleShadowArrayRefPtr const & GetShadows() const
GLF_API GlfSimpleMaterial const & GetMaterial() const
GLF_API void InitSamplerUnitBindings(GlfBindingMapPtr const &bindingMap) const
GLF_API bool GetUseLighting() const
GLF_API int GetNumLightsUsed() const
GLF_API void SetUseLighting(bool val)
GLF_API bool GetUseShadows() const
Definition: vec4f.h:45
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
GLF_API void UnbindSamplers(GlfBindingMapPtr const &bindingMap)
GLF_API ~GlfSimpleLightingContext()
GLF_API void BindUniformBlocks(GlfBindingMapPtr const &bindingMap)
GLuint GLfloat * val
Definition: glcorearb.h:1608
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
static GLF_API GlfSimpleLightingContextRefPtr New()
GLF_API void SetShadows(GlfSimpleShadowArrayRefPtr const &shadows)
GLF_API void SetUseColorMaterialDiffuse(bool val)
GLF_API void SetCamera(GfMatrix4d const &worldToViewMatrix, GfMatrix4d const &projectionMatrix)
std::vector< class GlfSimpleLight > GlfSimpleLightVector
Definition: simpleLight.h:254