From 922e89f9fe8a320af553909fc735fd1ae62e9766 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Sat, 14 Dec 2024 13:33:09 +0100 Subject: [PATCH] Updated shaders to FSR 3.1.3: - Color clamp now uses ellipsoid instead of AABB to help with ghosting streaks - Moved velocity factor to a different section of the accumulate pass --- .../ffx_fsr3upscaler_accumulate.h | 23 +++++++++---------- .../ffx_fsr3upscaler_callbacks_hlsl.h | 2 +- .../fsr3upscaler/ffx_fsr3upscaler_common.h | 2 +- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_accumulate.h b/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_accumulate.h index 2cba17c..084d4d3 100644 --- a/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_accumulate.h +++ b/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_accumulate.h @@ -52,21 +52,20 @@ void RectifyHistory( const FfxFloat32 fReactiveFactor = ffxPow(params.fReactiveMask, 1.0f / 2.0f); const FfxFloat32 fShadingChangeFactor = params.fShadingChange; const FfxFloat32 fBoxScaleT = ffxMax(fVecolityFactor, ffxMax(fDistanceFactor, ffxMax(fAccumulationFactor, ffxMax(fReactiveFactor, fShadingChangeFactor)))); + + const FfxFloat32 fBoxScale = ffxLerp(3.0f, 1.0f, fBoxScaleT); + const FfxFloat32x3 fScaledBoxVec = data.clippingBox.boxVec * FfxFloat32x3(1.7f, 1.0f, 1.0f) * fBoxScale; - const FfxFloat32 fBoxScale = ffxLerp(3.0f, 1.0f, fBoxScaleT); - - const FfxFloat32x3 fScaledBoxVec = data.clippingBox.boxVec * fBoxScale; - const FfxFloat32x3 fBoxMin = data.clippingBox.boxCenter - fScaledBoxVec; - const FfxFloat32x3 fBoxMax = data.clippingBox.boxCenter + fScaledBoxVec; - - if (any(FFX_GREATER_THAN(fBoxMin, data.fHistoryColor)) || any(FFX_GREATER_THAN(data.fHistoryColor, fBoxMax))) { - - const FfxFloat32x3 fClampedHistoryColor = clamp(data.fHistoryColor, fBoxMin, fBoxMax); + const FfxFloat32x3 fClampedScaledBoxVec = ffxMax(fScaledBoxVec, FfxFloat32x3(1.193e-7f, 1.193e-7f, 1.193e-7f)); + const FfxFloat32x3 fTransformedHistoryColor = (data.fHistoryColor - data.clippingBox.boxCenter) / fClampedScaledBoxVec; - const FfxFloat32 fHistoryContribution = ffxMax(params.fLumaInstabilityFactor, data.fLockContributionThisFrame) * params.fAccumulation * (1 - params.fDisocclusion); + if (length(fTransformedHistoryColor)>1.f) { + const FfxFloat32x3 fClampedHistoryColor = normalize(fTransformedHistoryColor); + const FfxFloat32x3 fFinalClampedHistoryColor = (fClampedHistoryColor * fScaledBoxVec) + data.clippingBox.boxCenter; // Scale history color using rectification info, also using accumulation mask to avoid potential invalid color protection - data.fHistoryColor = ffxLerp(fClampedHistoryColor, data.fHistoryColor, ffxSaturate(fHistoryContribution)); + const FfxFloat32 fHistoryContribution = ffxMax(params.fLumaInstabilityFactor, data.fLockContributionThisFrame) * params.fAccumulation * (1 - params.fDisocclusion); + data.fHistoryColor = ffxLerp(fFinalClampedHistoryColor, data.fHistoryColor, ffxSaturate(fHistoryContribution)); } } @@ -97,7 +96,7 @@ void ComputeBaseAccumulationWeight(const AccumulationPassCommonParams params, FF { FfxFloat32 fBaseAccumulation = params.fAccumulation; - fBaseAccumulation = ffxMin(fBaseAccumulation, ffxLerp(fBaseAccumulation, 0.15f, ffxSaturate(ffxMax(0.0f, params.f4KVelocity / 0.5f)))); + fBaseAccumulation = ffxMin(fBaseAccumulation, ffxLerp(fBaseAccumulation, 0.15f, ffxSaturate(ffxMax(0.0f, (params.f4KVelocity * VelocityFactor()) / 0.5f)))); data.fHistoryWeight = fBaseAccumulation; } diff --git a/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_callbacks_hlsl.h b/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_callbacks_hlsl.h index f719674..e6f661c 100644 --- a/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_callbacks_hlsl.h +++ b/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_callbacks_hlsl.h @@ -796,7 +796,7 @@ FfxFloat32 Exposure() FfxFloat32 exposure = r_input_exposure[FfxUInt32x2(0, 0)].x; #if defined(__XBOX_SCARLETT) - if (exposure < 0.000030517578/** 2^15 */) { + if (exposure < 0.000030517578/** 2^-15 */) { exposure = 1.0f; } #else diff --git a/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_common.h b/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_common.h index 28993c6..87aa596 100644 --- a/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_common.h +++ b/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_common.h @@ -123,7 +123,7 @@ struct AccumulationPassCommonParams FfxFloat32 Get4KVelocity(FfxFloat32x2 fMotionVector) { - return length(fMotionVector * FfxFloat32x2(3840.0f, 2160.0f)) * VelocityFactor(); + return length(fMotionVector * FfxFloat32x2(3840.0f, 2160.0f)); } struct RectificationBox