From 37a8af6b65aa9e10ac771cf00c9c60ee11ec1e12 Mon Sep 17 00:00:00 2001 From: Tleety Date: Sun, 11 May 2014 01:05:22 +0200 Subject: [PATCH] Added being able to change attenuation in real time --- src/Components/PointLight.h | 6 ++-- src/Renderer.cpp | 55 ++++++++++++++++++++++++++++++++++++- src/Renderer.h | 1 + 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/Components/PointLight.h b/src/Components/PointLight.h index 646ea01..b08be67 100755 --- a/src/Components/PointLight.h +++ b/src/Components/PointLight.h @@ -11,11 +11,11 @@ struct PointLight : Component { PointLight() : Specular(1.0f, 1.0f, 1.0f) - , Diffuse(0.4f, 0.4f, 0.4f) + , Diffuse(1.0f, 1.0f, 1.0f) , specularExponent(50.0f) - , ConstantAttenuation(1.05f) + , ConstantAttenuation(1.0f) , LinearAttenuation(0.f) - , QuadraticAttenuation(2.55f) + , QuadraticAttenuation(3.f) { } float ConstantAttenuation, LinearAttenuation, QuadraticAttenuation; diff --git a/src/Renderer.cpp b/src/Renderer.cpp index b8204c7..f652a28 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -133,6 +133,9 @@ void Renderer::LoadContent() m_FinalPassProgram.Compile(); m_FinalPassProgram.Link(); Gamma = 2.2f; + CAtt = 1.0f; + LAtt = 0.0f; + QAtt = 3.0f; m_ScreenQuad = CreateQuad(); FrameBufferTextures(); @@ -161,6 +164,49 @@ void Renderer::Draw(double dt) LOG_INFO("Gamma_DOWN: %f", Gamma); } + if(glfwGetKey(m_Window, GLFW_KEY_1)) + { + if(glfwGetKey(m_Window, GLFW_KEY_KP_ADD)) + { + CAtt += 0.5f * dt; + LOG_INFO("Const: %f", CAtt); + } + if(glfwGetKey(m_Window, GLFW_KEY_KP_SUBTRACT)) + { + CAtt -= 0.5f * dt; + LOG_INFO("Const: %f", CAtt); + } + } + if(glfwGetKey(m_Window, GLFW_KEY_2)) + { + if(glfwGetKey(m_Window, GLFW_KEY_KP_ADD)) + { + LAtt += 0.5f * dt; + LOG_INFO("Linear: %f", LAtt); + } + if(glfwGetKey(m_Window, GLFW_KEY_KP_SUBTRACT)) + { + LAtt -= 0.5f * dt; + LOG_INFO("Linear: %f", LAtt); + } + } + if(glfwGetKey(m_Window, GLFW_KEY_3)) + { + if(glfwGetKey(m_Window, GLFW_KEY_KP_ADD)) + { + QAtt += 0.5f * dt; + LOG_INFO("Quadratic: %f", QAtt); + } + if(glfwGetKey(m_Window, GLFW_KEY_KP_SUBTRACT)) + { + QAtt -= 0.5f * dt; + LOG_INFO("Quadratic: %f", QAtt); + } + } + + + + glDisable(GL_BLEND); DrawFBO(); @@ -657,7 +703,7 @@ void Renderer::DrawFBO() m_FinalPassProgram.Bind(); // Ambient light - glUniform3fv(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "La"), 1, glm::value_ptr(glm::vec3(0.3f, 0.3f, 0.3f))); + glUniform3fv(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "La"), 1, glm::value_ptr(glm::vec3(0.1f, 0.1f, 0.1f))); glUniform1f(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "Gamma"), Gamma); glActiveTexture(GL_TEXTURE0); @@ -733,6 +779,10 @@ void Renderer::DrawLightScene() glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "LinearAttenuation"), light.LinearAttenuation); glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "QuadraticAttenuation"), light.QuadraticAttenuation); +// glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ConstantAttenuation"), CAtt); +// glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "LinearAttenuation"), LAtt); +// glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "QuadraticAttenuation"), QAtt); + glDrawArrays(GL_TRIANGLES, 0, m_sphereModel->Vertices.size()); }; glEnable (GL_DEPTH_TEST); @@ -750,6 +800,9 @@ glm::mat4 Renderer::CreateLightMatrix(Light &_light) float c = _light.ConstantAttenuation; float l = _light.LinearAttenuation; float q = _light.QuadraticAttenuation; +// float c = CAtt; +// float l = LAtt; +// float q = QAtt; float cutOffRadius = abs(sqrt((-4*c*q) + pow(l, 2) + (1024*q) - l) / (2*q)); glm::mat4 model; diff --git a/src/Renderer.h b/src/Renderer.h index f1f728e..672c6f6 100755 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -85,6 +85,7 @@ private: bool m_DrawNormals; bool m_DrawWireframe; bool m_DrawBounds; + float CAtt, LAtt, QAtt; std::shared_ptr m_Skybox;