generated from karl/cpp-template
66 lines
2.3 KiB
C++
66 lines
2.3 KiB
C++
#include "BumpMapDemo.h"
|
|
#include "Input.h"
|
|
#include <glm/common.hpp>
|
|
|
|
BumpMapDemo::BumpMapDemo()
|
|
: number_of_steps(10.0), number_of_refinement_steps(10.0), bump_depth(0.1),
|
|
render_shader(Shader("Shader/bump.vs", "Shader/bump.fs")),
|
|
camera(Camera(90, 1920, 1080, 0.1, 1000.0)),
|
|
albedo("Resources/Textures/PavingStones/PavingStones070_2K_Color.jpg", Texture::Settings()),
|
|
bump("Resources/Textures/PavingStones/PavingStones070_2K_Displacement.jpg",
|
|
Texture::Settings()),
|
|
normal("Resources/Textures/PavingStones/PavingStones070_2K_Normal.jpg", Texture::Settings()) {
|
|
// Move and rotate the camera so we see the quad well
|
|
camera.translate(glm::vec3(0.0, -1.0, 1.0));
|
|
camera.rotate(30, glm::vec3(1.0, 0.0, 0.0));
|
|
}
|
|
|
|
void BumpMapDemo::render(float delta) {
|
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
render_shader.use();
|
|
|
|
// Camera
|
|
render_shader.setMat4("projection", camera.get_projection());
|
|
render_shader.setMat4("view", camera.get_view());
|
|
render_shader.setVec3("viewPos", camera.get_translation());
|
|
|
|
// Lighting
|
|
render_shader.setVec3("lightPos", glm::vec3(0.0, 1.0, 5.0));
|
|
|
|
// Settings for bump mapping
|
|
if (Input::is_key_down(GLFW_KEY_Q)) {
|
|
number_of_steps += delta * 5.0;
|
|
}
|
|
if (Input::is_key_down(GLFW_KEY_W)) {
|
|
number_of_steps -= delta * 5.0;
|
|
}
|
|
if (Input::is_key_down(GLFW_KEY_A)) {
|
|
number_of_refinement_steps += delta * 5.0;
|
|
}
|
|
if (Input::is_key_down(GLFW_KEY_S)) {
|
|
number_of_refinement_steps -= delta * 5.0;
|
|
}
|
|
if (Input::is_key_down(GLFW_KEY_Z)) {
|
|
bump_depth += delta * 0.1;
|
|
}
|
|
if (Input::is_key_down(GLFW_KEY_X)) {
|
|
bump_depth -= delta * 0.1;
|
|
}
|
|
|
|
render_shader.setFloat("number_of_steps", glm::max(0.0f, number_of_steps));
|
|
render_shader.setFloat("number_of_refinement_steps",
|
|
glm::max(0.0f, number_of_refinement_steps));
|
|
render_shader.setFloat("bump_depth", glm::max(0.0f, bump_depth));
|
|
|
|
// Textures
|
|
albedo.bind_to(0);
|
|
normal.bind_to(1);
|
|
bump.bind_to(2);
|
|
|
|
// Quad which is rendered onto
|
|
quad_mesh.rotate(delta * 25.0f, glm::normalize(glm::vec3(0.0, 0.0, 1.0)));
|
|
quad_mesh.render(render_shader);
|
|
}
|