Loading...
Searching...
No Matches
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
11
12#include "pxr/pxr.h"
13#include "pxr/imaging/glf/api.h"
17
19#include "pxr/base/gf/vec4f.h"
20
22#include "pxr/base/tf/refBase.h"
24#include "pxr/base/tf/token.h"
25
26#include "pxr/base/vt/array.h"
27
28#include <memory>
29
30PXR_NAMESPACE_OPEN_SCOPE
31
32
33TF_DECLARE_WEAK_AND_REF_PTRS(GlfSimpleLightingContext);
34TF_DECLARE_WEAK_AND_REF_PTRS(GlfSimpleShadowArray);
35
36class GlfSimpleLightingContext : public TfRefBase, public TfWeakBase {
37public:
38 typedef GlfSimpleLightingContext This;
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
87 void SetUseColorMaterialDiffuse(bool val);
88 GLF_API
89 bool GetUseColorMaterialDiffuse() const;
90
91 GLF_API
92 void SetStateFromOpenGL();
93
101
102 GLF_API
103 size_t ComputeShaderSourceHash();
104
105 GLF_API
106 std::string const & ComputeShaderSource(TfToken const &shaderStageKey);
107
109
110protected:
111 GLF_API
112 GlfSimpleLightingContext();
113 GLF_API
114 ~GlfSimpleLightingContext();
115
116 void _ComputePostSurfaceShaderState();
117
118 GlfSimpleLightVector _lights;
119 GlfSimpleShadowArrayRefPtr _shadows;
120
121 GfMatrix4d _worldToViewMatrix;
122 GfMatrix4d _projectionMatrix;
123
124 GlfSimpleMaterial _material;
125 GfVec4f _sceneAmbient;
126
127 bool _useLighting;
128 bool _useShadows;
129 bool _useColorMaterialDiffuse;
130
131 class _PostSurfaceShaderState {
132 public:
133 _PostSurfaceShaderState(size_t hash, GlfSimpleLightVector const & lights)
134 : _hash(hash)
135 {
136 _Init(lights);
137 }
138
139 std::string const & GetShaderSource() const {
140 return _shaderSource;
141 }
142
143 VtUCharArray const & GetUniformData() const {
144 return _uniformData;
145 }
146
147 size_t GetHash() const {
148 return _hash;
149 }
150
151 private:
152 void _Init(GlfSimpleLightVector const & lights);
153
154 std::string _shaderSource;
155 VtUCharArray _uniformData;
156 size_t _hash;
157 };
158 std::unique_ptr<_PostSurfaceShaderState> _postSurfaceShaderState;
159
160 bool _lightingUniformBlockValid;
161 bool _shadowUniformBlockValid;
162 bool _materialUniformBlockValid;
163 bool _postSurfaceShaderStateValid;
164};
165
166
167PXR_NAMESPACE_CLOSE_SCOPE
168
169#endif
Stores a 4x4 matrix of double elements.
Definition matrix4d.h:71
Basic type for a vector of 4 float components.
Definition vec4f.h:48
Enable a concrete base class for use with TfRefPtr.
Definition refBase.h:56
Token for efficient comparison, assignment, and hashing of known strings.
Definition token.h:81
Enable a concrete base class for use with TfWeakPtr.
Definition weakBase.h:124
Standard pointer typedefs.
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition declarePtrs.h:72
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...