Implement gamma correction in main config menu

This commit is contained in:
rainmakerv2 2024-12-16 19:01:00 +08:00
parent 8a4e03228a
commit 45426910e0
9 changed files with 79 additions and 21 deletions

View File

@ -64,6 +64,7 @@ static bool vkCrashDiagnostic = false;
static s16 cursorState = HideCursorState::Idle;
static int cursorHideTimeout = 5; // 5 seconds (default)
static bool separateupdatefolder = false;
static int GammaValue = 1000;
// Gui
std::vector<std::filesystem::path> settings_install_dirs = {};
@ -224,6 +225,10 @@ bool getSeparateUpdateEnabled() {
return separateupdatefolder;
}
int getGammaValue() {
return GammaValue;
}
void setGpuId(s32 selectedGpuId) {
gpuId = selectedGpuId;
}
@ -344,6 +349,10 @@ void setSeparateUpdateEnabled(bool use) {
separateupdatefolder = use;
}
void setGammaValue(int value) {
GammaValue = value;
}
void setMainWindowGeometry(u32 x, u32 y, u32 w, u32 h) {
main_window_geometry_x = x;
main_window_geometry_y = y;
@ -566,6 +575,7 @@ void load(const std::filesystem::path& path) {
shouldDumpShaders = toml::find_or<bool>(gpu, "dumpShaders", false);
shouldPatchShaders = toml::find_or<bool>(gpu, "patchShaders", true);
vblankDivider = toml::find_or<int>(gpu, "vblankDivider", 1);
GammaValue = toml::find_or<int>(gpu, "GammaValue", 1000);
}
if (data.contains("Vulkan")) {
@ -668,6 +678,7 @@ void save(const std::filesystem::path& path) {
data["GPU"]["dumpShaders"] = shouldDumpShaders;
data["GPU"]["patchShaders"] = shouldPatchShaders;
data["GPU"]["vblankDivider"] = vblankDivider;
data["GPU"]["GammaValue"] = GammaValue;
data["Vulkan"]["gpuId"] = gpuId;
data["Vulkan"]["validation"] = vkValidation;
data["Vulkan"]["validation_sync"] = vkValidationSync;
@ -775,6 +786,7 @@ void setDefaultValues() {
m_language = 1;
gpuId = -1;
separateupdatefolder = false;
GammaValue = 1000;
}
} // namespace Config
} // namespace Config

View File

@ -21,6 +21,7 @@ bool getPlayBGM();
int getBGMvolume();
bool getEnableDiscordRPC();
bool getSeparateUpdateEnabled();
int getGammaValue();
std::string getLogFilter();
std::string getLogType();
@ -68,6 +69,7 @@ void setNeoMode(bool enable);
void setUserName(const std::string& type);
void setUpdateChannel(const std::string& type);
void setSeparateUpdateEnabled(bool use);
void setGammaValue(int value);
void setGameInstallDirs(const std::vector<std::filesystem::path>& settings_install_dirs_config);
void setCursorState(s16 cursorState);

View File

@ -26,6 +26,8 @@
#include "common/discord_rpc_handler.h"
#endif
bool isGameRunning = false;
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
installEventFilter(this);

View File

@ -22,6 +22,7 @@
#include "main_window_ui.h"
#include "pkg_viewer.h"
extern bool isGameRunning;
class GameListFrame;
class MainWindow : public QMainWindow {
@ -70,7 +71,6 @@ private:
QIcon RecolorIcon(const QIcon& icon, bool isWhite);
bool isIconBlack = false;
bool isTableList = true;
bool isGameRunning = false;
QActionGroup* m_icon_size_act_group = nullptr;
QActionGroup* m_list_mode_act_group = nullptr;
QActionGroup* m_theme_act_group = nullptr;

View File

@ -19,6 +19,9 @@
#include "main_window.h"
#include "settings_dialog.h"
#include "ui_settings_dialog.h"
#include "video_core/renderer_vulkan/vk_presenter.h"
extern std::unique_ptr<Vulkan::Presenter> presenter;
QStringList languageNames = {"Arabic",
"Czech",
"Danish",
@ -108,6 +111,7 @@ SettingsDialog::SettingsDialog(std::span<const QString> physical_devices, QWidge
} else if (button == ui->buttonBox->button(QDialogButtonBox::Close)) {
ResetInstallFolders();
}
if (Common::Log::IsActive()) {
Common::Log::Filter filter;
filter.ParseFilterString(Config::getLogFilter());
@ -148,6 +152,13 @@ SettingsDialog::SettingsDialog(std::span<const QString> physical_devices, QWidge
[this](s16 index) { OnCursorStateChanged(index); });
}
// Graphics TAB
{
connect(ui->GammaSlider, &QSlider::valueChanged, this,
[this](int value) { GammaSliderChange(value); });
connect(ui->ResetGammaButton, &QPushButton::clicked, this, [this]() { ResetGamma(); });
}
// PATH TAB
{
connect(ui->addFolderButton, &QPushButton::clicked, this, [this]() {
@ -207,6 +218,7 @@ SettingsDialog::SettingsDialog(std::span<const QString> physical_devices, QWidge
ui->heightDivider->installEventFilter(this);
ui->dumpShadersCheckBox->installEventFilter(this);
ui->nullGpuCheckBox->installEventFilter(this);
ui->GammaSlider->installEventFilter(this);
// Paths
ui->gameFoldersGroupBox->installEventFilter(this);
@ -282,6 +294,7 @@ void SettingsDialog::LoadValuesFromConfig() {
ui->vkSyncValidationCheckBox->setChecked(
toml::find_or<bool>(data, "Vulkan", "validation_sync", false));
ui->rdocCheckBox->setChecked(toml::find_or<bool>(data, "Vulkan", "rdocEnable", false));
ui->GammaSlider->setValue(toml::find_or<int>(data, "GPU", "GammaValue", 1000));
#ifdef ENABLE_UPDATER
ui->updateCheckBox->setChecked(toml::find_or<bool>(data, "General", "autoUpdate", false));
@ -361,6 +374,18 @@ void SettingsDialog::OnCursorStateChanged(s16 index) {
}
}
void SettingsDialog::GammaSliderChange(int value) {
float Gammafloat = static_cast<float>((value / 1000.0f));
if (isGameRunning) {
presenter->GetGammaRef() = Gammafloat;
}
}
void SettingsDialog::ResetGamma() {
ui->GammaSlider->setValue(1000);
}
int SettingsDialog::exec() {
return QDialog::exec();
}
@ -509,6 +534,7 @@ void SettingsDialog::UpdateSettings() {
Config::setRdocEnabled(ui->rdocCheckBox->isChecked());
Config::setAutoUpdate(ui->updateCheckBox->isChecked());
Config::setUpdateChannel(ui->updateComboBox->currentText().toStdString());
Config::setGammaValue(ui->GammaSlider->value());
#ifdef ENABLE_DISCORD_RPC
auto* rpc = Common::Singleton<DiscordRPCHandler::RPC>::Instance();

View File

@ -36,6 +36,8 @@ private:
void InitializeEmulatorLanguages();
void OnLanguageChanged(int index);
void OnCursorStateChanged(s16 index);
void GammaSliderChange(int value);
void ResetGamma();
std::unique_ptr<Ui::SettingsDialog> ui;

View File

@ -60,8 +60,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>832</width>
<height>431</height>
<width>815</width>
<height>623</height>
</rect>
</property>
<property name="sizePolicy">
@ -696,7 +696,7 @@
<property name="bottomMargin">
<number>5</number>
</property>
<item alignment="Qt::AlignmentFlag::AlignHCenter">
<item>
<widget class="QSpinBox" name="idleTimeoutSpinBox">
<property name="enabled">
<bool>true</bool>
@ -897,20 +897,34 @@
</widget>
</item>
<item>
<widget class="QWidget" name="widgetgraphicsBottom" native="true">
<layout class="QHBoxLayout" name="widgetgraphicsBottomHLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Gamma Correction</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<widget class="QSlider" name="GammaSlider">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>2000</number>
</property>
<property name="value">
<number>1000</number>
</property>
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="ResetGammaButton">
<property name="text">
<string>Reset Gamma</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -1,7 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/config.h"
#include "common/debug.h"
#include "common/singleton.h"
#include "core/debug_state.h"

View File

@ -5,6 +5,7 @@
#include <condition_variable>
#include "common/config.h"
#include "video_core/amdgpu/liverpool.h"
#include "video_core/renderer_vulkan/vk_instance.h"
#include "video_core/renderer_vulkan/vk_scheduler.h"
@ -42,7 +43,7 @@ class Rasterizer;
class Presenter {
struct PostProcessSettings {
float gamma = 1.0f;
float gamma = static_cast<float>((Config::getGammaValue() / 1000.0f));
};
public: