Skip to content

Commit

Permalink
Add config options for palette saturation and lightness
Browse files Browse the repository at this point in the history
  • Loading branch information
pskelton committed Aug 8, 2024
1 parent d8cdca5 commit 9750d63
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/Application/GameConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,9 @@ class GameConfig : public Config {
"Filtering method when scaling rendered framebuffer to window dimensions if they differ."
" 0 - disabled (render dimensions will always match window dimensions), 1 - linear filter, 2 - nearest filter"};

Float Saturation = { this, "saturation", 0.65f, "Colour saturation multiplier for textures and palettes" };
Float Lightness = { this, "lightness", 1.1f, "Colour lightness multiplier for textures and palettes" };

private:
static int ValidateGamma(int level) {
return std::clamp(level, 0, 9);
Expand Down
7 changes: 5 additions & 2 deletions src/Engine/Graphics/PaletteManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "Library/Logger/Logger.h"

#include "Utility/String/Format.h"
#include <Engine/Engine.h>

PaletteManager *pPaletteManager = new PaletteManager;

Expand Down Expand Up @@ -57,12 +58,14 @@ Palette PaletteManager::createGrayscalePalette() {

Palette PaletteManager::createLoadedPalette(const Palette &palette) {
Palette result;
float satConfig = engine->config->graphics.Saturation.value();
float lightConfig = engine->config->graphics.Lightness.value();

for (size_t i = 0; i < 256; i++) {
HsvColorf hsv = palette.colors[i].toColorf().toHsv();

hsv.v = std::clamp(hsv.v * 1.1f, 0.0f, 1.0f); // TODO(pskelton): value multiplier 1.1 should be configurable
hsv.s = std::clamp(hsv.s * 0.64999998f, 0.0f, 1.0f); // TODO(pskelton): saturation multiplier 0.65 should be configurable
hsv.v = std::clamp(hsv.v * lightConfig, 0.0f, 1.0f);
hsv.s = std::clamp(hsv.s * satConfig, 0.0f, 1.0f);

result.colors[i] = hsv.toRgb().toColor();
}
Expand Down

0 comments on commit 9750d63

Please sign in to comment.