Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
ForwardLight.hpp
1#pragma once
2
3#include "scene/Scene.hpp"
4
5#include "renderers/LightRenderer.hpp"
6#include "renderers/shadowmaps/ShadowMap.hpp"
7#include "scene/lights/Light.hpp"
8#include "scene/lights/PointLight.hpp"
9#include "scene/lights/DirectionalLight.hpp"
10#include "scene/lights/SpotLight.hpp"
11#include "resources/Buffer.hpp"
12
13#include "Common.hpp"
14
15
20class ForwardLight final : public LightRenderer {
21
22public:
23
25 struct GPULight {
26 glm::mat4 viewToLight;
27 glm::vec4 colorAndBias;
30 glm::vec4 typeModeLayer;
31 glm::vec4 angles;
32 };
33
37 explicit ForwardLight(size_t count);
38
43 void updateCameraInfos(const glm::mat4 & viewMatrix, const glm::mat4 & projMatrix);
44
45
49 void draw(const SpotLight * light) override;
50
54 void draw(const PointLight * light) override;
55
59 void draw(const DirectionalLight * light) override;
60
62 size_t count() const {
63 return _currentCount;
64 }
65
67 const std::vector<const Texture *> & shadowMaps() const {
68 return _shadowMaps;
69 }
70
73 return _lightsData;
74 }
75
76private:
77
78 size_t _currentId = 0;
79 size_t _currentCount = 0;
80 const static size_t _maxLightCount;
82
83 glm::mat4 _view = glm::mat4(1.0f);
84 glm::mat4 _proj = glm::mat4(1.0f);
85 glm::mat4 _invView = glm::mat4(1.0f);
86
87 std::vector<const Texture *> _shadowMaps;
88};
89
90
96
97public:
98
100 struct GPUProbe {
101 glm::vec4 positionAndMip{0.0f};
102 glm::vec4 sizeAndFade{0.0f};
103 glm::vec4 centerAndCos{0.0f};
104 glm::vec4 extentAndSin{0.0f};
105 };
106
110 explicit ForwardProbe(size_t count);
111
115 void draw(const LightProbe & probe);
116
118 size_t count() const {
119 return _currentCount;
120 }
121
123 const std::vector<const Texture *> & envmaps() const {
124 return _probesMaps;
125 }
126
128 const std::vector<const Buffer *> & shCoeffs() const {
129 return _probesCoeffs;
130 }
131
134 return _probesData;
135 }
136
137private:
138
139 size_t _currentId = 0;
140 size_t _currentCount = 0;
141 const static size_t _maxProbeCount;
143
144 std::vector<const Texture *> _probesMaps;
145 std::vector<const Buffer *> _probesCoeffs;
146};
A directional light, where all light rays have the same direction.
Definition: DirectionalLight.hpp:13
Store lights data for forward rendering in a GPU buffer.
Definition: ForwardLight.hpp:20
size_t _currentCount
Number of lights to store.
Definition: ForwardLight.hpp:79
void updateCameraInfos(const glm::mat4 &viewMatrix, const glm::mat4 &projMatrix)
Definition: ForwardLight.cpp:18
glm::mat4 _view
Cached camera view matrix.
Definition: ForwardLight.hpp:83
std::vector< const Texture * > _shadowMaps
Shadow maps list.
Definition: ForwardLight.hpp:87
void draw(const SpotLight *light) override
Definition: ForwardLight.cpp:24
UniformBuffer< GPULight > _lightsData
GPU buffer.
Definition: ForwardLight.hpp:81
size_t count() const
Definition: ForwardLight.hpp:62
const std::vector< const Texture * > & shadowMaps() const
Definition: ForwardLight.hpp:67
size_t _currentId
Current insertion location.
Definition: ForwardLight.hpp:78
static const size_t _maxLightCount
Maximum allowed number of lights (see forward_lights.glsl).
Definition: ForwardLight.hpp:80
glm::mat4 _invView
Cached inverse view matrix.
Definition: ForwardLight.hpp:85
UniformBuffer< GPULight > & data()
Definition: ForwardLight.hpp:72
glm::mat4 _proj
Cached camera projection matrix.
Definition: ForwardLight.hpp:84
Store environment probes data for forward rendering in a GPU buffer.
Definition: ForwardLight.hpp:95
static const size_t _maxProbeCount
Maximum allowed number of probes (see forward_lights.glsl).
Definition: ForwardLight.hpp:141
size_t _currentId
Current insertion location.
Definition: ForwardLight.hpp:139
void draw(const LightProbe &probe)
Definition: ForwardLight.cpp:121
const std::vector< const Texture * > & envmaps() const
Definition: ForwardLight.hpp:123
std::vector< const Texture * > _probesMaps
Environment maps list.
Definition: ForwardLight.hpp:144
UniformBuffer< GPUProbe > & data()
Definition: ForwardLight.hpp:133
std::vector< const Buffer * > _probesCoeffs
Environment SH coeffs list.
Definition: ForwardLight.hpp:145
size_t count() const
Definition: ForwardLight.hpp:118
size_t _currentCount
Number of probes to store.
Definition: ForwardLight.hpp:140
const std::vector< const Buffer * > & shCoeffs() const
Definition: ForwardLight.hpp:128
UniformBuffer< GPUProbe > _probesData
GPU buffer.
Definition: ForwardLight.hpp:142
Store environment lighting for reflections.
Definition: LightProbe.hpp:12
Base structure of a per-light specialized renderer.
Definition: LightRenderer.hpp:13
An omnidirectional punctual light, where light is radiating in all directions from a single point in ...
Definition: PointLight.hpp:15
A spotlight, where light rays in a given cone are radiating from a single point in space....
Definition: SpotLight.hpp:13
Represents a buffer containing uniform data, stored on the CPU and GPU. Depending on the update frequ...
Definition: Buffer.hpp:164
Represent a light on the GPU for the forward renderer.
Definition: ForwardLight.hpp:25
glm::vec4 colorAndBias
Light tint and shadow bias.
Definition: ForwardLight.hpp:27
glm::vec4 directionAndPlane
Light direction and far plane distance.
Definition: ForwardLight.hpp:29
glm::vec4 angles
Cone inner and outer angles.
Definition: ForwardLight.hpp:31
glm::vec4 typeModeLayer
Light type, shadow mode and shadow map layer.
Definition: ForwardLight.hpp:30
glm::mat4 viewToLight
View to light matrix.
Definition: ForwardLight.hpp:26
glm::vec4 positionAndRadius
Light position and effect radius.
Definition: ForwardLight.hpp:28
Represent a probe on the GPU for the forward renderer.
Definition: ForwardLight.hpp:100
glm::vec4 extentAndSin
The cubemap parallax box half size, and the cubemap parallax box orientation (precomputed sin).
Definition: ForwardLight.hpp:104
glm::vec4 positionAndMip
The cubemap location and the mip.
Definition: ForwardLight.hpp:101
glm::vec4 centerAndCos
The cubemap parallax box center, and the cubemap parallax box orientation (precomputed cos).
Definition: ForwardLight.hpp:103
glm::vec4 sizeAndFade
The cubemap box effect size, and the size of its fading region on edges.
Definition: ForwardLight.hpp:102