Nebula
Loading...
Searching...
No Matches
lightcontext.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
9//------------------------------------------------------------------------------
11#include "coregraphics/shader.h"
12#include "coregraphics/buffer.h"
14#include <array>
15//#include <render/system_shaders/lights_cluster.h>
16#include "gpulang/render/system_shaders/lights_cluster.h"
17
18
19namespace Frame
20{
21class FrameScript;
22};
23
24namespace Lighting
25{
27{
29public:
30
38
39 enum class AreaLightShape
40 {
44 };
45
49 virtual ~LightContext();
50
52 static void Create();
54 static void Discard();
55
57 static void SetupGlobalLight(const Graphics::GraphicsEntityId id, const Math::vec3& color, const float intensity, const Math::vec3& ambient, const float zenith, const float azimuth, bool castShadows = false);
59 static void SetupPointLight(
61 , const Math::vec3& color
62 , const float intensity
63 , const float range
64 , bool castShadows = false
65 , const CoreGraphics::TextureId projection = CoreGraphics::InvalidTextureId
66 );
67
69 static void SetupSpotLight(
71 , const Math::vec3& color
72 , const float intensity
73 , const float innerConeAngle
74 , const float outerConeAngle
75 , const float range
76 , bool castShadows = false
77 , const CoreGraphics::TextureId projection = CoreGraphics::InvalidTextureId
78 );
79
81 static void SetupAreaLight(
83 , const AreaLightShape shape
84 , const Math::vec3& color
85 , const float intensity
86 , const float range
87 , bool twoSided = false
88 , bool castShadows = false
89 , bool renderMesh = false
90 );
91
93 static void SetColor(const Graphics::GraphicsEntityId id, const Math::vec3& color);
97 static void SetRange(const Graphics::GraphicsEntityId id, const float range);
99 static void SetIntensity(const Graphics::GraphicsEntityId id, const float intensity);
101 static float GetIntensity(const Graphics::GraphicsEntityId id);
103 static void SetTransform(const Graphics::GraphicsEntityId id, const float azimuth, const float zenith);
108
110 static const void SetPosition(const Graphics::GraphicsEntityId id, const Math::point& position);
114 static const void SetRotation(const Graphics::GraphicsEntityId id, const Math::quat& rotation);
118 static const void SetScale(const Graphics::GraphicsEntityId id, const Math::vec3& scale);
120 static const Math::vec3 GetScale(const Graphics::GraphicsEntityId id);
121
125 static void SetAmbient(const Graphics::GraphicsEntityId id, Math::vec3& ambient);
126
129
131 static void GetInnerOuterAngle(const Graphics::GraphicsEntityId id, float& inner, float& outer);
133 static void SetInnerOuterAngle(const Graphics::GraphicsEntityId id, float inner, float outer);
134
136 static void OnPrepareView(const Ptr<Graphics::View>& view, const Graphics::FrameContext& ctx);
137
143 static void WindowResized(const CoreGraphics::WindowId windowId, SizeT width, SizeT height);
144#ifndef PUBLIC_BUILD
146 static void OnRenderDebug(uint32_t flags);
147#endif
148
150 static void SetupTerrainShadows(const CoreGraphics::TextureId terrainShadowMap, const uint worldSize);
151
157 static const LightsCluster::LightUniforms::STRUCT& GetLightUniforms();
158
159private:
160
162 static void SetGlobalLightTransform(const Graphics::ContextEntityId id, const Math::mat4& transform, const Math::vector& direction);
164 static void SetGlobalLightViewProjTransform(const Graphics::ContextEntityId id, const Math::mat4& transform);
165
166 enum
167 {
174 };
175
176 typedef Ids::IdAllocator<
177 LightType, // type
178 Math::vec3, // color
179 float, // intensity
180 bool, // shadow caster
181 float,
182 Ids::Id32 // typed light id (index into pointlights, spotlights and globallights)
185
187 {
189 };
190
191 enum
192 {
199 };
200
201 typedef Ids::IdAllocator<
202 Math::transform44, // transform
203 ConstantBufferSet, // constant buffer binding for light
204 ConstantBufferSet, // constant buffer binding for shadows
205 Util::FixedArray<uint>, // dynamic offsets
206 CoreGraphics::TextureId, // projection (if invalid, don't use)
207 Graphics::GraphicsEntityId // graphics entity used for observer stuff
210
211 enum
212 {
221 };
222
223 typedef Ids::IdAllocator<
224 Math::transform44, // transform
225 ConstantBufferSet, // constant buffer binding for light
226 ConstantBufferSet, // constant buffer binding for shadows
227 Util::FixedArray<uint>, // dynamic offsets
228 std::array<float, 2>, // cone angle
229 CoreGraphics::TextureId, // projection (if invalid, don't use)
230 Math::mat4, // projection matrix
231 Graphics::GraphicsEntityId // graphics entity used for observer stuff
234
235 enum
236 {
245 };
246
247 typedef Ids::IdAllocator<
248 Math::transform44, // transform
249 AreaLightShape, // shape of area light
250 ConstantBufferSet, // constant buffer binding for light
251 ConstantBufferSet, // constant buffer binding for shadows
252 Util::FixedArray<uint>, // dynamic offsets
253 bool, // two sides
254 Graphics::GraphicsEntityId, // graphics entity used for observer stuff
255 bool // render mesh as well
258
259 enum
260 {
266 };
267
268 typedef Ids::IdAllocator<
269 Math::vector, // direction
270 Math::vec3, // ambient
271 Math::mat4, // transform (basically just a rotation in the direction)
272 Math::mat4, // transform for visibility and such
273 Util::Array<Graphics::GraphicsEntityId> // view ids for cascades
276
277
278 enum
279 {
281 };
282
283 typedef Ids::IdAllocator<
286
289
293 static void Dealloc(Graphics::ContextEntityId id);
294};
295} // namespace Lighting
A FrameScript describes render operations being done to produce a single frame.
Definition framescript.h:41
Definition graphicscontext.h:165
An ID allocator associates an id with a slice in an N number of arrays.
Definition idallocator.h:39
static Math::vec3 GetColor(const Graphics::GraphicsEntityId id)
Definition lightcontext.cc:575
static void SetupGlobalLight(const Graphics::GraphicsEntityId id, const Math::vec3 &color, const float intensity, const Math::vec3 &ambient, const float zenith, const float azimuth, bool castShadows=false)
setup entity as global light
Definition lightcontext.cc:294
static void WindowResized(const CoreGraphics::WindowId windowId, SizeT width, SizeT height)
React to window resize event.
Definition lightcontext.cc:1308
static const void SetScale(const Graphics::GraphicsEntityId id, const Math::vec3 &scale)
Set light scale.
Definition lightcontext.cc:779
Ids::IdAllocator< Math::vector, Math::vec3, Math::mat4, Math::mat4, Util::Array< Graphics::GraphicsEntityId > > DirectionalLightAllocator
Definition lightcontext.h:274
@ PointLight_Observer
Definition lightcontext.h:198
@ PointLight_Transform
Definition lightcontext.h:193
@ PointLight_ProjectionTexture
Definition lightcontext.h:197
@ PointLight_DynamicOffsets
Definition lightcontext.h:196
@ PointLight_ConstantBufferSet
Definition lightcontext.h:194
@ PointLight_ShadowConstantBufferSet
Definition lightcontext.h:195
@ ShadowCaster_Transform
Definition lightcontext.h:280
static ShadowCasterAllocator shadowCasterAllocator
Definition lightcontext.h:287
static const CoreGraphics::BufferId GetLightIndexBuffer()
get light index lists buffer
Definition lightcontext.cc:997
static Math::vec3 GetAmbient(const Graphics::GraphicsEntityId id)
Definition lightcontext.cc:350
static void SetAmbient(const Graphics::GraphicsEntityId id, Math::vec3 &ambient)
Definition lightcontext.cc:360
@ DirectionalLight_ViewProjTransform
Definition lightcontext.h:264
@ DirectionalLight_Ambient
Definition lightcontext.h:262
@ DirectionalLight_Direction
Definition lightcontext.h:261
@ DirectionalLight_CascadeObservers
Definition lightcontext.h:265
@ DirectionalLight_Transform
Definition lightcontext.h:263
static const Math::mat4 GetTransform(const Graphics::GraphicsEntityId id)
get transform
Definition lightcontext.cc:640
Ids::IdAllocator< Math::transform44, AreaLightShape, ConstantBufferSet, ConstantBufferSet, Util::FixedArray< uint >, bool, Graphics::GraphicsEntityId, bool > AreaLightAllocator
Definition lightcontext.h:256
static void SetupPointLight(const Graphics::GraphicsEntityId id, const Math::vec3 &color, const float intensity, const float range, bool castShadows=false, const CoreGraphics::TextureId projection=CoreGraphics::InvalidTextureId)
Setup entity as point light source.
Definition lightcontext.cc:373
static float GetIntensity(const Graphics::GraphicsEntityId id)
Definition lightcontext.cc:605
static const Math::point GetPosition(const Graphics::GraphicsEntityId id)
Get light position.
Definition lightcontext.cc:705
static void SetRange(const Graphics::GraphicsEntityId id, const float range)
set range of light
Definition lightcontext.cc:585
static const Math::quat GetRotation(const Graphics::GraphicsEntityId id)
Get light rotation.
Definition lightcontext.cc:757
static void GetInnerOuterAngle(const Graphics::GraphicsEntityId id, float &inner, float &outer)
get inner and outer angle for spotlights
Definition lightcontext.cc:849
static const LightsCluster::LightUniforms::STRUCT & GetLightUniforms()
get light uniforms
Definition lightcontext.cc:1015
static const CoreGraphics::BufferId GetLightsBuffer()
get light lists buffer
Definition lightcontext.cc:1006
static const void SetRotation(const Graphics::GraphicsEntityId id, const Math::quat &rotation)
Set light rotation.
Definition lightcontext.cc:727
static void SetGlobalLightViewProjTransform(const Graphics::ContextEntityId id, const Math::mat4 &transform)
Set global light shadow transform.
Definition lightcontext.cc:1035
LightType
Definition lightcontext.h:32
@ PointLightType
Definition lightcontext.h:34
@ AreaLightType
Definition lightcontext.h:36
@ SpotLightType
Definition lightcontext.h:35
@ DirectionalLightType
Definition lightcontext.h:33
static void SetColor(const Graphics::GraphicsEntityId id, const Math::vec3 &color)
set color of light
Definition lightcontext.cc:565
static Graphics::ContextEntityId Alloc()
allocate a new slice for this context
Definition lightcontext.cc:1332
static const Math::vec3 GetScale(const Graphics::GraphicsEntityId id)
Get light scale.
Definition lightcontext.cc:817
static void SetIntensity(const Graphics::GraphicsEntityId id, const float intensity)
set intensity of light
Definition lightcontext.cc:595
static void Discard()
discard light context
Definition lightcontext.cc:285
static void SetInnerOuterAngle(const Graphics::GraphicsEntityId id, float inner, float outer)
set inner and outer angle for spotlights
Definition lightcontext.cc:863
static const void SetPosition(const Graphics::GraphicsEntityId id, const Math::point &position)
Set light position.
Definition lightcontext.cc:675
static AreaLightAllocator areaLightAllocator
Definition lightcontext.h:257
LightContext()
constructor
Definition lightcontext.cc:105
static void SetupSpotLight(const Graphics::GraphicsEntityId id, const Math::vec3 &color, const float intensity, const float innerConeAngle, const float outerConeAngle, const float range, bool castShadows=false, const CoreGraphics::TextureId projection=CoreGraphics::InvalidTextureId)
Setup entity as spot light.
Definition lightcontext.cc:415
static void SetGlobalLightTransform(const Graphics::ContextEntityId id, const Math::mat4 &transform, const Math::vector &direction)
Set global light transform.
Definition lightcontext.cc:1024
static DirectionalLightAllocator directionalLightAllocator
Definition lightcontext.h:275
@ SpotLight_DynamicOffsets
Definition lightcontext.h:216
@ SpotLight_ShadowConstantBufferSet
Definition lightcontext.h:215
@ SpotLight_Transform
Definition lightcontext.h:213
@ SpotLight_ProjectionTexture
Definition lightcontext.h:218
@ SpotLight_ConstantBufferSet
Definition lightcontext.h:214
@ SpotLight_ProjectionTransform
Definition lightcontext.h:219
@ SpotLight_Observer
Definition lightcontext.h:220
@ SpotLight_ConeAngles
Definition lightcontext.h:217
static PointLightAllocator pointLightAllocator
Definition lightcontext.h:209
@ Range
Definition lightcontext.h:172
@ TypedLightId
Definition lightcontext.h:173
@ Intensity
Definition lightcontext.h:170
@ Type
Definition lightcontext.h:168
@ Color
Definition lightcontext.h:169
@ ShadowCaster
Definition lightcontext.h:171
static void SetTransform(const Graphics::GraphicsEntityId id, const float azimuth, const float zenith)
Set transform as angles.
Definition lightcontext.cc:615
static void OnRenderDebug(uint32_t flags)
render debug
Definition lightcontext.cc:1387
AreaLightShape
Definition lightcontext.h:40
@ Disk
Definition lightcontext.h:41
@ Rectangle
Definition lightcontext.h:42
@ Tube
Definition lightcontext.h:43
virtual ~LightContext()
destructor
Definition lightcontext.cc:113
Ids::IdAllocator< Math::transform44, ConstantBufferSet, ConstantBufferSet, Util::FixedArray< uint >, std::array< float, 2 >, CoreGraphics::TextureId, Math::mat4, Graphics::GraphicsEntityId > SpotLightAllocator
Definition lightcontext.h:232
Ids::IdAllocator< Math::transform44, ConstantBufferSet, ConstantBufferSet, Util::FixedArray< uint >, CoreGraphics::TextureId, Graphics::GraphicsEntityId > PointLightAllocator
Definition lightcontext.h:208
static Util::HashTable< Graphics::GraphicsEntityId, uint, 16, 1 > shadowCasterSliceMap
Definition lightcontext.h:288
static const Math::mat4 GetObserverTransform(const Graphics::GraphicsEntityId id)
get the view transform including projections
Definition lightcontext.cc:665
static void SetupTerrainShadows(const CoreGraphics::TextureId terrainShadowMap, const uint worldSize)
Setup terrain shadows.
Definition lightcontext.cc:986
static SpotLightAllocator spotLightAllocator
Definition lightcontext.h:233
static GenericLightAllocator genericLightAllocator
Definition lightcontext.h:184
static LightType GetType(const Graphics::GraphicsEntityId id)
get the light type
Definition lightcontext.cc:839
Ids::IdAllocator< Math::mat4 > ShadowCasterAllocator
Definition lightcontext.h:285
Ids::IdAllocator< LightType, Math::vec3, float, bool, float, Ids::Id32 > GenericLightAllocator
Definition lightcontext.h:183
static void Create()
setup light context
Definition lightcontext.cc:122
static void Dealloc(Graphics::ContextEntityId id)
deallocate a slice
Definition lightcontext.cc:1341
static void SetupAreaLight(const Graphics::GraphicsEntityId id, const AreaLightShape shape, const Math::vec3 &color, const float intensity, const float range, bool twoSided=false, bool castShadows=false, bool renderMesh=false)
Setup entity as area light.
Definition lightcontext.cc:472
static void OnPrepareView(const Ptr< Graphics::View > &view, const Graphics::FrameContext &ctx)
prepare light visibility
Definition lightcontext.cc:882
static void UpdateViewDependentResources(const Ptr< Graphics::View > &view, const Graphics::FrameContext &ctx)
prepare light lists
Definition lightcontext.cc:1045
static void RunFrameScriptJobs(const Graphics::FrameContext &ctx)
run framescript when visibility is done
@ AreaLight_DynamicOffsets
Definition lightcontext.h:241
@ AreaLight_TwoSided
Definition lightcontext.h:242
@ AreaLight_ConstantBufferSet
Definition lightcontext.h:239
@ AreaLight_Shape
Definition lightcontext.h:238
@ AreaLight_ShadowConstantBufferSet
Definition lightcontext.h:240
@ AreaLight_RenderMesh
Definition lightcontext.h:244
@ AreaLight_Transform
Definition lightcontext.h:237
@ AreaLight_Observer
Definition lightcontext.h:243
A 4x4 matrix which is described by translation, rotation and scale.
Definition transform44.h:20
Nebula's smart pointer class which manages the life time of RefCounted objects.
Definition ptr.h:38
Nebula's dynamic array class.
Definition array.h:60
Implements a fixed size one-dimensional array.
Definition fixedarray.h:20
Organizes key/value pairs by a hash code.
Definition hashtable.h:42
ImGUI debug interface for inspecting frame scripts.
Definition shaderserverbase.h:52
uint32_t Id32
Definition id.h:138
The lighting subsystem allows for attaching light source functionality to a GraphicsEntityId.
Definition csmutil.cc:19
CoreGraphics::TextureId terrainShadowMap
Definition lightcontext.cc:55
A shader represents an entire shader resource, containing several stages and programs.
Definition buffer.h:23
texture type
Definition texture.h:25
Definition window.h:25
Definition graphicscontext.h:133
Definition graphicsserver.h:31
The graphics entity is only an Id, to which we can attach GraphicsContexts.
Definition graphicsentity.h:16
Definition lightcontext.h:187
uint offset
Definition lightcontext.h:188
uint slice
Definition lightcontext.h:188
A 4x4 single point precision float matrix.
Definition mat4.h:49
Represents a 3D point in space.
Definition point.h:22
A quaternion is usually used to represent an orientation in 3D space.
Definition quat.h:30
A 3D vector.
Definition vec3.h:37
A vector is a 3D direction in space.
Definition vector.h:22
int SizeT
Definition types.h:42
unsigned int uint
Definition types.h:33