Skip to content

Commit

Permalink
Add gamma and exposure
Browse files Browse the repository at this point in the history
  • Loading branch information
pwalig committed Sep 2, 2024
1 parent 1ff3431 commit 835ecbc
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 9 deletions.
11 changes: 8 additions & 3 deletions src/f_pbr.glsl
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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_;
Expand Down Expand Up @@ -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);
}
30 changes: 24 additions & 6 deletions src/graphics_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,26 @@ game::graphics_menu::graphics_menu(const std::function<void()>& 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
Expand All @@ -53,6 +59,10 @@ game::graphics_menu::graphics_menu(const std::function<void()>& 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);
Expand All @@ -78,6 +88,14 @@ game::graphics_menu::graphics_menu(const std::function<void()>& 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");
Expand Down
5 changes: 5 additions & 0 deletions src/graphics_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/pbr_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
2 changes: 2 additions & 0 deletions src/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 835ecbc

Please sign in to comment.