From 5388ffa93e434f41b47ddb21fc02eeb8338475ba Mon Sep 17 00:00:00 2001 From: Tim <15017472+doodlum@users.noreply.github.com> Date: Sun, 17 Nov 2024 01:38:53 +0000 Subject: [PATCH 1/5] refactor: sss menu text --- src/Features/ScreenSpaceShadows.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Features/ScreenSpaceShadows.cpp b/src/Features/ScreenSpaceShadows.cpp index 11b7bfe0a0..23eb3dc980 100644 --- a/src/Features/ScreenSpaceShadows.cpp +++ b/src/Features/ScreenSpaceShadows.cpp @@ -23,11 +23,10 @@ void ScreenSpaceShadows::DrawSettings() { if (ImGui::TreeNodeEx("General", ImGuiTreeNodeFlags_DefaultOpen)) { ImGui::Checkbox("Enable", (bool*)&bendSettings.Enable); - ImGui::SliderInt("Sample Count", (int*)&bendSettings.SampleCount, 1, 4); - - ImGui::SliderFloat("SurfaceThickness", &bendSettings.SurfaceThickness, 0.005f, 0.05f); - ImGui::SliderFloat("BilinearThreshold", &bendSettings.BilinearThreshold, 0.02f, 1.0f); - ImGui::SliderFloat("ShadowContrast", &bendSettings.ShadowContrast, 0.0f, 4.0f); + ImGui::SliderInt("Sample Count Multiplier", (int*)&bendSettings.SampleCount, 1, 4); + ImGui::SliderFloat("Surface Thickness", &bendSettings.SurfaceThickness, 0.005f, 0.05f); + ImGui::SliderFloat("Bilinear Threshold", &bendSettings.BilinearThreshold, 0.02f, 1.0f); + ImGui::SliderFloat("Shadow Contrast", &bendSettings.ShadowContrast, 0.0f, 4.0f); ImGui::Spacing(); ImGui::Spacing(); From 3f1bfe70c3b184be66ef24fb7fa1d48e74cc0ba2 Mon Sep 17 00:00:00 2001 From: Ilya Perapechka <50655277+Jonahex@users.noreply.github.com> Date: Mon, 18 Nov 2024 03:46:43 +0300 Subject: [PATCH 2/5] fix: fixes for pbr land crashes in vr. (#751) Co-authored-by: Ilya Perapechka --- src/TruePBR.cpp | 21 +++++++++++++++------ src/TruePBR.h | 3 +++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/TruePBR.cpp b/src/TruePBR.cpp index fc0b946363..ec1bcce6b1 100644 --- a/src/TruePBR.cpp +++ b/src/TruePBR.cpp @@ -365,6 +365,7 @@ void TruePBR::SetupGlintsTexture() void TruePBR::SetupFrame() { + SetupDefaultPBRLandTextureSet(); } void TruePBR::SetupTextureSetData() @@ -1089,8 +1090,8 @@ void SetupLandscapeTexture(BSLightingShaderMaterialPBRLandscape& material, RE::T RE::TESLandTexture* GetDefaultLandTexture() { - static RE::TESLandTexture* const defaultLandTexture = *REL::Relocation(RELOCATION_ID(514783, 400936)); - return defaultLandTexture; + static const auto defaultLandTextureAddress = REL::Relocation(RELOCATION_ID(514783, 400936)); + return *defaultLandTextureAddress; } struct TESObjectLAND_SetupMaterial @@ -1132,7 +1133,7 @@ struct TESObjectLAND_SetupMaterial if (land->loadedData != nullptr && land->loadedData->mesh[0] != nullptr) { land->data.flags.set(static_cast(8)); for (uint32_t quadIndex = 0; quadIndex < 4; ++quadIndex) { - auto shaderProperty = static_cast(RE::MemoryManager::GetSingleton()->Allocate(sizeof(RE::BSLightingShaderProperty), 0, false)); + auto shaderProperty = static_cast(RE::MemoryManager::GetSingleton()->Allocate(REL::Module::IsVR() ? 0x178 : sizeof(RE::BSLightingShaderProperty), 0, false)); shaderProperty->Ctor(); { @@ -1601,9 +1602,17 @@ void TruePBR::PostPostLoad() void TruePBR::DataLoaded() { defaultPbrLandTextureSet = RE::TESForm::LookupByEditorID("DefaultPBRLand"); - if (defaultPbrLandTextureSet != nullptr) { - logger::info("[TruePBR] replacing default land texture set record with {}", defaultPbrLandTextureSet->GetFormEditorID()); - GetDefaultLandTexture()->textureSet = defaultPbrLandTextureSet; + SetupDefaultPBRLandTextureSet(); +} + +void TruePBR::SetupDefaultPBRLandTextureSet() +{ + if (!defaultLandTextureSetReplaced && defaultPbrLandTextureSet != nullptr) { + if (auto* defaultLandTexture = GetDefaultLandTexture()) { + logger::info("[TruePBR] replacing default land texture set record with {}", defaultPbrLandTextureSet->GetFormEditorID()); + defaultLandTexture->textureSet = defaultPbrLandTextureSet; + defaultLandTextureSetReplaced = true; + } } } diff --git a/src/TruePBR.h b/src/TruePBR.h index b309906c87..64bd6ecd9e 100644 --- a/src/TruePBR.h +++ b/src/TruePBR.h @@ -74,8 +74,11 @@ struct TruePBR PBRTextureSetData* GetPBRTextureSetData(const RE::TESForm* textureSet); bool IsPBRTextureSet(const RE::TESForm* textureSet); + void SetupDefaultPBRLandTextureSet(); + std::unordered_map pbrTextureSets; RE::BGSTextureSet* defaultPbrLandTextureSet = nullptr; + bool defaultLandTextureSetReplaced = false; std::string selectedPbrTextureSetName; PBRTextureSetData* selectedPbrTextureSet = nullptr; From b0a85fc45d6ca6018baedbc40d92a80eda64554f Mon Sep 17 00:00:00 2001 From: doodlum <15017472+doodlum@users.noreply.github.com> Date: Mon, 18 Nov 2024 00:47:47 +0000 Subject: [PATCH 3/5] fix: sky motion vectors (#752) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: sky smear fix attempt * style: 🎨 apply clang-format changes --------- Co-authored-by: doodlum --- package/Shaders/DeferredCompositeCS.hlsl | 30 ++++++++++++------------ package/Shaders/Sky.hlsl | 10 +------- src/Deferred.cpp | 6 ++--- src/Hooks.cpp | 11 +++++++++ 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/package/Shaders/DeferredCompositeCS.hlsl b/package/Shaders/DeferredCompositeCS.hlsl index 6d2e97cb26..a117451bb0 100644 --- a/package/Shaders/DeferredCompositeCS.hlsl +++ b/package/Shaders/DeferredCompositeCS.hlsl @@ -2,6 +2,7 @@ #include "Common/Color.hlsli" #include "Common/FrameBuffer.hlsli" #include "Common/GBuffer.hlsli" +#include "Common/MotionBlur.hlsli" #include "Common/SharedData.hlsli" #include "Common/VR.hlsli" @@ -13,7 +14,7 @@ Texture2D Masks2Texture : register(t4); RWTexture2D MainRW : register(u0); RWTexture2D NormalTAAMaskSpecularMaskRW : register(u1); -RWTexture2D SnowParametersRW : register(u2); +RWTexture2D MotionVectorsRW : register(u2); #if defined(DYNAMIC_CUBEMAPS) Texture2D DepthTexture : register(t5); @@ -42,7 +43,7 @@ Texture2D SpecularSSGITexture : register(t10); : SV_DispatchThreadID) { half2 uv = half2(dispatchID.xy + 0.5) * BufferDim.zw; uint eyeIndex = Stereo::GetEyeIndexFromTexCoord(uv); - uv *= DynamicResolutionParams2.xy; // adjust for dynamic res + uv *= DynamicResolutionParams2.xy; // Adjust for dynamic res uv = Stereo::ConvertFromStereoUV(uv, eyeIndex); half3 normalGlossiness = NormalRoughnessTexture[dispatchID.xy]; @@ -53,7 +54,15 @@ Texture2D SpecularSSGITexture : register(t10); half3 albedo = AlbedoTexture[dispatchID.xy]; half3 masks2 = Masks2Texture[dispatchID.xy]; - half2 snowParameters = masks2.xy; + half depth = DepthTexture[dispatchID.xy]; + half4 positionWS = half4(2 * half2(uv.x, -uv.y + 1) - 1, depth, 1); + positionWS = mul(CameraViewProjInverse[eyeIndex], positionWS); + positionWS.xyz = positionWS.xyz / positionWS.w; + + if (depth == 1.0) { + MotionVectorsRW[dispatchID.xy] = GetSSMotionVector(positionWS, positionWS, eyeIndex); // Apply sky motion vectors + } + half pbrWeight = masks2.z; half glossiness = normalGlossiness.z; @@ -73,15 +82,7 @@ Texture2D SpecularSSGITexture : register(t10); color = Color::GammaToLinear(color); - half depth = DepthTexture[dispatchID.xy]; - - half4 positionCS = half4(2 * half2(uv.x, -uv.y + 1) - 1, depth, 1); - positionCS = mul(CameraViewProjInverse[eyeIndex], positionCS); - positionCS.xyz = positionCS.xyz / positionCS.w; - - half3 positionWS = positionCS.xyz; - - half3 V = normalize(positionWS); + half3 V = normalize(positionWS.xyz); half3 R = reflect(V, normalWS); half roughness = 1.0 - glossiness; @@ -96,9 +97,9 @@ Texture2D SpecularSSGITexture : register(t10); finalIrradiance += specularIrradiance; # elif defined(SKYLIGHTING) # if defined(VR) - float3 positionMS = positionWS + CameraPosAdjust[eyeIndex].xyz - CameraPosAdjust[0].xyz; + float3 positionMS = positionWS.xyz + CameraPosAdjust[eyeIndex].xyz - CameraPosAdjust[0].xyz; # else - float3 positionMS = positionWS; + float3 positionMS = positionWS.xyz; # endif sh2 skylighting = Skylighting::sample(skylightingSettings, SkylightingProbeArray, positionMS.xyz, normalWS); @@ -172,5 +173,4 @@ Texture2D SpecularSSGITexture : register(t10); MainRW[dispatchID.xy] = color; NormalTAAMaskSpecularMaskRW[dispatchID.xy] = half4(GBuffer::EncodeNormalVanilla(normalVS), 0.0, 0.0); - SnowParametersRW[dispatchID.xy] = snowParameters; } \ No newline at end of file diff --git a/package/Shaders/Sky.hlsl b/package/Shaders/Sky.hlsl index 6c990c77d0..f49474b01e 100644 --- a/package/Shaders/Sky.hlsl +++ b/package/Shaders/Sky.hlsl @@ -240,15 +240,7 @@ PS_OUTPUT main(PS_INPUT input) psout.Color = float4(0, 0, 0, 1.0); # endif // OCCLUSION - float3 viewPosition = mul(CameraView[eyeIndex], float4(input.WorldPosition.xyz, 1)).xyz; - float2 screenUV = FrameBuffer::ViewToUV(viewPosition, true, eyeIndex); - - float4 positionWS = half4(2 * half2(screenUV.x, -screenUV.y + 1) - 1, 1.0, 1); - positionWS = mul(CameraViewProjInverse[eyeIndex], positionWS); - positionWS.xyz = positionWS.xyz / positionWS.w; - positionWS.w = 1; - - float2 screenMotionVector = GetSSMotionVector(positionWS, positionWS, eyeIndex); + float2 screenMotionVector = GetSSMotionVector(input.WorldPosition, input.PreviousWorldPosition, eyeIndex); psout.MotionVectors = float4(screenMotionVector, 0, psout.Color.w); psout.Normal = float4(0.5, 0.5, 0, psout.Color.w); diff --git a/src/Deferred.cpp b/src/Deferred.cpp index c6ce40fcd1..b578f96dd8 100644 --- a/src/Deferred.cpp +++ b/src/Deferred.cpp @@ -366,11 +366,11 @@ void Deferred::DeferredPasses() auto main = renderer->GetRuntimeData().renderTargets[forwardRenderTargets[0]]; auto normals = renderer->GetRuntimeData().renderTargets[forwardRenderTargets[2]]; - auto snow = renderer->GetRuntimeData().renderTargets[forwardRenderTargets[3]]; - auto depth = renderer->GetDepthStencilData().depthStencils[RE::RENDER_TARGETS_DEPTHSTENCIL::kPOST_ZPREPASS_COPY]; auto reflectance = renderer->GetRuntimeData().renderTargets[REFLECTANCE]; + auto motionVectors = renderer->GetRuntimeData().renderTargets[RE::RENDER_TARGETS::kMOTION_VECTOR]; + bool interior = true; if (auto sky = RE::Sky::GetSingleton()) interior = sky->mode.get() != RE::Sky::Mode::kFull; @@ -455,7 +455,7 @@ void Deferred::DeferredPasses() context->CSSetShaderResources(0, ARRAYSIZE(srvs), srvs); - ID3D11UnorderedAccessView* uavs[3]{ main.UAV, normals.UAV, snow.UAV }; + ID3D11UnorderedAccessView* uavs[3]{ main.UAV, normals.UAV, motionVectors.UAV }; context->CSSetUnorderedAccessViews(0, ARRAYSIZE(uavs), uavs, nullptr); auto shader = interior ? GetComputeMainCompositeInterior() : GetComputeMainComposite(); diff --git a/src/Hooks.cpp b/src/Hooks.cpp index 887ec07f1b..178ef0b01d 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -443,6 +443,16 @@ namespace Hooks static inline REL::Relocation func; }; + struct CreateRenderTarget_MotionVectors + { + static void thunk(RE::BSGraphics::Renderer* This, RE::RENDER_TARGETS::RENDER_TARGET a_target, RE::BSGraphics::RenderTargetProperties* a_properties) + { + State::GetSingleton()->ModifyRenderTarget(a_target, a_properties); + func(This, a_target, a_properties); + } + static inline REL::Relocation func; + }; + struct BSShader__BeginTechnique_SetVertexShader { static void thunk(RE::BSGraphics::Renderer* This, RE::BSGraphics::VertexShader* a_vertexShader) @@ -674,6 +684,7 @@ namespace Hooks stl::write_thunk_call(REL::RelocationID(100458, 107175).address() + REL::Relocate(0x458, 0x45B, 0x5B0)); stl::write_thunk_call(REL::RelocationID(100458, 107175).address() + REL::Relocate(0x46B, 0x46E, 0x5C3)); stl::write_thunk_call(REL::RelocationID(100458, 107175).address() + REL::Relocate(0x406, 0x409, 0x55e)); + stl::write_thunk_call(REL::RelocationID(100458, 107175).address() + REL::Relocate(0x4F0, 0x4EF, 0x64E)); stl::write_thunk_call(REL::RelocationID(100458, 107175).address() + REL::Relocate(0x1245, 0x123B, 0x1917)); stl::write_thunk_call(REL::RelocationID(100458, 107175).address() + REL::Relocate(0xA25, 0xA25, 0xCD2)); From 14c594917857ae08b7279ee4afdd9a723da9ed54 Mon Sep 17 00:00:00 2001 From: doodlum <15017472+doodlum@users.noreply.github.com> Date: Mon, 18 Nov 2024 01:31:54 +0000 Subject: [PATCH 4/5] chore: remove unused llf flags (#749) --- features/Light Limit Fix/Shaders/LightLimitFix/Common.hlsli | 2 -- src/Features/LightLimitFix.cpp | 3 --- src/Features/LightLimitFix.h | 4 +--- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/features/Light Limit Fix/Shaders/LightLimitFix/Common.hlsli b/features/Light Limit Fix/Shaders/LightLimitFix/Common.hlsli index cdaec13feb..f7e4e7dbb4 100644 --- a/features/Light Limit Fix/Shaders/LightLimitFix/Common.hlsli +++ b/features/Light Limit Fix/Shaders/LightLimitFix/Common.hlsli @@ -12,8 +12,6 @@ namespace LightFlags static const uint PortalStrict = (1 << 0); static const uint Shadow = (1 << 1); static const uint Simple = (1 << 2); - static const uint Particle = (1 << 3); - static const uint Billboard = (1 << 4); } struct ClusterAABB diff --git a/src/Features/LightLimitFix.cpp b/src/Features/LightLimitFix.cpp index 07d768cf34..6c42250698 100644 --- a/src/Features/LightLimitFix.cpp +++ b/src/Features/LightLimitFix.cpp @@ -885,7 +885,6 @@ void LightLimitFix::UpdateLights() } clusteredLight.lightFlags.set(LightFlags::Simple); - clusteredLight.lightFlags.set(LightFlags::Particle); AddCachedParticleLights(lightsData, clusteredLight); @@ -943,7 +942,6 @@ void LightLimitFix::UpdateLights() SetLightPosition(light, position); // Light is complete for both eyes by now light.lightFlags.set(LightFlags::Simple); - light.lightFlags.set(LightFlags::Billboard); AddCachedParticleLights(lightsData, light); } @@ -959,7 +957,6 @@ void LightLimitFix::UpdateLights() clusteredLight.positionWS[1].data.z += eyePositionOffset.z / (float)clusteredLights; } clusteredLight.lightFlags.set(LightFlags::Simple); - clusteredLight.lightFlags.set(LightFlags::Particle); AddCachedParticleLights(lightsData, clusteredLight); } } diff --git a/src/Features/LightLimitFix.h b/src/Features/LightLimitFix.h index 631648130d..ad2ffa24ca 100644 --- a/src/Features/LightLimitFix.h +++ b/src/Features/LightLimitFix.h @@ -29,9 +29,7 @@ struct LightLimitFix : Feature { PortalStrict = (1 << 0), Shadow = (1 << 1), - Simple = (1 << 2), - Particle = (1 << 3), - Billboard = (1 << 4) + Simple = (1 << 2) }; struct PositionOpt From 4a7a343e510ba286ad02ecc86a72883990357d73 Mon Sep 17 00:00:00 2001 From: Tim <15017472+doodlum@users.noreply.github.com> Date: Mon, 18 Nov 2024 15:46:05 +0000 Subject: [PATCH 5/5] fix: Effect soft fade --- package/Shaders/Effect.hlsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/Shaders/Effect.hlsl b/package/Shaders/Effect.hlsl index 8af5db29db..5af223230c 100644 --- a/package/Shaders/Effect.hlsl +++ b/package/Shaders/Effect.hlsl @@ -592,7 +592,7 @@ PS_OUTPUT main(PS_INPUT input) float softMul = 1; # if defined(SOFT) float depth = TexDepthSamplerEffect.Load(int3(input.Position.xy, 0)).x; - softMul = saturate(-input.TexCoord0.w + LightingInfluence.y / ((1 - depth) * CameraData.z + CameraData.y)); + softMul = saturate(-input.TexCoord0.w + LightingInfluence.y / ((1 - depth) * CameraDataEffect.z + CameraDataEffect.y)); # endif float lightingInfluence = LightingInfluence.x;