Skip to content

Commit

Permalink
feat: enable settings for SSR
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse committed Sep 16, 2024
1 parent d692956 commit 8bbc827
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 7 deletions.
10 changes: 7 additions & 3 deletions package/Shaders/ISReflectionsRayTracing.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ PS_OUTPUT main(PS_INPUT input)
PS_OUTPUT psout;
psout.Color = 0;

# ifndef ENABLESSR
// Disable SSR raymarch
return psout;
# endif
# ifdef VR
uint eyeIndex = input.TexCoord.x >= 0.5;
# else
Expand Down Expand Up @@ -135,10 +139,10 @@ PS_OUTPUT main(PS_INPUT input)
bool fromOtherEye = false;
# endif
const int maxIterations =
# ifndef VR
16
# ifdef MAX_ITERATIONS
MAX_ITERATIONS
# else
48
16
# endif
; // Adjust based on performance/quality tradeoff

Expand Down
79 changes: 77 additions & 2 deletions src/Features/DynamicCubemaps.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "DynamicCubemaps.h"
#include "ShaderCache.h"

#include "State.h"
#include "Util.h"
Expand All @@ -8,14 +9,50 @@

constexpr auto MIPLEVELS = 8;

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
DynamicCubemaps::Settings,
EnabledSSR,
EnabledCreator,
MaxIterations);

std::vector<std::pair<std::string_view, std::string_view>> DynamicCubemaps::GetShaderDefineOptions()
{
std::vector<std::pair<std::string_view, std::string_view>> result;
maxIterationsString = std::to_string(settings.MaxIterations);
if (settings.EnabledSSR) {
result.push_back({ "ENABLESSR", "" });
}

result.push_back({ "MAX_ITERATIONS", maxIterationsString });

return result;
}

void DynamicCubemaps::DrawSettings()
{
if (ImGui::TreeNodeEx("Settings", ImGuiTreeNodeFlags_DefaultOpen)) {
if (ImGui::TreeNodeEx("Screen Space Reflections", ImGuiTreeNodeFlags_DefaultOpen)) {
recompileFlag |= ImGui::Checkbox("Enable Screen Space Reflections", reinterpret_cast<bool*>(&settings.EnabledSSR));
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text("Enable Screen Space Reflections on Water");
}
if (settings.EnabledSSR) {
recompileFlag |= ImGui::SliderInt("Max Iterations", reinterpret_cast<int*>(&settings.MaxIterations), 1, 128);
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text(
"The maximum iterations to ray march. "
"Higher values result in better quality but lower performance.");
}
RenderImGuiSettingsTree(SSRSettings, "Skyrim SSR");
ImGui::TreePop();
}
ImGui::TreePop();
}

if (ImGui::TreeNodeEx("Dynamic Cubemap Creator", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::Text("You must enable creator mode by adding the shader define CREATOR");
ImGui::Checkbox("Enable Creator", reinterpret_cast<bool*>(&settings.Enabled));
if (settings.Enabled) {
ImGui::Checkbox("Enable Creator", reinterpret_cast<bool*>(&settings.EnabledCreator));
if (settings.EnabledCreator) {
ImGui::ColorEdit3("Color", reinterpret_cast<float*>(&settings.CubemapColor));
ImGui::SliderFloat("Roughness", &settings.CubemapColor.w, 0.0f, 1.0f, "%.2f");
if (ImGui::Button("Export")) {
Expand Down Expand Up @@ -106,6 +143,37 @@ void DynamicCubemaps::DrawSettings()
}
}

void DynamicCubemaps::LoadSettings(json& o_json)
{
settings = o_json;
LoadGameSettings(SSRSettings);
if (REL::Module::IsVR()) {
LoadGameSettings(iniVRCubeMapSettings);
}
recompileFlag = true;

}

void DynamicCubemaps::SaveSettings(json& o_json)
{
o_json = settings;
SaveGameSettings(SSRSettings);
if (REL::Module::IsVR()) {
SaveGameSettings(iniVRCubeMapSettings);
}
}

void DynamicCubemaps::RestoreDefaultSettings()
{
settings = {};
ResetGameSettingsToDefaults(SSRSettings);
if (REL::Module::IsVR()) {
ResetGameSettingsToDefaults(iniVRCubeMapSettings);
ResetGameSettingsToDefaults(hiddenVRCubeMapSettings);
}
recompileFlag = true;
}

void DynamicCubemaps::DataLoaded()
{
if (REL::Module::IsVR()) {
Expand Down Expand Up @@ -368,6 +436,13 @@ void DynamicCubemaps::Irradiance(bool a_reflections)
void DynamicCubemaps::UpdateCubemap()
{
TracyD3D11Zone(State::GetSingleton()->tracyCtx, "Cubemap Update");
if (recompileFlag) {
auto& shaderCache = SIE::ShaderCache::Instance();
if (!shaderCache.Clear("Data//Shaders//ISReflectionsRayTracing.hlsl"))
// if can't find specific hlsl file cache, clear all image space files
shaderCache.Clear(RE::BSShader::Types::ImageSpace);
recompileFlag = false;
}

switch (nextTask) {
case NextTask::kInferrence:
Expand Down
20 changes: 18 additions & 2 deletions src/Features/DynamicCubemaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ struct DynamicCubemaps : Feature

bool activeReflections = false;
bool resetCapture = true;
bool recompileFlag = false;

enum class NextTask
{
Expand All @@ -77,12 +78,15 @@ struct DynamicCubemaps : Feature

struct Settings
{
uint Enabled = false;
uint pad0[3]{};
uint EnabledCreator = false;
uint EnabledSSR = true;
uint MaxIterations = static_cast<uint>(REL::Relocate(16, 16, 48));
uint pad0{};
float4 CubemapColor{ 1.0f, 1.0f, 1.0f, 0.0f };
};

Settings settings;
std::string maxIterationsString = ""; // required to avoid string going out of scope for defines

void UpdateCubemap();

Expand All @@ -91,15 +95,27 @@ struct DynamicCubemaps : Feature
virtual inline std::string GetName() override { return "Dynamic Cubemaps"; }
virtual inline std::string GetShortName() override { return "DynamicCubemaps"; }
virtual inline std::string_view GetShaderDefineName() override { return "DYNAMIC_CUBEMAPS"; }
virtual inline std::vector<std::pair<std::string_view, std::string_view>> GetShaderDefineOptions() override;

bool HasShaderDefine(RE::BSShader::Type) override { return true; };

virtual void SetupResources() override;
virtual void Reset() override;

virtual void SaveSettings(json&) override;
virtual void LoadSettings(json&) override;
virtual void RestoreDefaultSettings() override;
virtual void DrawSettings() override;
virtual void DataLoaded() override;
virtual void PostPostLoad() override;

std::map<std::string, gameSetting> SSRSettings{
{ "fWaterSSRNormalPerturbationScale:Display", { "Water Normal Perturbation Scale", "Controls the scale of normal perturbations for Screen Space Reflections (SSR) on water surfaces.", 0, 0.05f, 0.f, 1.f } },
{ "fWaterSSRBlurAmount:Display", { "Water SSR Blur Amount", "Defines the amount of blur applied to Screen Space Reflections on water surfaces.", 0, 0.3f, 0.f, 1.f } },
{ "fWaterSSRIntensity:Display", { "Water SSR Intensity", "Adjusts the intensity or strength of Screen Space Reflections on water.", 0, 1.3f, 0.f, 5.f } },
{ "bDownSampleNormalSSR:Display", { "Down Sample Normal SSR", "Enables or disables downsampling of normals for SSR to improve performance.", 0, true, false, true } }
};

std::map<std::string, gameSetting> iniVRCubeMapSettings{
{ "bAutoWaterSilhouetteReflections:Water", { "Auto Water Silhouette Reflections", "Automatically reflects silhouettes on water surfaces.", 0, true, false, true } },
{ "bForceHighDetailReflections:Water", { "Force High Detail Reflections", "Forces the use of high-detail reflections on water surfaces.", 0, true, false, true } }
Expand Down
2 changes: 2 additions & 0 deletions src/ShaderCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,8 @@ namespace SIE
std::string::size_type pos = a_key.find(':');
if (pos != std::string::npos)
type = a_key.substr(0, pos);
if (type.starts_with("IS") || type == "ReflectionsRayTracing")
type = "ImageSpace"; // fix type for image space shaders
return type;
}

Expand Down

0 comments on commit 8bbc827

Please sign in to comment.