From 4afdbf56c451f2f295df68555f75e52ddaa3a5ca Mon Sep 17 00:00:00 2001 From: Tim <15017472+doodlum@users.noreply.github.com> Date: Thu, 15 Jun 2023 21:17:28 +0100 Subject: [PATCH 1/4] Disabled screen-space shadows in interiors --- src/Features/ScreenSpaceShadows.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Features/ScreenSpaceShadows.cpp b/src/Features/ScreenSpaceShadows.cpp index 83ad54aec..032e8688f 100644 --- a/src/Features/ScreenSpaceShadows.cpp +++ b/src/Features/ScreenSpaceShadows.cpp @@ -152,8 +152,13 @@ void ScreenSpaceShadows::ModifyLighting(const RE::BSShader*, const uint32_t) auto context = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; auto accumulator = RE::BSGraphics::BSShaderAccumulator::GetCurrentAccumulator(); - auto sunLight = skyrim_cast(accumulator->GetRuntimeData().activeShadowSceneNode->GetRuntimeData().sunLight->light.get()); - if (sunLight) { + auto dirLight = skyrim_cast(accumulator->GetRuntimeData().activeShadowSceneNode->GetRuntimeData().sunLight->light.get()); + + bool skyLight = true; + if (auto sky = RE::Sky::GetSingleton()) + skyLight = sky->mode.get() == RE::Sky::Mode::kFull; + + if (dirLight && skyLight) { auto renderer = RE::BSGraphics::Renderer::GetSingleton(); if (!screenSpaceShadowsTexture) { @@ -257,7 +262,7 @@ void ScreenSpaceShadows::ModifyLighting(const RE::BSShader*, const uint32_t) data.DynamicRes.z = 1.0f / data.DynamicRes.x; data.DynamicRes.w = 1.0f / data.DynamicRes.y; - auto& direction = sunLight->GetWorldDirection(); + auto& direction = dirLight->GetWorldDirection(); DirectX::XMFLOAT3 position{}; position.x = -direction.x; position.y = -direction.y; From 47bd0ffd58518c1d3bd1404662bd21f3fe417260 Mon Sep 17 00:00:00 2001 From: Tim <15017472+doodlum@users.noreply.github.com> Date: Thu, 15 Jun 2023 21:18:23 +0100 Subject: [PATCH 2/4] Version bump --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e5187fd0..8bda1512c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.21) project( CommunityShaders - VERSION 0.3.2 + VERSION 0.3.3 LANGUAGES CXX ) From c901d367d759eee6821f88494bb3d0b01bbdd908 Mon Sep 17 00:00:00 2001 From: Pentalimbed Date: Sun, 25 Jun 2023 16:43:37 +0800 Subject: [PATCH 3/4] simplify json io with nlohmann json macro --- src/Features/DistantTreeLighting.cpp | 39 +++++++------------- src/Features/GrassCollision.cpp | 29 +++++++-------- src/Features/GrassLighting.cpp | 32 ++++++----------- src/Features/ScreenSpaceShadows.cpp | 54 +++++++++------------------- 4 files changed, 53 insertions(+), 101 deletions(-) diff --git a/src/Features/DistantTreeLighting.cpp b/src/Features/DistantTreeLighting.cpp index d51fc1a53..7d2cef8d3 100644 --- a/src/Features/DistantTreeLighting.cpp +++ b/src/Features/DistantTreeLighting.cpp @@ -3,10 +3,16 @@ #include "State.h" #include "Util.h" +NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT( + DistantTreeLighting::Settings, + EnableComplexTreeLOD, + EnableDirLightFix, + SubsurfaceScatteringAmount, + FogDimmerAmount) + void DistantTreeLighting::DrawSettings() { if (ImGui::BeginTabItem("Tree LOD Lighting")) { - if (ImGui::TreeNodeEx("Complex Tree LOD", ImGuiTreeNodeFlags_DefaultOpen)) { ImGui::Text("Enables advanced lighting simulation on tree LOD."); ImGui::Text("Requires DynDOLOD."); @@ -37,7 +43,6 @@ void DistantTreeLighting::DrawSettings() ImGui::SliderFloat("Fog Dimmer Amount", &settings.FogDimmerAmount, 0.0f, 1.0f); ImGui::TreePop(); - } ImGui::EndTabItem(); @@ -52,12 +57,9 @@ enum class DistantTreeShaderTechniques void DistantTreeLighting::ModifyDistantTree(const RE::BSShader*, const uint32_t descriptor) { - if (auto player = RE::PlayerCharacter::GetSingleton()) - { - if (auto worldSpace = player->GetWorldspace()) - { - if (lastWorldSpace != worldSpace) - { + if (auto player = RE::PlayerCharacter::GetSingleton()) { + if (auto worldSpace = player->GetWorldspace()) { + if (lastWorldSpace != worldSpace) { lastWorldSpace = worldSpace; if (auto name = worldSpace->GetFormEditorID()) { CSimpleIniA ini; @@ -74,7 +76,6 @@ void DistantTreeLighting::ModifyDistantTree(const RE::BSShader*, const uint32_t const auto technique = descriptor & 1; if (technique != static_cast(DistantTreeShaderTechniques::Depth)) { - PerPass perPassData{}; ZeroMemory(&perPassData, sizeof(perPassData)); @@ -147,17 +148,8 @@ void DistantTreeLighting::Draw(const RE::BSShader* shader, const uint32_t descri void DistantTreeLighting::Load(json& o_json) { - if (o_json["Tree LOD Lighting"].is_object()) { - json& distantTreeLighting = o_json["Distant Tree Lighting"]; - if (distantTreeLighting["EnableComplexTreeLOD"].is_boolean()) - settings.EnableComplexTreeLOD = distantTreeLighting["EnableComplexTreeLOD"]; - if (distantTreeLighting["EnableDirLightFix"].is_boolean()) - settings.EnableDirLightFix = distantTreeLighting["EnableDirLightFix"]; - if (distantTreeLighting["SubsurfaceScatteringAmount"].is_number()) - settings.SubsurfaceScatteringAmount = distantTreeLighting["SubsurfaceScatteringAmount"]; - if (distantTreeLighting["FogDimmerAmount"].is_number()) - settings.FogDimmerAmount = distantTreeLighting["FogDimmerAmount"]; - } + settings = o_json["Distant Tree Lighting"]; + CSimpleIniA ini; ini.SetUnicode(); ini.LoadFile(L"Data\\Shaders\\Features\\TreeLODLighting.ini"); @@ -173,12 +165,7 @@ void DistantTreeLighting::Load(json& o_json) void DistantTreeLighting::Save(json& o_json) { - json distantTreeLighting; - distantTreeLighting["EnableComplexTreeLOD"] = (bool)settings.EnableComplexTreeLOD; - distantTreeLighting["EnableDirLightFix"] = (bool)settings.EnableDirLightFix; - distantTreeLighting["SubsurfaceScatteringAmount"] = settings.SubsurfaceScatteringAmount; - distantTreeLighting["FogDimmerAmount"] = settings.FogDimmerAmount; - o_json["Tree LOD Lighting"] = distantTreeLighting; + o_json["Tree LOD Lighting"] = settings; } void DistantTreeLighting::SetupResources() diff --git a/src/Features/GrassCollision.cpp b/src/Features/GrassCollision.cpp index 69e980414..9a94eb496 100644 --- a/src/Features/GrassCollision.cpp +++ b/src/Features/GrassCollision.cpp @@ -5,6 +5,12 @@ #include "Features/Clustered.h" +NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT( + GrassCollision::Settings, + EnableGrassCollision, + RadiusMultiplier, + DisplacementMultiplier) + enum class GrassShaderTechniques { RenderDepth = 8, @@ -15,14 +21,14 @@ void GrassCollision::DrawSettings() if (ImGui::BeginTabItem("Grass Collision")) { if (ImGui::TreeNodeEx("Grass Collision", ImGuiTreeNodeFlags_DefaultOpen)) { ImGui::Text("Allows player collision to modify grass position."); - + ImGui::Checkbox("Enable Grass Collision", (bool*)&settings.EnableGrassCollision); ImGui::Text("Distance from collision centres to apply collision"); ImGui::SliderFloat("Radius Multiplier", &settings.RadiusMultiplier, 0.0f, 8.0f); - + ImGui::Text("Strength of each collision on grass position."); ImGui::SliderFloat("Displacement Multiplier", &settings.DisplacementMultiplier, 0.0f, 32.0f); - + ImGui::TreePop(); } @@ -242,15 +248,8 @@ void GrassCollision::Draw(const RE::BSShader* shader, const uint32_t descriptor) void GrassCollision::Load(json& o_json) { - if (o_json["Grass Collision"].is_object()) { - json& grassCollision = o_json["Grass Collision"]; - if (grassCollision["EnableGrassCollision"].is_boolean()) - settings.EnableGrassCollision = grassCollision["EnableGrassCollision"]; - if (grassCollision["RadiusMultiplier"].is_number()) - settings.RadiusMultiplier = grassCollision["RadiusMultiplier"]; - if (grassCollision["DisplacementMultiplier"].is_number()) - settings.DisplacementMultiplier = grassCollision["DisplacementMultiplier"]; - } + settings = o_json["Grass Collision"]; + CSimpleIniA ini; ini.SetUnicode(); ini.LoadFile(L"Data\\Shaders\\Features\\GrassCollision.ini"); @@ -266,11 +265,7 @@ void GrassCollision::Load(json& o_json) void GrassCollision::Save(json& o_json) { - json grassCollision; - grassCollision["EnableGrassCollision"] = (bool)settings.EnableGrassCollision; - grassCollision["RadiusMultiplier"] = settings.RadiusMultiplier; - grassCollision["DisplacementMultiplier"] = settings.DisplacementMultiplier; - o_json["Grass Collision"] = grassCollision; + o_json["Grass Collision"] = settings; } void GrassCollision::SetupResources() diff --git a/src/Features/GrassLighting.cpp b/src/Features/GrassLighting.cpp index bb6d28c91..83e129dac 100644 --- a/src/Features/GrassLighting.cpp +++ b/src/Features/GrassLighting.cpp @@ -5,6 +5,14 @@ #include "Features/Clustered.h" +NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT( + GrassLighting::Settings, + Glossiness, + SpecularStrength, + SubsurfaceScatteringAmount, + EnableDirLightFix, + EnablePointLights) + enum class GrassShaderTechniques { RenderDepth = 8, @@ -104,19 +112,8 @@ void GrassLighting::Draw(const RE::BSShader* shader, const uint32_t descriptor) void GrassLighting::Load(json& o_json) { - if (o_json["Grass Lighting"].is_object()) { - json& grassLighting = o_json["Grass Lighting"]; - if (grassLighting["Glossiness"].is_number()) - settings.Glossiness = grassLighting["Glossiness"]; - if (grassLighting["SpecularStrength"].is_number()) - settings.SpecularStrength = grassLighting["SpecularStrength"]; - if (grassLighting["SubsurfaceScatteringAmount"].is_number()) - settings.SubsurfaceScatteringAmount = grassLighting["SubsurfaceScatteringAmount"]; - if (grassLighting["EnableDirLightFix"].is_boolean()) - settings.EnableDirLightFix = grassLighting["EnableDirLightFix"]; - if (grassLighting["EnablePointLights"].is_boolean()) - settings.EnablePointLights = grassLighting["EnablePointLights"]; - } + settings = o_json["Grass Lighting"]; + CSimpleIniA ini; ini.SetUnicode(); ini.LoadFile(L"Data\\Shaders\\Features\\GrassLighting.ini"); @@ -132,16 +129,9 @@ void GrassLighting::Load(json& o_json) void GrassLighting::Save(json& o_json) { - json grassLighting; - grassLighting["Glossiness"] = settings.Glossiness; - grassLighting["SpecularStrength"] = settings.SpecularStrength; - grassLighting["SubsurfaceScatteringAmount"] = settings.SubsurfaceScatteringAmount; - grassLighting["EnableDirLightFix"] = (bool)settings.EnableDirLightFix; - grassLighting["EnablePointLights"] = (bool)settings.EnablePointLights; - o_json["Grass Lighting"] = grassLighting; + o_json["Grass Lighting"] = settings; } - void GrassLighting::SetupResources() { perFrame = new ConstantBuffer(ConstantBufferDesc()); diff --git a/src/Features/ScreenSpaceShadows.cpp b/src/Features/ScreenSpaceShadows.cpp index 032e8688f..06bbee667 100644 --- a/src/Features/ScreenSpaceShadows.cpp +++ b/src/Features/ScreenSpaceShadows.cpp @@ -5,6 +5,18 @@ using RE::RENDER_TARGETS; +NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT( + ScreenSpaceShadows::Settings, + MaxSamples, + FarDistanceScale, + FarThicknessScale, + FarHardness, + NearDistance, + NearThickness, + NearHardness, + BlurRadius, + BlurDropoff) + void ScreenSpaceShadows::DrawSettings() { if (ImGui::BeginTabItem("Screen-Space Shadows")) { @@ -153,9 +165,9 @@ void ScreenSpaceShadows::ModifyLighting(const RE::BSShader*, const uint32_t) auto accumulator = RE::BSGraphics::BSShaderAccumulator::GetCurrentAccumulator(); auto dirLight = skyrim_cast(accumulator->GetRuntimeData().activeShadowSceneNode->GetRuntimeData().sunLight->light.get()); - + bool skyLight = true; - if (auto sky = RE::Sky::GetSingleton()) + if (auto sky = RE::Sky::GetSingleton()) skyLight = sky->mode.get() == RE::Sky::Mode::kFull; if (dirLight && skyLight) { @@ -403,29 +415,8 @@ void ScreenSpaceShadows::Draw(const RE::BSShader* shader, const uint32_t descrip void ScreenSpaceShadows::Load(json& o_json) { - if (o_json["Screen-Space Shadows"].is_object()) { - json& ssShadows = o_json["Screen-Space Shadows"]; - if (ssShadows["EnableScreenSpaceShadows"].is_boolean()) - enabled = ssShadows["EnableScreenSpaceShadows"]; - if (ssShadows["MaxSamples"].is_number()) - settings.MaxSamples = ssShadows["MaxSamples"]; - if (ssShadows["FarDistanceScale"].is_number()) - settings.FarDistanceScale = ssShadows["FarDistanceScale"]; - if (ssShadows["FarThicknessScale"].is_number()) - settings.FarThicknessScale = ssShadows["FarThicknessScale"]; - if (ssShadows["FarHardness"].is_number()) - settings.FarHardness = ssShadows["FarHardness"]; - if (ssShadows["NearDistance"].is_number()) - settings.NearDistance = ssShadows["NearDistance"]; - if (ssShadows["NearThickness"].is_number()) - settings.NearThickness = ssShadows["NearThickness"]; - if (ssShadows["NearHardness"].is_number()) - settings.NearHardness = ssShadows["NearHardness"]; - if (ssShadows["BlurRadius"].is_number()) - settings.BlurRadius = ssShadows["BlurRadius"]; - if (ssShadows["BlurDropoff"].is_number()) - settings.BlurDropoff = ssShadows["BlurDropoff"]; - } + settings = o_json["Screen-Space Shadows"]; + CSimpleIniA ini; ini.SetUnicode(); ini.LoadFile(L"Data\\Shaders\\Features\\ScreenSpaceShadows.ini"); @@ -441,18 +432,7 @@ void ScreenSpaceShadows::Load(json& o_json) void ScreenSpaceShadows::Save(json& o_json) { - json ssShadows; - ssShadows["EnableScreenSpaceShadows"] = enabled; - ssShadows["MaxSamples"] = settings.MaxSamples; - ssShadows["FarDistanceScale"] = settings.FarDistanceScale; - ssShadows["FarThicknessScale"] = settings.FarThicknessScale; - ssShadows["FarHardness"] = settings.FarHardness; - ssShadows["NearDistance"] = settings.NearDistance; - ssShadows["NearThickness"] = settings.NearThickness; - ssShadows["NearHardness"] = settings.NearHardness; - ssShadows["BlurRadius"] = settings.BlurRadius; - ssShadows["BlurDropoff"] = settings.BlurDropoff; - o_json["Screen-Space Shadows"] = ssShadows; + o_json["Screen-Space Shadows"] = settings; } void ScreenSpaceShadows::SetupResources() From 84bd218644159707609081020fd4db1a31ae23d0 Mon Sep 17 00:00:00 2001 From: Tim <15017472+doodlum@users.noreply.github.com> Date: Sun, 25 Jun 2023 12:41:15 +0100 Subject: [PATCH 4/4] Fixed crashes on missing settings --- src/Features/DistantTreeLighting.cpp | 3 ++- src/Features/GrassCollision.cpp | 3 ++- src/Features/GrassLighting.cpp | 3 ++- src/Features/ScreenSpaceShadows.cpp | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Features/DistantTreeLighting.cpp b/src/Features/DistantTreeLighting.cpp index 7d2cef8d3..39dada370 100644 --- a/src/Features/DistantTreeLighting.cpp +++ b/src/Features/DistantTreeLighting.cpp @@ -148,8 +148,9 @@ void DistantTreeLighting::Draw(const RE::BSShader* shader, const uint32_t descri void DistantTreeLighting::Load(json& o_json) { + if (o_json["Distant Tree Lighting"].is_object()) settings = o_json["Distant Tree Lighting"]; - + CSimpleIniA ini; ini.SetUnicode(); ini.LoadFile(L"Data\\Shaders\\Features\\TreeLODLighting.ini"); diff --git a/src/Features/GrassCollision.cpp b/src/Features/GrassCollision.cpp index 9a94eb496..1807f532a 100644 --- a/src/Features/GrassCollision.cpp +++ b/src/Features/GrassCollision.cpp @@ -248,7 +248,8 @@ void GrassCollision::Draw(const RE::BSShader* shader, const uint32_t descriptor) void GrassCollision::Load(json& o_json) { - settings = o_json["Grass Collision"]; + if (o_json["Grass Collision"].is_object()) + settings = o_json["Grass Collision"]; CSimpleIniA ini; ini.SetUnicode(); diff --git a/src/Features/GrassLighting.cpp b/src/Features/GrassLighting.cpp index 83e129dac..b1cf3b645 100644 --- a/src/Features/GrassLighting.cpp +++ b/src/Features/GrassLighting.cpp @@ -112,7 +112,8 @@ void GrassLighting::Draw(const RE::BSShader* shader, const uint32_t descriptor) void GrassLighting::Load(json& o_json) { - settings = o_json["Grass Lighting"]; + if (o_json["Grass Lighting"].is_object()) + settings = o_json["Grass Lighting"]; CSimpleIniA ini; ini.SetUnicode(); diff --git a/src/Features/ScreenSpaceShadows.cpp b/src/Features/ScreenSpaceShadows.cpp index 06bbee667..cad33a89d 100644 --- a/src/Features/ScreenSpaceShadows.cpp +++ b/src/Features/ScreenSpaceShadows.cpp @@ -415,7 +415,8 @@ void ScreenSpaceShadows::Draw(const RE::BSShader* shader, const uint32_t descrip void ScreenSpaceShadows::Load(json& o_json) { - settings = o_json["Screen-Space Shadows"]; + if (o_json["Screen-Space Shadows"].is_object()) + settings = o_json["Screen-Space Shadows"]; CSimpleIniA ini; ini.SetUnicode();