Added ambient lighting
This commit is contained in:
parent
dea312a704
commit
482205b96e
|
@ -33,6 +33,8 @@ file(GLOB_RECURSE source_files
|
||||||
"vendor/src/*.c"
|
"vendor/src/*.c"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
message(STATUS ${source_files})
|
||||||
|
|
||||||
add_library(openglu SHARED
|
add_library(openglu SHARED
|
||||||
${include_files}
|
${include_files}
|
||||||
${source_files}
|
${source_files}
|
||||||
|
|
|
@ -32,8 +32,8 @@ add_custom_command(TARGET movement POST_BUILD
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/assets $<TARGET_FILE_DIR:movement>/assets
|
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/assets $<TARGET_FILE_DIR:movement>/assets
|
||||||
)
|
)
|
||||||
|
|
||||||
# if(WIN32)
|
if(WIN32)
|
||||||
# add_custom_command(TARGET movement POST_BUILD
|
add_custom_command(TARGET movement POST_BUILD
|
||||||
# COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:openglu> $<TARGET_FILE:glfw> $<TARGET_FILE_DIR:movement>
|
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:openglu> $<TARGET_FILE:glfw> $<TARGET_FILE_DIR:movement>
|
||||||
# )
|
)
|
||||||
# endif()
|
endif()
|
|
@ -201,6 +201,9 @@ int main(int argc, char** argv)
|
||||||
oglu::Texture crate = oglu::MakeTexture("assets/crate.jpg");
|
oglu::Texture crate = oglu::MakeTexture("assets/crate.jpg");
|
||||||
oglu::Texture opengl = oglu::MakeTexture("assets/opengl.png");
|
oglu::Texture opengl = oglu::MakeTexture("assets/opengl.png");
|
||||||
|
|
||||||
|
oglu::AmbientLight ambient;
|
||||||
|
ambient.intensity = 0.1f;
|
||||||
|
|
||||||
camera.Move(0.0f, 0.0f, 5.0f);
|
camera.Move(0.0f, 0.0f, 5.0f);
|
||||||
|
|
||||||
// Window loop
|
// Window loop
|
||||||
|
@ -209,7 +212,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||||
|
|
||||||
oglu::Color bgColor(0.29f, 0.13f, 0.23f);
|
oglu::Color bgColor = oglu::Color::Black;
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
processInput(window);
|
processInput(window);
|
||||||
|
@ -222,6 +225,8 @@ 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", 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()));
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,12 @@ out vec4 FragColor;
|
||||||
uniform sampler2D texture1;
|
uniform sampler2D texture1;
|
||||||
uniform sampler2D texture2;
|
uniform sampler2D texture2;
|
||||||
|
|
||||||
|
uniform float ambientStrength;
|
||||||
|
uniform vec3 ambientColor;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
FragColor = mix(texture(texture1, oUV), texture(texture2, oUV), 0.2);
|
vec3 ambient = ambientColor * ambientStrength;
|
||||||
|
|
||||||
|
FragColor = mix(texture(texture1, oUV), texture(texture2, oUV), 0.2) * vec4(ambient, 1.0);
|
||||||
}
|
}
|
|
@ -33,7 +33,7 @@ namespace oglu
|
||||||
* @param green Green component
|
* @param green Green component
|
||||||
* @param alpha Red component
|
* @param alpha Red component
|
||||||
*/
|
*/
|
||||||
Color(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha = 255);
|
Color(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha = 0.f);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GLfloat r; ///< Red channel
|
GLfloat r; ///< Red channel
|
||||||
|
|
22
include/lighting/ambient.hpp
Normal file
22
include/lighting/ambient.hpp
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef AMBIENT_HPP
|
||||||
|
#define AMBIENT_HPP
|
||||||
|
|
||||||
|
#include <core.hpp>
|
||||||
|
#include <color.hpp>
|
||||||
|
|
||||||
|
namespace oglu
|
||||||
|
{
|
||||||
|
class OGLU_API AmbientLight
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AmbientLight();
|
||||||
|
AmbientLight(GLfloat r, GLfloat g, GLfloat b, GLfloat intensity);
|
||||||
|
AmbientLight(const Color& color, GLfloat intensity);
|
||||||
|
AmbientLight(const AmbientLight& other);
|
||||||
|
|
||||||
|
GLfloat intensity;
|
||||||
|
Color color;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -15,6 +15,8 @@
|
||||||
#include <object.hpp>
|
#include <object.hpp>
|
||||||
#include <camera.hpp>
|
#include <camera.hpp>
|
||||||
|
|
||||||
|
#include <lighting/ambient.hpp>
|
||||||
|
|
||||||
namespace oglu
|
namespace oglu
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace oglu
|
||||||
const Color Color::Transparent(0.f, 0.f, 0.f, 0.f);
|
const Color Color::Transparent(0.f, 0.f, 0.f, 0.f);
|
||||||
|
|
||||||
Color::Color() :
|
Color::Color() :
|
||||||
r(0.f), g(0.f), b(0.f), a(0.f)
|
r(0.f), g(0.f), b(0.f), a(1.f)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
24
src/lighting/ambient.cpp
Normal file
24
src/lighting/ambient.cpp
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#include "lighting/ambient.hpp"
|
||||||
|
|
||||||
|
namespace oglu
|
||||||
|
{
|
||||||
|
AmbientLight::AmbientLight() :
|
||||||
|
color(1.f, 1.f, 1.f), intensity(1.0f)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
AmbientLight::AmbientLight(GLfloat r, GLfloat g, GLfloat b, GLfloat intensity) :
|
||||||
|
color(r, g, b), intensity(intensity)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
AmbientLight::AmbientLight(const Color& color, GLfloat intensity) :
|
||||||
|
color(color), intensity(intensity)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
AmbientLight::AmbientLight(const AmbientLight& other) :
|
||||||
|
color(other.color), intensity(other.intensity)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue