From fe58218c7e349e6a7435a3df8ae499214e162691 Mon Sep 17 00:00:00 2001 From: Hugo Willaume Date: Mon, 10 Jun 2019 14:02:05 +0900 Subject: [PATCH] Looks like the G-buffer debug is working alright --- BaseGLProject/DSGeometryPass.frag | 2 -- BaseGLProject/DSGeometryPass.vert | 4 +--- BaseGLProject/Loader.h | 4 +++- BaseGLProject/Models/Mesh.cpp | 6 +++--- BaseGLProject/MyGLWindow.cpp | 13 +++++++++---- BaseGLProject/SceneContext.h | 2 ++ BaseGLProject/Source.cpp | 23 +++++++++++++++++------ BaseGLProject/imgui.ini | 5 +++++ 8 files changed, 40 insertions(+), 19 deletions(-) diff --git a/BaseGLProject/DSGeometryPass.frag b/BaseGLProject/DSGeometryPass.frag index 5506a6c..c949452 100644 --- a/BaseGLProject/DSGeometryPass.frag +++ b/BaseGLProject/DSGeometryPass.frag @@ -12,8 +12,6 @@ uniform sampler2D tex; void main() { gPosition = FragPos; - //gPosition = normalize(abs(FragPos)); - //gPosition = vec3(1,1,1); gNormal = normalize(Normal); diff --git a/BaseGLProject/DSGeometryPass.vert b/BaseGLProject/DSGeometryPass.vert index bacc130..35c4808 100644 --- a/BaseGLProject/DSGeometryPass.vert +++ b/BaseGLProject/DSGeometryPass.vert @@ -15,10 +15,8 @@ uniform mat4 ModelMatrix; void main(void) { - Normal = v_normal * NormalMatrix; + Normal = NormalMatrix * v_normal; TexCoords = v_texmap; gl_Position = mvp * vec4(coord3d, 1.0f); FragPos = (ModelMatrix * vec4(coord3d, 1.0f)).xyz; - //FragPos = coord3.xyz; - //FragPos = gl_Position.xyz; } \ No newline at end of file diff --git a/BaseGLProject/Loader.h b/BaseGLProject/Loader.h index de5e02a..b0bf53e 100644 --- a/BaseGLProject/Loader.h +++ b/BaseGLProject/Loader.h @@ -96,7 +96,9 @@ private: glGetShaderiv(shaderId, GL_COMPILE_STATUS, &shaderStatus); if (shaderStatus == GL_FALSE) { - throw std::runtime_error(shaderTypeString + " compilation failed: " + getInfoLog(ObjectType::SHADER, shaderId)); + std::string err = getInfoLog(ObjectType::SHADER, shaderId); + std::cout << err << std::endl; + throw std::runtime_error(shaderTypeString + " compilation failed: " + err); } else { diff --git a/BaseGLProject/Models/Mesh.cpp b/BaseGLProject/Models/Mesh.cpp index 985f13f..410194a 100644 --- a/BaseGLProject/Models/Mesh.cpp +++ b/BaseGLProject/Models/Mesh.cpp @@ -352,11 +352,11 @@ void Mesh::draw(SceneContext &ctx) { ctx.modelMatrix = model.getMatrix(); ctx.mvpMatrix = ctx.projectionMatrix * ctx.viewMatrix * ctx.modelMatrix; ctx.modelViewMatrix = ctx.viewMatrix * ctx.modelMatrix; - ctx.normalMatrix = glm::mat3(glm::transpose(glm::inverse(ctx.modelViewMatrix))); + ctx.normalMatrix = glm::transpose(glm::inverse(glm::mat3(ctx.modelMatrix))); shader.addUniform("mvp", ctx.mvpMatrix); - //shader.addUniform("NormalMatrix", ctx.normalMatrix); - //shader.addUniform("ModelMatrix", ctx.modelMatrix); + shader.addUniform("NormalMatrix", ctx.normalMatrix); + shader.addUniform("ModelMatrix", ctx.modelMatrix); glActiveTexture(GL_TEXTURE0); diff --git a/BaseGLProject/MyGLWindow.cpp b/BaseGLProject/MyGLWindow.cpp index a81095e..e7f76d4 100644 --- a/BaseGLProject/MyGLWindow.cpp +++ b/BaseGLProject/MyGLWindow.cpp @@ -150,12 +150,12 @@ void MyGlWindow::setup() float pos_x = std::rand() % 100 - 50; float pos_z = std::rand() % 100 - 50; - /*meshes[cube_name]->addStartTranslation(glm::vec4(0, 1, 0, 0)); + meshes[cube_name]->addStartTranslation(glm::vec4(0, 1, 0, 0)); meshes[cube_name]->addStartTranslation(glm::vec4(pos_x, 0, 0, 0)); meshes[cube_name]->addStartTranslation(glm::vec4(0, 0, pos_z, 0)); meshes[cube_name]->addStartRotation(glm::vec4(1, 0, 0, std::rand() % 360)); meshes[cube_name]->addStartRotation(glm::vec4(0, 1, 0, std::rand() % 360)); - meshes[cube_name]->addStartRotation(glm::vec4(0, 0, 1, std::rand() % 360));*/ + meshes[cube_name]->addStartRotation(glm::vec4(0, 0, 1, std::rand() % 360)); float light_r = (40 + std::rand() % 60) / 100.f; float light_g = (40 + std::rand() % 60) / 100.f; @@ -184,12 +184,17 @@ void MyGlWindow::draw() glViewport(0, 0, _scnctx.width, _scnctx.height); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - _multipassManager.enableFrameBufferTexture("position_buffer"); + _multipassManager.enableFrameBufferTexture(_scnctx.fbo_display_name); + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); for (auto it = meshes.begin(); it != meshes.end(); it++) (*it).second->draw(_scnctx); - + + glDisable(GL_CULL_FACE); _multipassManager.drawResultToScreen(_scnctx); + + } void MyGlWindow::resize(int w, int h) diff --git a/BaseGLProject/SceneContext.h b/BaseGLProject/SceneContext.h index 5a44b92..775d24b 100644 --- a/BaseGLProject/SceneContext.h +++ b/BaseGLProject/SceneContext.h @@ -27,6 +27,8 @@ struct SceneContext GLuint width; glm::vec4 bg; + std::string fbo_display_name; + void adjustSpots() { for (auto it : lights) diff --git a/BaseGLProject/Source.cpp b/BaseGLProject/Source.cpp index 14a3c9b..72a030f 100644 --- a/BaseGLProject/Source.cpp +++ b/BaseGLProject/Source.cpp @@ -169,21 +169,32 @@ int loop(GLFWwindow *window) int fps = 60; double previousTime = glfwGetTime(); + glWin._scnctx.fbo_display_name = "position_buffer"; + bool is_selected = false; + while (!glfwWindowShouldClose(window)) { ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); - /*if (ImGui::Begin("First Window")) + if (ImGui::Begin("Scene settings")) { - ImGui::SetWindowPos(ImVec2(20, 20)); + if (ImGui::BeginCombo("Debug Buffer", "Choose here")) + { + if (ImGui::Selectable("Position buffer", &is_selected, 0, ImVec2(120, 10))) + glWin._scnctx.fbo_display_name = "position_buffer"; + if (ImGui::Selectable("Normal buffer", &is_selected, 0, ImVec2(120, 10))) + glWin._scnctx.fbo_display_name = "normal_buffer"; + if (ImGui::Selectable("Color buffer", &is_selected, 0, ImVec2(120, 10))) + glWin._scnctx.fbo_display_name = "color_buffer"; - static float bgColor[3] = { 0.6f, 0.6f, 0.9f }; - ImGui::ColorEdit3("Background", bgColor, 0); - glWin.setBgColor(bgColor); + ImGui::EndCombo(); + } + + ImGui::SetWindowPos(ImVec2(20, 20)); } - ImGui::End();*/ + ImGui::End(); double currentTime = glfwGetTime(); frameCount++; diff --git a/BaseGLProject/imgui.ini b/BaseGLProject/imgui.ini index a863f79..6ceff39 100644 --- a/BaseGLProject/imgui.ini +++ b/BaseGLProject/imgui.ini @@ -53,3 +53,8 @@ Pos=1030,20 Size=85,32 Collapsed=0 +[Window][Scene settings] +Pos=20,20 +Size=309,85 +Collapsed=0 +