diff --git a/src/f_pbr.glsl b/src/f_pbr.glsl index ae75d1e..aa76dca 100644 --- a/src/f_pbr.glsl +++ b/src/f_pbr.glsl @@ -1,6 +1,9 @@ #version 330 #define MAX_LIGHTS 32 +uniform float gamma = 2.2; +uniform float exposure = 1.0; + // texture maps uniform sampler2D albedo_map; uniform sampler2D normal_map; @@ -168,7 +171,7 @@ void main(void) { vec2 pTexCoords = parallaxTextureCoords(V, iTexCoord, 0.01, 10); // paralax texture coordinates vec3 N = normalize(2 * texture(normal_map, pTexCoords).xyz - 1); // normal vector in tbn space - vec3 albedo = pow(texture(albedo_map, pTexCoords).rgb, vec3(2.2)) * albedo_; + vec3 albedo = pow(texture(albedo_map, pTexCoords).rgb, vec3(gamma)) * albedo_; float alpha = texture(albedo_map, pTexCoords).a; vec4 data = texture(data_map, pTexCoords); float roughness = data.r * roughness_; @@ -206,8 +209,10 @@ void main(void) { vec3 color = Lo * (1.0 - min(emission, 1.0)) + (emission * albedo); - color = color / (color + vec3(1.0)); - color = pow(color, vec3(1.0 / 2.2)); + //color = color / (color + vec3(1.0)); + color = vec3(1.0) - exp(-color * exposure); + + color = pow(color, vec3(1.0 / gamma)); pixelColor = vec4(color, alpha); } diff --git a/src/graphics_menu.cpp b/src/graphics_menu.cpp index 9faaaa8..ce3d85b 100644 --- a/src/graphics_menu.cpp +++ b/src/graphics_menu.cpp @@ -21,20 +21,26 @@ game::graphics_menu::graphics_menu(const std::function& on_close) : glm::vec3(0.5f, 0.7f, 0.02f), glm::scale(glm::mat4(1.0f), glm::vec3(0.017f, 0.03f, 1.0f))), fullscreen_text("FULLSCREEN", "../assets/fonts/bitmap/handwiriting-readable.png", glm::vec3(0.5f, 0.65f, 0.02f), glm::scale(glm::mat4(1.0f), glm::vec3(0.017f, 0.03f, 1.0f))), - minimization_text("MINIMIZATION", "../assets/fonts/bitmap/handwiriting-readable.png", + gamma_text("GAMMA: " + std::to_string(renderer::gamma), "../assets/fonts/bitmap/handwiriting-readable.png", glm::vec3(0.5f, 0.6f, 0.02f), glm::scale(glm::mat4(1.0f), glm::vec3(0.017f, 0.03f, 1.0f))), + exposure_text("EXPOSURE: " + std::to_string(renderer::exposure), "../assets/fonts/bitmap/handwiriting-readable.png", + glm::vec3(0.5f, 0.5f, 0.02f), glm::scale(glm::mat4(1.0f), glm::vec3(0.017f, 0.03f, 1.0f))), + minimization_text("MINIMIZATION", "../assets/fonts/bitmap/handwiriting-readable.png", + glm::vec3(0.25f, 0.6f, 0.02f), glm::scale(glm::mat4(1.0f), glm::vec3(0.017f, 0.03f, 1.0f))), magnification_text("MAGNIFICATION", "../assets/fonts/bitmap/handwiriting-readable.png", - glm::vec3(0.5f, 0.45f, 0.02f), glm::scale(glm::mat4(1.0f), glm::vec3(0.017f, 0.03f, 1.0f))), + glm::vec3(0.25f, 0.45f, 0.02f), glm::scale(glm::mat4(1.0f), glm::vec3(0.017f, 0.03f, 1.0f))), anisotropy_text("ANISOTROPY : ", "../assets/fonts/bitmap/handwiriting-readable.png", - glm::vec3(0.5f, 0.3f, 0.02f), glm::scale(glm::mat4(1.0f), glm::vec3(0.017f, 0.03f, 1.0f))), + glm::vec3(0.25f, 0.3f, 0.02f), glm::scale(glm::mat4(1.0f), glm::vec3(0.017f, 0.03f, 1.0f))), fov(glm::vec3(0.5f, 0.85f, 0.02f), glm::vec2(0.12f, 0.02f)), framerate(glm::vec3(0.5f, 0.75f, 0.02f), glm::vec2(0.12f, 0.02f)), framerate_enable(glm::vec3(0.6f, 0.75f, 0.02f), glm::vec2(0.015f, 0.015f)), vsynch(glm::vec3(0.6f, 0.7f, 0.02f), glm::vec2(0.015f, 0.015f)), fullscreen(glm::vec3(0.6f, 0.65f, 0.02f), glm::vec2(0.015f, 0.015f)), - minimization(glm::vec3(0.5f, 0.55f, 0.016f), glm::vec2(0.12f, 0.02f)), - magnification(glm::vec3(0.5f, 0.4f, 0.018f), glm::vec2(0.12f, 0.02f)), - anisotropy(glm::vec3(0.5f, 0.25f, 0.02f), glm::vec2(0.12f, 0.02f)), + gamma(glm::vec3(0.5f, 0.55f, 0.02f), glm::vec2(0.12f, 0.02f)), + exposure(glm::vec3(0.5f, 0.45f, 0.02f), glm::vec2(0.12f, 0.02f)), + minimization(glm::vec3(0.25f, 0.55f, 0.016f), glm::vec2(0.12f, 0.02f)), + magnification(glm::vec3(0.25f, 0.4f, 0.018f), glm::vec2(0.12f, 0.02f)), + anisotropy(glm::vec3(0.25f, 0.25f, 0.02f), glm::vec2(0.12f, 0.02f)), back(glm::vec3(0.5f, 0.1f, 0.02f), glm::vec2(0.07f, 0.03f), "../assets/textures/White_Square.png", "BACK", "../assets/fonts/bitmap/handwiriting-readable.png") { // singleton stuff @@ -53,6 +59,10 @@ game::graphics_menu::graphics_menu(const std::function& on_close) : framerate_enable.update_check(framerate_cap_enable); vsynch.update_check(vsynch_enabled); fullscreen.update_check(engine::is_fullscreen); + gamma.value = renderer::gamma / 5.0f; + gamma.update_visual(); + exposure.value = renderer::exposure / 5.0f; + exposure.update_visual(); float maxAnisotropy; glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY, &maxAnisotropy); anisotropy_text.text += std::to_string(maxAnisotropy); @@ -78,6 +88,14 @@ game::graphics_menu::graphics_menu(const std::function& on_close) : fullscreen.on_click.subscribe([this]() { game::gameplay_manager::full_screen(); }); + gamma.on_value_changed = [this](float new_gamma) { + renderer::gamma = new_gamma * 5.0f; + this->gamma_text.text = "GAMMA: " + std::to_string(renderer::gamma); + }; + exposure.on_value_changed = [this](float new_exposure) { + renderer::exposure = new_exposure * 5.0f; + this->exposure_text.text = "EXPOSURE: " + std::to_string(renderer::exposure); + }; minimization.values.push_back("NEAREST"); minimization.values.push_back("LINEAR"); minimization.values.push_back("NEAREST MIPMAP NEAREST"); diff --git a/src/graphics_menu.h b/src/graphics_menu.h index 758a356..a065bef 100644 --- a/src/graphics_menu.h +++ b/src/graphics_menu.h @@ -19,6 +19,11 @@ namespace game { ui_system::ui_checkbox fullscreen; ui_system::ui_text fullscreen_text; + ui_system::ui_slider gamma; + ui_system::ui_text gamma_text; + ui_system::ui_slider exposure; + ui_system::ui_text exposure_text; + ui_system::ui_dropdown minimization; ui_system::ui_text minimization_text; ui_system::ui_dropdown magnification; diff --git a/src/pbr_model.cpp b/src/pbr_model.cpp index 8ecec69..c1debce 100644 --- a/src/pbr_model.cpp +++ b/src/pbr_model.cpp @@ -22,6 +22,9 @@ renderer::pbr_model::pbr_model( void renderer::pbr_model::draw() { spPBR->use();//Aktywacja programu cieniującego + glUniform1f(spPBR->u("gamma"), renderer::gamma); + glUniform1f(spPBR->u("exposure"), renderer::exposure); + //Przeslij parametry programu cieniującego do karty graficznej glUniformMatrix4fv(spPBR->u("P"), 1, false, glm::value_ptr(renderer::active_camera.get_P())); glUniformMatrix4fv(spPBR->u("V"), 1, false, glm::value_ptr(renderer::active_camera.get_V())); diff --git a/src/renderer.cpp b/src/renderer.cpp index 5aef2ae..513b4be 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -9,6 +9,8 @@ renderer::camera renderer::active_camera; float renderer::global_fov = 70.0f; +float renderer::gamma = 2.2f; +float renderer::exposure = 1.0f; void renderer::draw_scene(GLFWwindow* window) { //************Place any code here that draws something inside the window******************l diff --git a/src/renderer.h b/src/renderer.h index d51d13e..cf50879 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -8,6 +8,8 @@ namespace renderer { extern renderer::camera active_camera; extern float global_fov; + extern float gamma; + extern float exposure; void draw_scene(GLFWwindow* window);