From f368e763106b12d3003d801fda266474816a3076 Mon Sep 17 00:00:00 2001 From: doodlum <15017472+doodlum@users.noreply.github.com> Date: Sun, 16 Feb 2025 15:01:57 +0000 Subject: [PATCH] feat(cloud shadows): add opacity slider (#963) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat!(cloud shadows): add opacity slider * style: 🎨 apply clang-format changes --------- Co-authored-by: doodlum --- .../Shaders/CloudShadows/CloudShadows.hlsli | 2 +- .../Shaders/Features/CloudShadows.ini | 2 +- package/Shaders/Common/ShadowSampling.hlsli | 5 +--- package/Shaders/Common/SharedData.hlsli | 7 +++++ src/FeatureBuffer.cpp | 4 ++- src/Features/CloudShadows.cpp | 28 +++++++++++++++++++ src/Features/CloudShadows.h | 15 ++++++++++ 7 files changed, 56 insertions(+), 7 deletions(-) diff --git a/features/Cloud Shadows/Shaders/CloudShadows/CloudShadows.hlsli b/features/Cloud Shadows/Shaders/CloudShadows/CloudShadows.hlsli index 59d6b7618..2a75b94c4 100644 --- a/features/Cloud Shadows/Shaders/CloudShadows/CloudShadows.hlsli +++ b/features/Cloud Shadows/Shaders/CloudShadows/CloudShadows.hlsli @@ -21,6 +21,6 @@ namespace CloudShadows { float3 cloudSampleDir = GetCloudShadowSampleDir(worldPosition, SharedData::DirLightDirection.xyz).xyz; float cloudCubeSample = CloudShadowsTexture.SampleLevel(textureSampler, cloudSampleDir, 0).x; - return 1.0 - saturate(cloudCubeSample); + return lerp(1.0, 1.0 - cloudCubeSample, SharedData::cloudShadowsSettings.Opacity); } } diff --git a/features/Cloud Shadows/Shaders/Features/CloudShadows.ini b/features/Cloud Shadows/Shaders/Features/CloudShadows.ini index de2206be5..7c4d5a2a3 100644 --- a/features/Cloud Shadows/Shaders/Features/CloudShadows.ini +++ b/features/Cloud Shadows/Shaders/Features/CloudShadows.ini @@ -1,2 +1,2 @@ [Info] -Version = 1-1-1 \ No newline at end of file +Version = 1-2-0 \ No newline at end of file diff --git a/package/Shaders/Common/ShadowSampling.hlsli b/package/Shaders/Common/ShadowSampling.hlsli index 049a48df6..10eff49f7 100644 --- a/package/Shaders/Common/ShadowSampling.hlsli +++ b/package/Shaders/Common/ShadowSampling.hlsli @@ -156,11 +156,8 @@ namespace ShadowSampling #endif #if defined(CLOUD_SHADOWS) - if (!SharedData::InMapMenu) { + if (!SharedData::InMapMenu) worldShadow *= CloudShadows::GetCloudShadowMult(positionWS, LinearSampler); - if (worldShadow == 0.0) - return worldShadow; - } #endif return worldShadow; diff --git a/package/Shaders/Common/SharedData.hlsli b/package/Shaders/Common/SharedData.hlsli index f342bf054..20a1080e5 100644 --- a/package/Shaders/Common/SharedData.hlsli +++ b/package/Shaders/Common/SharedData.hlsli @@ -130,6 +130,12 @@ namespace SharedData uint2 pad0; }; + struct CloudShadowsSettings + { + float Opacity; + float3 pad0; + }; + cbuffer FeatureData : register(b6) { GrassLightingSettings grassLightingSettings; @@ -139,6 +145,7 @@ namespace SharedData LightLimitFixSettings lightLimitFixSettings; WetnessEffectsSettings wetnessEffectsSettings; SkylightingSettings skylightingSettings; + CloudShadowsSettings cloudShadowsSettings; }; Texture2D DepthTexture : register(t17); diff --git a/src/FeatureBuffer.cpp b/src/FeatureBuffer.cpp index c4d439d09..913d67b75 100644 --- a/src/FeatureBuffer.cpp +++ b/src/FeatureBuffer.cpp @@ -1,5 +1,6 @@ #include "FeatureBuffer.h" +#include "Features/CloudShadows.h" #include "Features/DynamicCubemaps.h" #include "Features/ExtendedMaterials.h" #include "Features/GrassLighting.h" @@ -35,5 +36,6 @@ std::pair GetFeatureBufferData(bool a_inWorld) globals::features::terrainShadows->GetCommonBufferData(), globals::features::lightLimitFix->GetCommonBufferData(), globals::features::wetnessEffects->GetCommonBufferData(), - globals::features::skylighting->GetCommonBufferData(a_inWorld)); + globals::features::skylighting->GetCommonBufferData(a_inWorld), + globals::features::cloudShadows->settings); } \ No newline at end of file diff --git a/src/Features/CloudShadows.cpp b/src/Features/CloudShadows.cpp index c168c2ba8..77bbf3c9c 100644 --- a/src/Features/CloudShadows.cpp +++ b/src/Features/CloudShadows.cpp @@ -1,5 +1,33 @@ #include "CloudShadows.h" +NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT( + CloudShadows::Settings, + Opacity) + +void CloudShadows::DrawSettings() +{ + ImGui::SliderFloat("Opacity", &settings.Opacity, 0.0f, 1.0f, "%.1f"); + if (auto _tt = Util::HoverTooltipWrapper()) { + ImGui::Text( + "Higher values make cloud shadows darker."); + } +} + +void CloudShadows::LoadSettings(json& o_json) +{ + settings = o_json; +} + +void CloudShadows::SaveSettings(json& o_json) +{ + o_json = settings; +} + +void CloudShadows::RestoreDefaultSettings() +{ + settings = {}; +} + void CloudShadows::CheckResourcesSide(int side) { static Util::FrameChecker frame_checker[6]; diff --git a/src/Features/CloudShadows.h b/src/Features/CloudShadows.h index 9656d04fa..bda3d5f5f 100644 --- a/src/Features/CloudShadows.h +++ b/src/Features/CloudShadows.h @@ -8,6 +8,14 @@ struct CloudShadows : Feature return &singleton; } + struct alignas(16) Settings + { + float Opacity = 0.8f; + float pad[3]; + }; + + Settings settings; + virtual inline std::string GetName() override { return "Cloud Shadows"; } virtual inline std::string GetShortName() override { return "CloudShadows"; } virtual inline std::string_view GetShaderDefineName() override { return "CLOUD_SHADOWS"; } @@ -26,6 +34,13 @@ struct CloudShadows : Feature virtual void SetupResources() override; + virtual void DrawSettings() override; + + virtual void LoadSettings(json& o_json) override; + virtual void SaveSettings(json& o_json) override; + + virtual void RestoreDefaultSettings() override; + void CheckResourcesSide(int side); void ModifySky(RE::BSRenderPass* Pass);