Cogs.Core
LightSystem.h
1#pragma once
2
3#include "Systems/ComponentSystem.h"
4
5#include "Components/Core/LightComponent.h"
6
7#include "Systems/Core/CameraSystem.h"
8
9#include "Resources/Resources.h"
10
11#include "Renderer/Constants.h"
12
13#include "Rendering/DataFormat.h"
14
15namespace Cogs
16{
17 namespace Core
18 {
19 class Context;
20
21 // Corner points of the frusta for which a shadow map must cover.
22 //
23
25 {
26 std::vector<glm::vec3> points;
27 std::vector<unsigned> offsets;
28 glm::vec2 viewportMin;
29 glm::vec2 viewportMax;
30 };
31
33 struct LightData
34 {
35 glm::vec4 lightPosition;
36 glm::vec4 lightDirection;
37 glm::vec4 lightColor;
38 float lightRange = 0.f;
39
40 uint16_t maxViewports = 4;
41 uint16_t numViewports = maxViewports;
42
43 uint16_t frameMod[6] = { 0 };
44 uint16_t frameOffset[6] = { 0 };
45
46 float nearDepths[kMaxCascades] = { 0.f };
47 float farDepths[kMaxCascades] = { 0.f };
48
49 RenderPassOptions passOptions;
50
51 CameraData lightCameraData[kMaxCascades];
52 glm::vec4 cascadeLine;
53
54 float shadowIntensityOffset = 0;
55 TextureHandle shadowTexture;
56 uint32_t arrayOffset = 0;
57 uint32_t textureSize = 1024;
58
59 uint32_t cubeOffset = 0;
60
61 bool enabled = true;
62 bool castShadows = false;
63 bool tightShadowBounds = false;
64 bool dynamicCascadeCount = false;
65
66 ShadowUpdate shadowUpdate = ShadowUpdate::Default;
67
68 bool frustaPointsCapture = false;
69 LightCascadeFrustaPoints frustaPoints[kMaxCascades];
70 glm::mat4 lightRawProjection[kMaxCascades];
71 };
72
77 class LightSystem : public ComponentSystemWithDataPool<LightComponent, LightData>
78 {
79 public:
80 LightSystem(Memory::Allocator * allocator, SizeType capacity) : ComponentSystemWithDataPool(allocator, capacity) {}
81
82 void initialize(Context* context) override;
83
85 void update(Context * context) override;
86
89
90 TextureHandle cascadeArray = {};
91 uint32_t currentLayerCount = 0;
92 uint32_t currentTextureSize = 0;
93 Cogs::TextureFormat currentShadowFormat = TextureFormat::Unknown;
94
95 TextureHandle cubeArray = {};
96 uint32_t currentCubeCount = 0;
97 uint32_t currentPointShadowResolution = 0;
98 Cogs::TextureFormat currentPointShadowFormat = TextureFormat::Unknown;
99
100 SoftShadows softShadows = SoftShadows::High;
101 bool lightsChanged = true;
102
103 };
104 }
105}
Context * context
Pointer to the Context instance the system lives in.
void update()
Updates the system state to that of the current frame.
Component system with parallel data per component stored in a pool similar to how the components them...
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
Holds all LightComponent instances in the system.
Definition: LightSystem.h:78
void initialize(Context *context) override
Initialize the system.
void preRender(Context *context)
Cull light system.
Base allocator implementation.
Definition: Allocator.h:30
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
ComponentIndex SizeType
Type used to track the size of pools.
Definition: Component.h:19
Contains data describing a Camera instance and its derived data structured such as matrix data and vi...
Definition: CameraSystem.h:67
Defines calculated light data.
Definition: LightSystem.h:34