Skip to content

Commit

Permalink
brightness slider
Browse files Browse the repository at this point in the history
  • Loading branch information
Kade-github committed May 23, 2024
1 parent e10a5a8 commit 65ce41d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 7 deletions.
10 changes: 8 additions & 2 deletions Assets/Shaders/frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ uniform float FogFar;
uniform vec3 FogColor;
uniform float lightLevel;
uniform float redness;
uniform float brightness;

float FogMin = 0.0;

float getFogFactor(float d)
Expand Down Expand Up @@ -66,7 +68,11 @@ void main()

FragColor = mix(FragColor, vec4(1.0, 0.0, 0.0, FragColor.a), redness);

// Adjust brightness and contrast

FragColor = vec4(FragColor.rgb * brightness, FragColor.a);

if (FogFar < 1000)
FragColor = mix(FragColor, vec4(FogColor, FragColor.a), fogFactor);
FragColor = mix(FragColor, vec4(FogColor.rgb * brightness, FragColor.a), fogFactor);

}
}
4 changes: 3 additions & 1 deletion src/Game/Data/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Settings

float masterVolume = 0.2f;

float brightness = 1.0f;

bool vsync = true;
bool fullscreen = false;

Expand All @@ -26,7 +28,7 @@ class Settings
void Load();
void Save();

MSGPACK_DEFINE_ARRAY(fov, renderDistance, fogDistance, vsync, fullscreen, masterVolume, useAmbientDiffuse);
MSGPACK_DEFINE_ARRAY(fov, renderDistance, fogDistance, vsync, fullscreen, masterVolume, useAmbientDiffuse, brightness);
};

#endif
3 changes: 3 additions & 0 deletions src/Game/LightingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "WorldManager.h"
#include <glad/glad.h>
#include <Game.h>
#include "Data/Settings.h"
#include "Scenes/Gameplay.h"

LightingManager* LightingManager::instance = nullptr;
Expand Down Expand Up @@ -145,6 +146,8 @@ void LightingManager::SunColor()
sun.color = glm::mix(sun.color, cave, std::lerp(0, lastMax, caveLerp));
}

sun.color *= Settings::instance->brightness;

glClearColor(sun.color.x, sun.color.y, sun.color.z, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

Expand Down
1 change: 1 addition & 0 deletions src/Game/Scenes/Gameplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ void Gameplay::Draw()
Game::instance->shader->SetUniform1f("lightLevel", 10.0f);
Game::instance->shader->SetUniform1f("redness", 0.0f);
Game::instance->shader->SetUniform1i("useAmbientDiffusion", (int)Settings::instance->useAmbientDiffuse);
Game::instance->shader->SetUniform1f("brightness", Settings::instance->brightness);

Game::instance->shader->Unbind();

Expand Down
24 changes: 20 additions & 4 deletions src/Game/Scenes/SettingsMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,44 @@ void SettingsMenu::Create()

ambientDiffuse = new Bar(glm::vec3(0, 0, 0), "Ambient Diffusion: " + std::string(Settings::instance->useAmbientDiffuse ? "on" : "off"));

ambientDiffuse->position = glm::vec3(c2d->_w / 2, c2d->_h / 2 + 300, 0);
ambientDiffuse->position = glm::vec3(c2d->_w / 2, c2d->_h / 2 + 200, 0);

ambientDiffuse->position -= glm::vec3(ambientDiffuse->width / 2, 0, 0);

c2d->AddObject(ambientDiffuse);

vsync = new Bar(glm::vec3(0, 0, 0), "VSync: " + std::string(Settings::instance->vsync ? "on" : "off"));

vsync->position = glm::vec3(c2d->_w / 2, (c2d->_h / 2) + 200, 0);
vsync->position = glm::vec3(c2d->_w / 2, (c2d->_h / 2) + 100, 0);

vsync->position -= glm::vec3(vsync->width / 2, 0, 0);

c2d->AddObject(vsync);

fullscreen = new Bar(glm::vec3(0, 0, 0), "Fullscreen: " + std::string(Settings::instance->fullscreen ? "on" : "off"));

fullscreen->position = glm::vec3(c2d->_w / 2, c2d->_h / 2 + 100, 0);
fullscreen->position = glm::vec3(c2d->_w / 2, c2d->_h / 2, 0);

fullscreen->position -= glm::vec3(fullscreen->width / 2, 0, 0);

c2d->AddObject(fullscreen);

float brightnessPerc = Settings::instance->brightness;

brightness = new DragBar(glm::vec3(0, 0, 0), "Brightness", brightnessPerc);

brightness->max = 2.0f;

brightness->min = 0.1f;

brightness->UpdateBar();

brightness->position = glm::vec3(c2d->_w / 2, c2d->_h / 2 + 100, 0);

brightness->position -= glm::vec3(brightness->width / 2, 0, 0);

c2d->AddObject(brightness);

float fovPerc = Settings::instance->fov;

fov = new DragBar(glm::vec3(0, 0, 0), "FOV", fovPerc);
Expand Down Expand Up @@ -194,7 +210,7 @@ void SettingsMenu::Destroy()
Settings::instance->fov = fov->value;
Settings::instance->renderDistance = renderDistance->value;
Settings::instance->fogDistance = fogDistance->value;

Settings::instance->brightness = brightness->value;

Settings::instance->Save();
Scene::Destroy();
Expand Down
1 change: 1 addition & 0 deletions src/Game/Scenes/SettingsMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SettingsMenu : public Scene
Bar* fullscreen;
Bar* ambientDiffuse;

DragBar* brightness;
DragBar* fov;
DragBar* renderDistance;
DragBar* fogDistance;
Expand Down

0 comments on commit 65ce41d

Please sign in to comment.