-
Notifications
You must be signed in to change notification settings - Fork 0
/
RendererSystem.h
138 lines (108 loc) · 2.63 KB
/
RendererSystem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#ifndef RENDERER_SYSTEM_H_
#define RENDERER_SYSTEM_H_
#include "Systems.h"
#include "glad/glad.h"
#define GLM_FORCE_RADIANS
#include "glm/glm.hpp"
#include "GameObject.h"
#include "ModelRenderer.h"
#include "PointLight.h"
#include "DirectionalLight.h"
#include "Model.h"
#include "Mesh.h"
#include "Texture.h"
#include <vector>
struct GBuffer {
GLuint id;
GLuint positions;
GLuint normals;
GLuint diffuse;
GLuint specular;
};
const float quadVerts[12] = {
-1.0f, 1.0f,
-1.0f, -1.0f,
1.0f, -1.0f,
1.0f, -1.0f,
1.0f, 1.0f,
-1.0f, 1.0f
};
struct MeshToDraw {
Mesh* mesh;
Material* material;
glm::mat4 model;
GLuint vao;
GLuint indexVbo;
GLuint shaderProgram;
glm::vec3 position;
~MeshToDraw() {
mesh = nullptr;
material = nullptr;
}
};
struct PointLightToDraw {
glm::mat4 model;
glm::vec3 position;
float luminance;
glm::vec3 color;
float radius;
};
struct PointLightToGPU {
glm::vec4 position;
glm::vec3 color;
float luminance;
};
class RendererSystem : public Systems {
private:
std::vector<ModelRenderer*> modelRenderers;
std::vector<MeshToDraw> meshesToDraw;
std::vector<MeshToDraw> transparentToDraw;
std::vector<PointLightToGPU> pointLightsToGPU;
// TODO: Need to add lights to the asset manager
std::vector<PointLight*> pointLights;
DirectionalLight* sun;
std::vector<PointLightToDraw> pointLightsToDraw;
GLubyte dummyData[4] = { 255, 255, 255, 255 };
int screenWidth; int screenHeight;
glm::mat4 proj; glm::mat4 view;
// Deferred
GBuffer gBuffer;
// Quad vert info
GLuint quadVAO; GLuint quadVBO;
// Directional Light quad
GLuint directionalLightShader;
glm::mat4 lightProjView;
// Light volumes
Mesh* lightVolume;
GLuint lightVolumeVAO; GLuint lightVolumeVBO; GLuint lightVolumeIBO;
GLuint lightVolumeShader;
GLuint pointLightsSSBO = 0;
// Shadows
GLuint shadowMapShader;
GLuint depthMapFBO; GLuint depthMap;
const int shadowWidth = 4096; const int shadowHeight = 4096;
// Post processing
GLuint finalQuadFBO; GLuint finalQuadRender;
GLuint finalQuadShader;
public:
int totalTriangles = 0;
// Timings
GLuint timeQuery;
long long cullTime; long long shadowTime;
long long deferredToTexTime; long long deferredLightsTime;
long long transparentTime; long long postFXXTime;
RendererSystem(const int&, const int&);
~RendererSystem();
void Setup();
void Register(const Component*);
void Update(const float&) {}
void Render();
void CullScene();
void DrawShadows();
void DeferredToTexture();
void DeferredLighting();
void DrawTransparent();
void PostProcess();
bool ShouldFrustumCull(const Mesh*, const glm::mat4&) const;
};
#endif