diff --git a/features/IBL/Shaders/IBL/DiffuseIBLCS.hlsl b/features/IBL/Shaders/IBL/DiffuseIBLCS.hlsl index 1bde95b017..5dd2346572 100644 --- a/features/IBL/Shaders/IBL/DiffuseIBLCS.hlsl +++ b/features/IBL/Shaders/IBL/DiffuseIBLCS.hlsl @@ -36,7 +36,7 @@ void main(uint3 dispatchID : SV_DispatchThreadID, uint groupIndex : SV_GroupInde // ENB compat rayDir.z = -abs(rayDir.z); - + // Sample cubemap with optimized direction float3 color = EnvTexture.SampleLevel(LinearSampler, -rayDir, 0).xyz; @@ -72,4 +72,4 @@ void main(uint3 dispatchID : SV_DispatchThreadID, uint groupIndex : SV_GroupInde IBLTexture[int2(1, 0)] = sharedG[0]; IBLTexture[int2(2, 0)] = sharedB[0]; } -} \ No newline at end of file +} diff --git a/package/Shaders/Common/SharedData.hlsli b/package/Shaders/Common/SharedData.hlsli index cf8a790c82..f3c69c4470 100644 --- a/package/Shaders/Common/SharedData.hlsli +++ b/package/Shaders/Common/SharedData.hlsli @@ -202,7 +202,7 @@ namespace SharedData { bool Enable; float3 pad; - + float GradientIntensity; float GradientDesaturation; float GradientTopIntensity; @@ -229,7 +229,7 @@ namespace SharedData float CloudsCurve; float CloudsDesaturation; float CloudsOpacity; - + float3 CloudsColorFilter; float CloudsVertexAlphaBoost; diff --git a/package/Shaders/DeferredCompositeCS.hlsl b/package/Shaders/DeferredCompositeCS.hlsl index a476539751..66aaead0e5 100644 --- a/package/Shaders/DeferredCompositeCS.hlsl +++ b/package/Shaders/DeferredCompositeCS.hlsl @@ -119,23 +119,24 @@ void SampleSSGISpecular(uint2 pixCoord, sh2 lobe, out float ao, out float3 il, i # endif sh2 skylighting = Skylighting::sample(SharedData::skylightingSettings, SkylightingProbeArray, stbn_vec3_2Dx1D_128x128x64, dispatchID.xy, positionMS.xyz, normalWS); - + float3 V = normalize(positionWS.xyz); float3 R = reflect(V, normalWS); #if defined(SSGI) + if (depth < 1.0f) { float ssgiAo; float3 ssgiIl; SampleSSGI(dispatchID.xy, normalWS, ssgiAo, ssgiIl); float3 directionalAmbientColor = max(0, mul(SharedData::DirectionalAmbient, float4(normalWS, 1.0))); - - if (SharedData::enbSettings.Enable){ + + if (SharedData::enbSettings.Enable){ sh2 shR = ImageBasedLighting::DiffuseSkyIBLTexture.Load(int3(0, 0, 0)); sh2 shG = ImageBasedLighting::DiffuseSkyIBLTexture.Load(int3(1, 0, 0)); sh2 shB = ImageBasedLighting::DiffuseSkyIBLTexture.Load(int3(2, 0, 0)); - + float colorR = SphericalHarmonics::SHHallucinateZH3Irradiance(shR, -normalWS); float colorG = SphericalHarmonics::SHHallucinateZH3Irradiance(shG, -normalWS); float colorB = SphericalHarmonics::SHHallucinateZH3Irradiance(shB, -normalWS); diff --git a/package/Shaders/DistantTree.hlsl b/package/Shaders/DistantTree.hlsl index 5a7e7fb8e3..281b12c745 100644 --- a/package/Shaders/DistantTree.hlsl +++ b/package/Shaders/DistantTree.hlsl @@ -242,7 +242,7 @@ PS_OUTPUT main(PS_INPUT input) float3 directionalAmbientColor = max(0, mul(SharedData::DirectionalAmbient, float4(normal, 1.0))); # if defined(IBL) if (SharedData::iblSettings.EnableDiffuseIBL) { - directionalAmbientColor += ImageBasedLighting::GetIBLColor(-normal) * SharedData::enbSettings.IBLMultiplicativeAmount; + directionalAmbientColor += ImageBasedLighting::GetIBLColor(-normal) * SharedData::enbSettings.IBLMultiplicativeAmount; } # endif diffuseColor += directionalAmbientColor; @@ -269,7 +269,7 @@ PS_OUTPUT main(PS_INPUT input) float3 directionalAmbientColor = mul(SharedData::DirectionalAmbient, float4(normal, 1.0)); # if defined(IBL) if (SharedData::iblSettings.EnableDiffuseIBL) { - directionalAmbientColor += ImageBasedLighting::GetIBLColor(-normal) * SharedData::enbSettings.IBLMultiplicativeAmount; + directionalAmbientColor += ImageBasedLighting::GetIBLColor(-normal) * SharedData::enbSettings.IBLMultiplicativeAmount; } # endif diffuseColor += directionalAmbientColor; diff --git a/package/Shaders/Lighting.hlsl b/package/Shaders/Lighting.hlsl index 3ef80619cf..bce38e15ed 100644 --- a/package/Shaders/Lighting.hlsl +++ b/package/Shaders/Lighting.hlsl @@ -2744,7 +2744,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) # if defined(IBL) if (SharedData::iblSettings.EnableDiffuseIBL && inWorld) { float3 iblColor = ImageBasedLighting::GetIBLColor(-ambientNormal); - directionalAmbientColor += iblColor * SharedData::enbSettings.IBLMultiplicativeAmount; + directionalAmbientColor += iblColor * SharedData::enbSettings.IBLMultiplicativeAmount; directionalAmbientColorAdditive += iblColor * SharedData::enbSettings.IBLAdditiveAmount; } # endif diff --git a/package/Shaders/RunGrass.hlsl b/package/Shaders/RunGrass.hlsl index 5f83d9ea70..4288ef194c 100644 --- a/package/Shaders/RunGrass.hlsl +++ b/package/Shaders/RunGrass.hlsl @@ -747,10 +747,10 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) # endif // SKYLIGHTING # if defined(IBL) - if (SharedData::iblSettings.EnableDiffuseIBL) { + if (SharedData::iblSettings.EnableDiffuseIBL) { float3 iblColor = ImageBasedLighting::GetIBLColor(-normal); - directionalAmbientColor += iblColor * SharedData::enbSettings.IBLMultiplicativeAmount; - directionalAmbientColorAdditive += iblColor * SharedData::enbSettings.IBLAdditiveAmount; + directionalAmbientColor += iblColor * SharedData::enbSettings.IBLMultiplicativeAmount; + directionalAmbientColorAdditive += iblColor * SharedData::enbSettings.IBLAdditiveAmount; } # endif @@ -938,8 +938,8 @@ PS_OUTPUT main(PS_INPUT input) # if defined(IBL) if (SharedData::iblSettings.EnableDiffuseIBL) { float3 iblColor = ImageBasedLighting::GetIBLColor(-normal); - directionalAmbientColor += iblColor * SharedData::enbSettings.IBLMultiplicativeAmount; - directionalAmbientColorAdditive += iblColor * SharedData::enbSettings.IBLAdditiveAmount; + directionalAmbientColor += iblColor * SharedData::enbSettings.IBLMultiplicativeAmount; + directionalAmbientColorAdditive += iblColor * SharedData::enbSettings.IBLAdditiveAmount; } # endif diff --git a/package/Shaders/Sky.hlsl b/package/Shaders/Sky.hlsl index 2813a9a1e6..71e6e613c2 100644 --- a/package/Shaders/Sky.hlsl +++ b/package/Shaders/Sky.hlsl @@ -255,12 +255,12 @@ PS_OUTPUT main(PS_INPUT input) # endif if ((Permutation::ExtraShaderDescriptor & Permutation::ExtraFlags::IsSun)) { - float distanceFromCenter = length(input.TexCoord0.xy * 2.0 - 1.0); + float distanceFromCenter = length(input.TexCoord0.xy * 2.0 - 1.0); - float sun = smoothstep(SharedData::enbSettings.ProceduralSunSize, - SharedData::enbSettings.ProceduralSunSize - SharedData::enbSettings.ProceduralSunEdgeSoftness * SharedData::enbSettings.ProceduralSunSize * 0.5, + float sun = smoothstep(SharedData::enbSettings.ProceduralSunSize, + SharedData::enbSettings.ProceduralSunSize - SharedData::enbSettings.ProceduralSunEdgeSoftness * SharedData::enbSettings.ProceduralSunSize * 0.5, distanceFromCenter * 25.0); - + float sunGlow = SharedData::enbSettings.ProceduralSunGlowCurve > 0.0 ? pow(pow(saturate(1.0 - distanceFromCenter), rcp(SharedData::enbSettings.ProceduralSunGlowCurve)), 3.0) * SharedData::enbSettings.ProceduralSunGlowIntensity : 0.0; baseColor = sun + sunGlow; diff --git a/src/Features/ENBPostProcessing.cpp b/src/Features/ENBPostProcessing.cpp index 444e17fd4c..dbadd47da2 100644 --- a/src/Features/ENBPostProcessing.cpp +++ b/src/Features/ENBPostProcessing.cpp @@ -70,7 +70,7 @@ ENBPostProcessing::PerFrame ENBPostProcessing::GetCommonBufferData() data.VolumetricRaysColorFilter = settingManager.GetInterpolatedColorTimeOfDayValue("ColorFilter", "GAMEVOLUMETRICRAYS"); data.ProceduralSunSize = settingManager.GetValue("Size", "PROCEDURALSUN"); - data.ProceduralSunEdgeSoftness =settingManager.GetValue("EdgeSoftness", "PROCEDURALSUN"); + data.ProceduralSunEdgeSoftness = settingManager.GetValue("EdgeSoftness", "PROCEDURALSUN"); data.ProceduralSunGlowIntensity = settingManager.GetInterpolatedTimeOfDayValue("GlowIntensity", "PROCEDURALSUN"); data.ProceduralSunGlowCurve = settingManager.GetInterpolatedTimeOfDayValue("GlowCurve", "PROCEDURALSUN"); @@ -110,7 +110,7 @@ float3 Curve(float3 color, float power) return color; } - + float3 Desaturation(float3 color, float desaturation) { float luminance = color.Dot({ 1.0f / 3.0f, 1.0f / 3.0f, 1.0f / 3.0f }); @@ -164,7 +164,7 @@ void ENBPostProcessing::OverrideWeather(RE::Sky* a_sky) dirLightColorF3 = Desaturation(dirLightColorF3, settingManager.GetInterpolatedTimeOfDayValue("DirectLightingDesaturation", "ENVIRONMENT")); dirLightColorF3 = ColorFilter(dirLightColorF3, settingManager.GetInterpolatedColorTimeOfDayValue("DirectLightingColorFilter", "ENVIRONMENT"), settingManager.GetInterpolatedTimeOfDayValue("DirectLightingColorFilterAmount", "ENVIRONMENT")); dirLightColorF3 = Intensity(dirLightColorF3, settingManager.GetInterpolatedTimeOfDayValue("DirectLightingIntensity", "ENVIRONMENT")); - + dirLightColorF3 /= !globals::game::isVR ? imageSpaceManager->GetRuntimeData().data.baseData.hdr.sunlightScale : imageSpaceManager->GetVRRuntimeData().data.baseData.hdr.sunlightScale; dirLightColor = F3ToNi(dirLightColorF3); @@ -204,7 +204,7 @@ void ENBPostProcessing::OverrideWeather(RE::Sky* a_sky) { auto fogAmountMultiplier = settingManager.GetInterpolatedTimeOfDayValue("FogAmountMultiplier", "ENVIRONMENT"); - + a_sky->fogNear /= fogAmountMultiplier; a_sky->fogFar /= fogAmountMultiplier; } @@ -237,7 +237,7 @@ void ENBPostProcessing::OverrideWeather(RE::Sky* a_sky) auto& starsColor = colors[(uint)RE::TESWeather::ColorTypes::kStars]; float3 starsColorF3 = NiToF3(starsColor); - + starsColorF3 = Curve(starsColorF3, settingManager.GetInterpolatedTimeOfDayValue("StarsCurve", "SKY")); starsColorF3 = Intensity(starsColorF3, settingManager.GetInterpolatedTimeOfDayValue("StarsIntensity", "SKY")); @@ -312,7 +312,7 @@ struct Sky_UpdateColors { static void thunk(RE::Sky* This, float a_delta) { - func(This, a_delta); + func(This, a_delta); globals::features::enbPostProcessing.CheckCommonData(); if (globals::features::enbPostProcessing.enableEffect) globals::features::enbPostProcessing.OverrideWeather(This); diff --git a/src/Features/IBL.cpp b/src/Features/IBL.cpp index 748e5fa4c4..22cc695b7a 100644 --- a/src/Features/IBL.cpp +++ b/src/Features/IBL.cpp @@ -86,7 +86,7 @@ void IBL::Prepass() std::array srvs = { (dynamicCubemaps.loaded && envTexture) ? envTexture->srv.get() : nullptr }; std::array uavs = { diffuseIBLTexture->uav.get() }; std::array samplers = { Deferred::GetSingleton()->linearSampler }; - + auto renderer = globals::game::renderer; auto& cubemap = renderer->GetRendererData().cubemapRenderTargets[RE::RENDER_TARGETS_CUBEMAP::kREFLECTIONS]; diff --git a/src/Features/SkySync.cpp b/src/Features/SkySync.cpp index db7795650c..1f12b64729 100644 --- a/src/Features/SkySync.cpp +++ b/src/Features/SkySync.cpp @@ -12,7 +12,23 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT( void SkySync::DrawSettings() { - ImGui::Checkbox("Enabled", &settings.Enabled); + if (ImGui::Checkbox("Enabled", &settings.Enabled)) { + shadowFader.Reset(); + + if (!settings.Enabled) { + auto sky = RE::Sky::GetSingleton(); + if (sky && sky->sun && sky->sun->light) { + auto dir = sky->sun->light->local.rotate.GetVectorX(); + if (dir.Unitize() < FLT_EPSILON) + dir = { 0.0f, 0.0f, 1.0f }; + + ShadowFader::SetLighting(sky->sun, dir, 1.0f); + SetSunBaseVisibility(sky->sun, 1.0f); + } + + volumetricLightingIntensityFactor = 1.0f; + } + } ImGui::Checkbox("Use alternate sun path", &settings.UseAlternateSunPath); @@ -209,10 +225,13 @@ void SkySync::ProcessMoon(const RE::Moon* moon, const float time, const Caster t const float moonRadius = type == Caster::Masser ? static_cast(*gMasserSize) : static_cast(*gSecundaSize); float intensity = CalculateVisibility(dir, moon->moonMesh->local.translate.y, moonRadius); - if (type == Caster::Masser) - intensity *= masserPhaseIntensityFactor; - else if (type == Caster::Secunda) - intensity *= secundaPhaseIntensityFactor * Util::Moon::SecundaIntensityFactor; + if (type == Caster::Masser) { + const float factor = masserPhaseIntensityFactor > 0.0f ? masserPhaseIntensityFactor : 1.0f; + intensity *= factor; + } else if (type == Caster::Secunda) { + const float factor = secundaPhaseIntensityFactor > 0.0f ? secundaPhaseIntensityFactor : 1.0f; + intensity *= factor * Util::Moon::SecundaIntensityFactor; + } if (time >= timings.sunriseFadeOutMoonStart && time <= timings.sunriseFadeOutMoonEnd) intensity *= SmoothStep(timings.sunriseFadeOutMoonEnd, timings.sunriseFadeOutMoonStart, time); @@ -441,22 +460,24 @@ void SkySync::Moon_Update::thunk(RE::Moon* moon, RE::Sky* sky) func(moon, sky); - if (auto& singleton = globals::features::skySync; singleton.settings.Enabled && updateMoonTexture != moon->updateMoonTexture) { - // Gets the texture name of the current moon phase when it changes rather than reading direct global variables - // Allows for compatibility with other mods that don't directly update the in-game phase values - const auto moonShaderProperty = skyrim_cast(moon->moonMesh->GetGeometryRuntimeData().properties[1].get()); - if (!moonShaderProperty) - return; + if (auto& singleton = globals::features::skySync; singleton.settings.Enabled) { + float* target = moon == sky->masser ? &singleton.masserPhaseIntensityFactor : &singleton.secundaPhaseIntensityFactor; + if (updateMoonTexture != moon->updateMoonTexture || *target <= 0.0f) { + // Gets the texture name of the current moon phase when it changes rather than reading direct global variables + // Allows for compatibility with other mods that don't directly update the in-game phase values + const auto moonShaderProperty = skyrim_cast(moon->moonMesh->GetGeometryRuntimeData().properties[1].get()); + if (!moonShaderProperty) + return; - const auto texture = moonShaderProperty->GetBaseTexture(); - if (!texture) - return; + const auto texture = moonShaderProperty->GetBaseTexture(); + if (!texture) + return; - const auto phase = Util::Moon::GetPhaseFromTexture(texture->name.c_str()); - const float intensityFactor = Util::Moon::GetPhaseIntensityFactor(phase); + const auto phase = Util::Moon::GetPhaseFromTexture(texture->name.c_str()); + const float intensityFactor = Util::Moon::GetPhaseIntensityFactor(phase); - float* target = moon == sky->masser ? &singleton.masserPhaseIntensityFactor : &singleton.secundaPhaseIntensityFactor; - *target = intensityFactor; + *target = intensityFactor; + } } } diff --git a/src/State.cpp b/src/State.cpp index c3ba1f8c04..1fd068a4f1 100644 --- a/src/State.cpp +++ b/src/State.cpp @@ -804,7 +804,7 @@ void State::UpdateSharedData([[maybe_unused]] bool a_inWorld, [[maybe_unused]] b data.SecundaColor = color; } } - + sharedDataCB->Update(data); }