Added being able to change attenuation in real time
This commit is contained in:
@@ -11,11 +11,11 @@ struct PointLight : Component
|
|||||||
{
|
{
|
||||||
PointLight()
|
PointLight()
|
||||||
: Specular(1.0f, 1.0f, 1.0f)
|
: Specular(1.0f, 1.0f, 1.0f)
|
||||||
, Diffuse(0.4f, 0.4f, 0.4f)
|
, Diffuse(1.0f, 1.0f, 1.0f)
|
||||||
, specularExponent(50.0f)
|
, specularExponent(50.0f)
|
||||||
, ConstantAttenuation(1.05f)
|
, ConstantAttenuation(1.0f)
|
||||||
, LinearAttenuation(0.f)
|
, LinearAttenuation(0.f)
|
||||||
, QuadraticAttenuation(2.55f)
|
, QuadraticAttenuation(3.f)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
float ConstantAttenuation, LinearAttenuation, QuadraticAttenuation;
|
float ConstantAttenuation, LinearAttenuation, QuadraticAttenuation;
|
||||||
|
|||||||
+54
-1
@@ -133,6 +133,9 @@ void Renderer::LoadContent()
|
|||||||
m_FinalPassProgram.Compile();
|
m_FinalPassProgram.Compile();
|
||||||
m_FinalPassProgram.Link();
|
m_FinalPassProgram.Link();
|
||||||
Gamma = 2.2f;
|
Gamma = 2.2f;
|
||||||
|
CAtt = 1.0f;
|
||||||
|
LAtt = 0.0f;
|
||||||
|
QAtt = 3.0f;
|
||||||
m_ScreenQuad = CreateQuad();
|
m_ScreenQuad = CreateQuad();
|
||||||
|
|
||||||
FrameBufferTextures();
|
FrameBufferTextures();
|
||||||
@@ -161,6 +164,49 @@ void Renderer::Draw(double dt)
|
|||||||
LOG_INFO("Gamma_DOWN: %f", Gamma);
|
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);
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
DrawFBO();
|
DrawFBO();
|
||||||
@@ -657,7 +703,7 @@ void Renderer::DrawFBO()
|
|||||||
m_FinalPassProgram.Bind();
|
m_FinalPassProgram.Bind();
|
||||||
|
|
||||||
// Ambient light
|
// 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);
|
glUniform1f(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "Gamma"), Gamma);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
@@ -733,6 +779,10 @@ void Renderer::DrawLightScene()
|
|||||||
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "LinearAttenuation"), light.LinearAttenuation);
|
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "LinearAttenuation"), light.LinearAttenuation);
|
||||||
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "QuadraticAttenuation"), light.QuadraticAttenuation);
|
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());
|
glDrawArrays(GL_TRIANGLES, 0, m_sphereModel->Vertices.size());
|
||||||
};
|
};
|
||||||
glEnable (GL_DEPTH_TEST);
|
glEnable (GL_DEPTH_TEST);
|
||||||
@@ -750,6 +800,9 @@ glm::mat4 Renderer::CreateLightMatrix(Light &_light)
|
|||||||
float c = _light.ConstantAttenuation;
|
float c = _light.ConstantAttenuation;
|
||||||
float l = _light.LinearAttenuation;
|
float l = _light.LinearAttenuation;
|
||||||
float q = _light.QuadraticAttenuation;
|
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));
|
float cutOffRadius = abs(sqrt((-4*c*q) + pow(l, 2) + (1024*q) - l) / (2*q));
|
||||||
|
|
||||||
glm::mat4 model;
|
glm::mat4 model;
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ private:
|
|||||||
bool m_DrawNormals;
|
bool m_DrawNormals;
|
||||||
bool m_DrawWireframe;
|
bool m_DrawWireframe;
|
||||||
bool m_DrawBounds;
|
bool m_DrawBounds;
|
||||||
|
float CAtt, LAtt, QAtt;
|
||||||
|
|
||||||
std::shared_ptr<Skybox> m_Skybox;
|
std::shared_ptr<Skybox> m_Skybox;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user