Added ambient lighting
This commit is contained in:
parent
482205b96e
commit
3f6e2c2b6b
|
@ -225,8 +225,7 @@ int main(int argc, char** argv)
|
||||||
shader->Use();
|
shader->Use();
|
||||||
shader->SetUniformTexture("texture1", crate, 0);
|
shader->SetUniformTexture("texture1", crate, 0);
|
||||||
shader->SetUniformTexture("texture2", opengl, 1);
|
shader->SetUniformTexture("texture2", opengl, 1);
|
||||||
shader->SetUniform("ambientStrength", ambient.intensity);
|
shader->SetUniform("ambientColor", "ambientStrength", ambient);
|
||||||
shader->SetUniform("ambientColor", ambient.color, true);
|
|
||||||
shader->SetUniformMatrix4fv("view", 1, GL_FALSE, glm::value_ptr(camera.GetMatrix()));
|
shader->SetUniformMatrix4fv("view", 1, GL_FALSE, glm::value_ptr(camera.GetMatrix()));
|
||||||
shader->SetUniformMatrix4fv("projection", 1, GL_FALSE, glm::value_ptr(camera.GetProjection()));
|
shader->SetUniformMatrix4fv("projection", 1, GL_FALSE, glm::value_ptr(camera.GetProjection()));
|
||||||
|
|
||||||
|
@ -237,10 +236,27 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::Begin("Test");
|
ImGui::Begin("Test");
|
||||||
ImGui::ColorEdit3("Background color", &bgColor.r);
|
|
||||||
ImGui::SliderFloat("FOV", &camera.fov, 30.0f, 100.0f);
|
if(ImGui::CollapsingHeader("Scene"));
|
||||||
ImGui::SliderFloat("zNear", &camera.zNear, 0.01, 1.0f);
|
{
|
||||||
ImGui::SliderFloat("zFar", &camera.zFar, 2.0f, 100.0f);
|
ImGui::ColorEdit3("Background color", &bgColor.r);
|
||||||
|
ImGui::SliderFloat("FOV", &camera.fov, 30.0f, 100.0f);
|
||||||
|
ImGui::SliderFloat("zNear", &camera.zNear, 0.01, 1.0f);
|
||||||
|
ImGui::SliderFloat("zFar", &camera.zFar, 2.0f, 100.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ImGui::CollapsingHeader("Lighting"))
|
||||||
|
{
|
||||||
|
if (ImGui::TreeNode("Ambient"))
|
||||||
|
{
|
||||||
|
ImGui::ColorEdit3("Color", &ambient.color.r);
|
||||||
|
ImGui::SliderFloat("Intensity", &ambient.intensity, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
ImGui::TreePop();
|
||||||
|
ImGui::Separator();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
|
|
|
@ -16,6 +16,7 @@ namespace oglu
|
||||||
class Color;
|
class Color;
|
||||||
class AbstractTexture;
|
class AbstractTexture;
|
||||||
class Transformable;
|
class Transformable;
|
||||||
|
class AmbientLight;
|
||||||
|
|
||||||
typedef std::shared_ptr<AbstractTexture> Texture;
|
typedef std::shared_ptr<AbstractTexture> Texture;
|
||||||
|
|
||||||
|
@ -338,6 +339,28 @@ namespace oglu
|
||||||
*/
|
*/
|
||||||
void SetUniform(GLint location, Transformable& v0, GLboolean transpose = GL_FALSE);
|
void SetUniform(GLint location, Transformable& v0, GLboolean transpose = GL_FALSE);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the ambient lighting.
|
||||||
|
*
|
||||||
|
* This function sets two variables, the ambient color and the intensity
|
||||||
|
*
|
||||||
|
* @param[in] colorName The name of the uniform holding the color information (must be vec3)
|
||||||
|
* @param[in] intensityName The name of the uniform holding the intensity information (must be float)
|
||||||
|
* @param[in] v0 A reference to an AmbientLight
|
||||||
|
*/
|
||||||
|
void SetUniform(const GLchar* colorName, const GLchar* intensityName, const AmbientLight& v0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the ambient lighting.
|
||||||
|
*
|
||||||
|
* This function sets two variables, the ambient color and the intensity
|
||||||
|
*
|
||||||
|
* @param[in] colorLocation The location of the uniform holding the color information (must be vec3)
|
||||||
|
* @param[in] intensityLocation The location of the uniform holding the intensity information (must be float)
|
||||||
|
* @param[in] v0 A reference to an AmbientLight
|
||||||
|
*/
|
||||||
|
void SetUniform(GLint colorLocation, GLint intensityLocation, const AmbientLight& v0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set array of uniform float.
|
* @brief Set array of uniform float.
|
||||||
*
|
*
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <color.hpp>
|
#include <color.hpp>
|
||||||
#include <texture.hpp>
|
#include <texture.hpp>
|
||||||
#include <transformable.hpp>
|
#include <transformable.hpp>
|
||||||
|
#include <lighting/ambient.hpp>
|
||||||
|
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
|
||||||
|
@ -259,6 +260,21 @@ namespace oglu
|
||||||
glUniformMatrix4fv(location, 1, transpose, glm::value_ptr(v0.GetMatrix()));
|
glUniformMatrix4fv(location, 1, transpose, glm::value_ptr(v0.GetMatrix()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AbstractShader::SetUniform(const GLchar* colorName, const GLchar* intensityName, const AmbientLight& v0)
|
||||||
|
{
|
||||||
|
SetUniform(
|
||||||
|
glGetUniformLocation(program, colorName),
|
||||||
|
glGetUniformLocation(program, intensityName),
|
||||||
|
v0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractShader::SetUniform(GLint colorLocation, GLint intensityLocation, const AmbientLight& v0)
|
||||||
|
{
|
||||||
|
SetUniform(colorLocation, v0.color, true);
|
||||||
|
SetUniform(intensityLocation, v0.intensity);
|
||||||
|
}
|
||||||
|
|
||||||
void AbstractShader::SetUniform1fv(const GLchar* name, GLsizei count, const GLfloat* value)
|
void AbstractShader::SetUniform1fv(const GLchar* name, GLsizei count, const GLfloat* value)
|
||||||
{
|
{
|
||||||
glUniform1fv(glGetUniformLocation(program, name), count, value);
|
glUniform1fv(glGetUniformLocation(program, name), count, value);
|
||||||
|
|
Loading…
Reference in a new issue