-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMain.cpp
506 lines (449 loc) · 18 KB
/
Main.cpp
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
#include "imgui.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
#include <string>
#include <shader.h>
#define STB_IMAGE_IMPLEMENTATION
// #include "stb_image.h"
#include <ApplicationUtility.h>
#include "Model.h"
#include <Light.h>
#include <glm.hpp>
#include <gtc/matrix_transform.hpp>
#include <gtc/type_ptr.hpp>
#include <gtx/string_cast.hpp>
#define INIT_WIDTH 1000
#define INIT_HEIGHT 1000
#define SD_WIDTH 2000
#define SD_HEIGHT 2000
int Left_Mouse_down = 0;
int Right_Mouse_down = 0;
float rotate_sensi = 0.3;
float walk_sensi = 0.05;
bool center_rotate = false;
bool poly_mode = false;
bool cube_shadow_enabled = true;
bool debug_window = false;
bool show_light = true;
bool multiCam = false;
bool peter_pan = true;
bool gamma_correction = false;
bool HDR = false;
bool deferred_shading = false;
glm::vec3 cameraPos;
glm::vec3 cameraTarget;
glm::vec3 cameraUp;
glm::vec3 cameraRight;
float near_plane = 0.1f;
float far_plane = 100.0f;
float fov = 90.0;
float scr_aspect = (float)INIT_WIDTH / (float)INIT_HEIGHT;
float sd_aspect = (float)SD_WIDTH / (float)SD_HEIGHT;
float light_offset = 0.1;
void processCamWalkInput(GLFWwindow* window) {
glm::vec3 front_direction = glm::normalize(cameraTarget - cameraPos);
// front_direction[1] = 0.0;
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
glfwSetWindowShouldClose(window, true);
}
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) {
cameraPos += walk_sensi * front_direction;
cameraTarget += walk_sensi * front_direction;
}
else if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) {
cameraPos -= walk_sensi * front_direction;
cameraTarget -= walk_sensi * front_direction;
}
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) {
cameraPos += walk_sensi * cameraRight;
cameraTarget += walk_sensi * cameraRight;
}
else if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) {
cameraPos -= walk_sensi * cameraRight;
cameraTarget -= walk_sensi * cameraRight;
}
if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) {
cameraPos += walk_sensi * cameraUp;
cameraTarget += walk_sensi * cameraUp;
}
else if (glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS) {
cameraPos -= walk_sensi * cameraUp;
cameraTarget -= walk_sensi * cameraUp;
}
}
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
if (key == GLFW_KEY_C && action == GLFW_PRESS) {
center_rotate = !center_rotate;
std::cout << center_rotate << std::endl;
}
}
int main() {
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_SAMPLES, 4);
// //init error check
GLFWwindow* window = glfwCreateWindow(INIT_WIDTH, INIT_HEIGHT, "Hello Atelier", NULL, NULL);
if (window == NULL) {
std::cout << "Creating window Failed\n" << std::endl;
glfwTerminate();
return 0;
}
glfwMakeContextCurrent(window);
glfwSetKeyCallback(window, key_callback);
glfwSetFramebufferSizeCallback(window, [](GLFWwindow* window, int width, int height) {
glViewport(0, 0, width, height);
});
glfwSetMouseButtonCallback(window, [](GLFWwindow* window, int button, int action, int mods) {
ImGuiIO& io = ImGui::GetIO();
if (!io.WantCaptureMouse) {
if (button == GLFW_MOUSE_BUTTON_1 && action == GLFW_PRESS) {
Left_Mouse_down = 1;
}
if (button == GLFW_MOUSE_BUTTON_2 && action == GLFW_PRESS) {
Right_Mouse_down = 1;
}
if (button == GLFW_MOUSE_BUTTON_1 && action == GLFW_RELEASE) {
Left_Mouse_down = 0;
}
if (button == GLFW_MOUSE_BUTTON_2 && action == GLFW_RELEASE) {
Right_Mouse_down = 0;
}
}
});
glfwSetCursorPosCallback(window, [](GLFWwindow * window, double xpos, double ypos) {
static double CursorLastX = xpos;
static double CursorLastY = ypos;
ImGuiIO& io = ImGui::GetIO();
if (Left_Mouse_down && !io.WantCaptureMouse) {
if (!center_rotate) {
glm::mat4 rot_mat = glm::mat4(1.0f);
float hor_r = -glm::radians(rotate_sensi * (xpos - CursorLastX) / INIT_WIDTH) * 500.0;
float ver_r = glm::radians(rotate_sensi * (ypos - CursorLastY) / INIT_HEIGHT) * 400.0;
rot_mat = glm::rotate(rot_mat, hor_r, cameraUp);
rot_mat = glm::rotate(rot_mat, ver_r, cameraRight);
glm::vec4 temp_cameraPos = rot_mat * glm::vec4(cameraPos.x - cameraTarget.x, cameraPos.y - cameraTarget.y, cameraPos.z - cameraTarget.z, 1.0);
cameraPos = glm::vec3(cameraTarget.x + temp_cameraPos.x / temp_cameraPos[3], cameraTarget.y + temp_cameraPos.y / temp_cameraPos[3], cameraTarget.z + temp_cameraPos.z / temp_cameraPos[3]);
}
else {
}
}
CursorLastX = xpos;
CursorLastY = ypos;
});
// get function pointers
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
std::cout << "Failed to initialize GLAD" << std::endl;
return 0;
}
// ----------------------------------------------------------------------------------------------------- //
// ----------------------------------------------------------------------------------------------------- //
// ----------------------------------------------------------------------------------------------------- //
// camera
cameraPos = glm::vec3(0.0f, 0.0f, 10.0f);
cameraTarget = glm::vec3(0.0f, 0.0f, 0.0f);
cameraUp = glm::vec3(0.0f, 1.0f, 0.0f);
// test texture
unsigned int texture1 = loadTexture("./data/uv.jpg");
// G Buffer
unsigned int gBuffer;
glGenFramebuffers(1, &gBuffer);
glBindFramebuffer(GL_FRAMEBUFFER, gBuffer);
unsigned int attachments[3] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 };
glDrawBuffers(3, attachments);
unsigned int gPosition = bindColorBuffer(gBuffer, INIT_WIDTH, INIT_HEIGHT, GL_COLOR_ATTACHMENT0, GL_RGBA16F);
unsigned int gNormal = bindColorBuffer(gBuffer, INIT_WIDTH, INIT_HEIGHT, GL_COLOR_ATTACHMENT1, GL_RGBA16F);
unsigned int gAlbedoSpec = bindColorBuffer(gBuffer, INIT_WIDTH, INIT_HEIGHT, GL_COLOR_ATTACHMENT2, GL_RGBA16F);
attachRBOToBuffer(gBuffer, INIT_WIDTH, INIT_HEIGHT, GL_DEPTH_COMPONENT, GL_DEPTH_ATTACHMENT);
// light
Light mylight= Light();
// ---depth---
glm::mat4 lightProjection = glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane, far_plane);
// default depth map
unsigned int depthMapFBO;
glGenFramebuffers(1, &depthMapFBO);
unsigned int depthMap = bindDepthMap(depthMapFBO, SD_WIDTH, SD_HEIGHT);
// soft shadow depth maps
unsigned int depthMapFBOs[6];
glGenFramebuffers(6, depthMapFBOs);
unsigned int depthMaps[6];
for (unsigned int i = 0; i < 6; i++)
{
depthMaps[i] = bindDepthMap(depthMapFBOs[i], SD_WIDTH, SD_HEIGHT);
}
// ---cube depth---
glm::mat4 perspectiveShadowProj = glm::perspective(glm::radians(fov), sd_aspect, near_plane, far_plane);
// default cube depth map
unsigned int depthCubeFBO;
glGenFramebuffers(1, &depthCubeFBO);
unsigned int depthCubemap = bindCubeDepthMap(depthCubeFBO, SD_WIDTH, SD_HEIGHT);
// light offsets for soft shadow
glm::vec3 offsets[6];
offsets[0] = glm::vec3(light_offset, 0.0, 0.0);
offsets[1] = glm::vec3(-light_offset, 0.0, 0.0);
offsets[2] = glm::vec3(0.0, light_offset, 0.0);
offsets[3] = glm::vec3(0.0, -light_offset, 0.0);
offsets[4] = glm::vec3(0.0, 0.0, light_offset);
offsets[5] = glm::vec3(0.0, 0.0, -light_offset);
Shader shadowDepth("./shader/ShadowDepth.vert", "./shader/empty.frag");
Shader cubeShadowDepth("./shader/cubeDepth.vert", "./shader/cubeDepth.frag", "./shader/cubeDepth.geom");
Shader planeShadowShader("./shader/ShadowRender.vert", "./shader/ShadowRender.frag");
// Shader planeShadowSoftShader("./shader/SoftShadowRender.vert", "./shader/SoftShadowRender.frag");
Shader cubeShadowShader("./shader/CubeShadowRender.vert", "./shader/CubePCSS.frag");
Shader DebugShader("./shader/quad.vert", "./shader/debug.frag");
Shader showLightShader("./shader/showLight.vert", "./shader/showLight.frag");
Shader gBufferGeoPass("./shader/CubeShadowRender.vert", "./shader/gBuffer.frag");
Shader gBufferLightPass("./shader/deferred_shading.vert", "./shader/gCubePCSS.frag");
Model MyModel("./model/sponza/sponza.obj");
// Model MyModel("./model/opengl_render_testing.obj");
// Model MyModel("./model/softshadowtest.obj");
Model LightModel("./model/light.obj");
std::cout << GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS << std::endl;
ImGui::CreateContext();
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init("#version 430");
ImGui::StyleColorsDark();
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glFrontFace(GL_CCW);
glDepthMask(GL_TRUE);
glDepthFunc(GL_LESS);
while (!glfwWindowShouldClose(window)) {
// start
processCamWalkInput(window);
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
cameraRight = glm::normalize(glm::cross(glm::normalize(cameraPos - cameraTarget), cameraUp));
glm::mat4 view_mat = glm::lookAt(cameraPos, cameraTarget, cameraUp);
glm::mat4 proj_mat = glm::perspective(glm::radians(fov), scr_aspect, near_plane, far_plane);
//setting
glBindFramebuffer(GL_FRAMEBUFFER, 0);
if (poly_mode) {
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
else {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
glViewport(0, 0, INIT_WIDTH, INIT_HEIGHT);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glClearColor(0.3f, 0.4f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (cube_shadow_enabled) {
// setup
std::vector<glm::mat4> shadowTransforms;
shadowTransforms.push_back(perspectiveShadowProj *
glm::lookAt(mylight.position, mylight.position + glm::vec3(1.0, 0.0, 0.0), glm::vec3(0.0, -1.0, 0.0)));
shadowTransforms.push_back(perspectiveShadowProj *
glm::lookAt(mylight.position, mylight.position + glm::vec3(-1.0, 0.0, 0.0), glm::vec3(0.0, -1.0, 0.0)));
shadowTransforms.push_back(perspectiveShadowProj *
glm::lookAt(mylight.position, mylight.position + glm::vec3(0.0, 1.0, 0.0), glm::vec3(0.0, 0.0, 1.0)));
shadowTransforms.push_back(perspectiveShadowProj *
glm::lookAt(mylight.position, mylight.position + glm::vec3(0.0, -1.0, 0.0), glm::vec3(0.0, 0.0, -1.0)));
shadowTransforms.push_back(perspectiveShadowProj *
glm::lookAt(mylight.position, mylight.position + glm::vec3(0.0, 0.0, 1.0), glm::vec3(0.0, -1.0, 0.0)));
shadowTransforms.push_back(perspectiveShadowProj *
glm::lookAt(mylight.position, mylight.position + glm::vec3(0.0, 0.0, -1.0), glm::vec3(0.0, -1.0, 0.0)));
//depthMap
glViewport(0, 0, SD_WIDTH, SD_HEIGHT);
glBindFramebuffer(GL_FRAMEBUFFER, depthCubeFBO);
glClear(GL_DEPTH_BUFFER_BIT);
cubeShadowDepth.use();
cubeShadowDepth.setVec3("lightPos", glm::value_ptr(mylight.position));
for (unsigned int i = 0; i < 6; ++i)
cubeShadowDepth.setMat4("shadowMatrices[" + std::to_string(i) + "]", shadowTransforms[i]);
cubeShadowDepth.setFloat("far_plane", far_plane);
if (peter_pan) {
glCullFace(GL_FRONT);
MyModel.Draw(cubeShadowDepth);
glCullFace(GL_BACK);
}
else {
MyModel.Draw(cubeShadowDepth);
}
//3d model
glViewport(0, 0, INIT_WIDTH, INIT_HEIGHT);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glClearColor(0.3f, 0.4f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
cubeShadowShader.use();
cubeShadowShader.setVec3("lightPos", glm::value_ptr(mylight.position));
cubeShadowShader.setVec3("viewPos", glm::value_ptr(cameraPos));
cubeShadowShader.setFloat("far_plane", far_plane);
cubeShadowShader.setMat4("proj", glm::value_ptr(proj_mat), false);
cubeShadowShader.setMat4("view", glm::value_ptr(view_mat), false);
cubeShadowShader.setBool("HDR", HDR);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_CUBE_MAP, depthCubemap);
cubeShadowShader.setInt("depthCubemap", 0);
glEnable(GL_FRAMEBUFFER_SRGB);
MyModel.Draw(cubeShadowShader);
glDisable(GL_FRAMEBUFFER_SRGB);
glViewport(0, 0, INIT_WIDTH, INIT_HEIGHT);
glBindFramebuffer(GL_FRAMEBUFFER, gBuffer);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gBufferGeoPass.use();
gBufferGeoPass.setMat4("proj", glm::value_ptr(proj_mat), false);
gBufferGeoPass.setMat4("view", glm::value_ptr(view_mat), false);
MyModel.Draw(gBufferGeoPass);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
else {
// setup
glm::mat4 lightView = glm::lookAt(mylight.position,
glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(0.0f, 1.0f, 0.0f));
glm::mat4 lightSpaceMatrix = lightProjection * lightView;
//soft Shadow
glm::mat4 lightSpaceMatrixArray[6];
if (multiCam) {
for (unsigned int i = 0; i < 6; i++)
{
glm::mat4 lightView = glm::lookAt(mylight.position + offsets[i],
glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(0.0f, 1.0f, 0.0f));
lightSpaceMatrixArray[i] = lightProjection * lightView;
}
}
//depthMap
glViewport(0, 0, SD_WIDTH, SD_HEIGHT);
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
glEnable(GL_DEPTH_TEST);
glClear(GL_DEPTH_BUFFER_BIT);
shadowDepth.use();
shadowDepth.setMat4("lightSpaceMatrix", glm::value_ptr(lightSpaceMatrix), false);
MyModel.Draw(shadowDepth);
if (multiCam) {
for (unsigned int i = 0; i < 6; i++)
{
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBOs[i]);
glEnable(GL_DEPTH_TEST);
glClear(GL_DEPTH_BUFFER_BIT);
shadowDepth.use();
shadowDepth.setMat4("lightSpaceMatrix", glm::value_ptr(lightSpaceMatrixArray[i]), false);
MyModel.Draw(shadowDepth);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
}
//3d model
planeShadowShader.use();
planeShadowShader.setMat4("lightSpaceMatrix", glm::value_ptr(lightSpaceMatrix), false);
planeShadowShader.setVec3("lightPos", glm::value_ptr(mylight.position));
planeShadowShader.setVec3("viewPos", glm::value_ptr(cameraPos));
planeShadowShader.setMat4("proj", glm::value_ptr(proj_mat), false);
planeShadowShader.setMat4("view", glm::value_ptr(view_mat), false);
planeShadowShader.setBool("multiCam", multiCam);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, depthMap);
// planeShadowShader.setInt("depthMap", 0);
if (multiCam) {
for (unsigned int i = 0; i < 6; i++) {
planeShadowShader.setMat4("LSM[" + std::to_string(i) + "]", lightSpaceMatrixArray[i]);
glActiveTexture(GL_TEXTURE0 + i + 1);
glBindTexture(GL_TEXTURE_2D, depthMaps[i]);
planeShadowShader.setInt("depthMaps[" + std::to_string(i) + "]", 1 + i);
}
}
MyModel.Draw(planeShadowShader);
}
// top right debug
if (debug_window) {
glViewport(0, 0, INIT_WIDTH, INIT_HEIGHT);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
DebugShader.use();
DebugShader.setInt("depthMap", 0);
DebugShader.setFloat("near_plane", near_plane);
DebugShader.setFloat("far_plane", far_plane);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, gNormal);
DebugShader.setInt("depthMap", 0);
unsigned int debugWindow = initQuad(0.0);
renderQuad(debugWindow);
}
if (show_light) {
glViewport(0, 0, INIT_WIDTH, INIT_HEIGHT);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glm::mat4 model = glm::mat4(1.0f);
model = glm::translate(model, mylight.position);
showLightShader.use();
showLightShader.setMat4("model", glm::value_ptr(model), false);
showLightShader.setMat4("view", glm::value_ptr(view_mat), false);
showLightShader.setMat4("proj", glm::value_ptr(proj_mat), false);
LightModel.Draw(showLightShader);
}
if (deferred_shading) {
glViewport(0, 0, INIT_WIDTH, INIT_HEIGHT);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
gBufferLightPass.use();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, gPosition);
gBufferLightPass.setInt("gPosition", 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, gNormal);
gBufferLightPass.setInt("gNormal", 1);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, gAlbedoSpec);
gBufferLightPass.setInt("gAlbedoSpec", 2);
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_CUBE_MAP, depthCubemap);
gBufferLightPass.setInt("depthCubemap", 3);
gBufferLightPass.setVec3("lightPos", glm::value_ptr(mylight.position));
gBufferLightPass.setVec3("viewPos", glm::value_ptr(cameraPos));
gBufferLightPass.setFloat("far_plane", far_plane);
gBufferLightPass.setBool("HDR", HDR);
unsigned int deferred_render_window = initQuad(-1.0);
glEnable(GL_FRAMEBUFFER_SRGB);
renderQuad(deferred_render_window);
glDisable(GL_FRAMEBUFFER_SRGB);
}
//imgui
{
ImGui::Begin("Setting");
ImGui::SliderFloat3("lightPos", glm::value_ptr(mylight.position), -30.0f, 30.0f);
ImGui::Checkbox("Gamma Correction", &gamma_correction);
ImGui::Checkbox("Rotate Mode", ¢er_rotate);
ImGui::Checkbox("Poly Mode", &poly_mode);
ImGui::Checkbox("Debug Window", &debug_window);
ImGui::Checkbox("Cube Shadow", &cube_shadow_enabled);
ImGui::Checkbox("Soft Shadow", &multiCam);
ImGui::Checkbox("Peter Pan", &peter_pan);
ImGui::Checkbox("HDR", &HDR);
ImGui::Checkbox("Deferred", &deferred_shading);
ImGui::SliderFloat("rotate speed", &rotate_sensi, 0.0f, 1.0f);
ImGui::SliderFloat("walk speed", &walk_sensi, 0.0f, 0.1f);
if (ImGui::Button("Reset Cam")) {
cameraPos = glm::vec3(0.0f, 0.0f, -20.0f);
cameraTarget = glm::vec3(0.0f, 0.0f, 0.0f);
cameraUp = glm::vec3(0.0f, 1.0f, 0.0f);
cameraRight = glm::normalize(glm::cross(cameraUp, glm::normalize(cameraPos - cameraTarget)));
}
if (ImGui::Button("Reset Target")) {
cameraTarget = glm::vec3(0.0f, 0.0f, 0.0f);
}
if (ImGui::Button("Print Debug")) {
std::cout << glm::to_string(view_mat) << std::endl;
std::cout << glm::to_string(cameraPos) << std::endl;
// std::cout << "cam_pos: \n" << cam_pos << "\nview_mat: \n" << view_mat.matrix() << "\trans_cam: \n" << axis <<"\n ========================"<< std::endl;
}
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
ImGui::End();
}
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(window);
glfwPollEvents();
}
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}