-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRenderer.cpp
More file actions
100 lines (73 loc) · 2.14 KB
/
Renderer.cpp
File metadata and controls
100 lines (73 loc) · 2.14 KB
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
//
// Created by adamyuan on 4/18/18.
//
#include <unordered_map>
#include "Renderer.hpp"
#include "Config.hpp"
#include "Resources.hpp"
#include <GLFW/glfw3.h>
void Renderer::Initialize()
{
shadow_map_.Initialize();
shadow_map_.Update();
skybox_.Initialize();
voxels_.Initialize();
voxels_.Voxelize();
voxels_.DirectLight(shadow_map_.Get());
voxels_.GenerateMipmap();
voxels_.Bounce();
voxels_.GenerateMipmap();
gbuffer_.Initialize();
cone_tracer_.Initialize();
final_shader_.Initialize();
final_shader_.SetUProjection(res::cam_projection);
final_shader_.SetUVoxelDimension(kVoxelDimension);
final_shader_.SetUVoxelWorldSize(kVoxelWorldSize);
final_shader_.SetUVoxelGridRangeMin(kVoxelGridRangeMin);
final_shader_.SetUVoxelGridRangeMax(kVoxelGridRangeMax);
final_shader_.SetUResolution(glm::ivec2(kWidth, kHeight));
}
void Renderer::Render(bool debug_voxel, bool indirect_trace, bool show_albedo, bool show_edge)
{
if(debug_voxel)
{
glViewport(0, 0, kWidth, kHeight);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
voxels_.Debug();
return;
}
gbuffer_.Update();
if(indirect_trace)
cone_tracer_.Update(gbuffer_, voxels_);
glViewport(0, 0, kWidth, kHeight);
glDisable(GL_DEPTH_TEST);
glCullFace(GL_BACK);
glClear(GL_COLOR_BUFFER_BIT);
gbuffer_.GetPositionTexture().Bind(0);
gbuffer_.GetNormalTexture().Bind(1);
gbuffer_.GetAlbedoTexture().Bind(2);
cone_tracer_.Get().Bind(3);
skybox_.Get().Bind(4);
shadow_map_.Get().Bind(5);
voxels_.GetRadiance().Bind(6);
for(int i = 0; i < 6; ++i) voxels_.GetMipmap()[i].Bind(i + 9u);
final_shader_.Use();
final_shader_.SetULightDir(res::light_dir);
final_shader_.SetULightMatrix(res::light_matrix);
final_shader_.SetUView(res::cam_view);
final_shader_.SetUCamPosition(res::cam_pos);
//set flags
final_shader_.SetUEnableIndirectTrace(indirect_trace);
final_shader_.SetUShowAlbedo(show_albedo);
final_shader_.SetUShowEdge(show_edge);
res::quad_object.Render(GL_TRIANGLES);
glEnable(GL_DEPTH_TEST);
}
void Renderer::UpdateLight()
{
shadow_map_.Update();
voxels_.DirectLight(shadow_map_.Get());
voxels_.GenerateMipmap();
voxels_.Bounce();
voxels_.GenerateMipmap();
}