| 1 |
diff --git a/thirdparty/amd-fsr2/ffx_fsr2.cpp b/thirdparty/amd-fsr2/ffx_fsr2.cpp |
| 2 |
index 3970aa7f5b..ec571b9cd2 100644 |
| 3 |
--- a/thirdparty/amd-fsr2/ffx_fsr2.cpp |
| 4 |
+++ b/thirdparty/amd-fsr2/ffx_fsr2.cpp |
| 5 |
@@ -952,6 +952,8 @@ static FfxErrorCode fsr2Dispatch(FfxFsr2Context_Private* context, const FfxFsr2D |
| 6 |
context->constants.lumaMipDimensions[0] = uint32_t(context->constants.maxRenderSize[0] / mipDiv); |
| 7 |
context->constants.lumaMipDimensions[1] = uint32_t(context->constants.maxRenderSize[1] / mipDiv); |
| 8 |
|
| 9 |
+ memcpy(context->constants.reprojectionMatrix, params->reprojectionMatrix, sizeof(context->constants.reprojectionMatrix)); |
| 10 |
+ |
| 11 |
// reactive mask bias |
| 12 |
const int32_t threadGroupWorkRegionDim = 8; |
| 13 |
const int32_t dispatchSrcX = (context->constants.renderSize[0] + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; |
| 14 |
diff --git a/thirdparty/amd-fsr2/ffx_fsr2.h b/thirdparty/amd-fsr2/ffx_fsr2.h |
| 15 |
index 2a1c74abb1..dfcd4caf35 100644 |
| 16 |
--- a/thirdparty/amd-fsr2/ffx_fsr2.h |
| 17 |
+++ b/thirdparty/amd-fsr2/ffx_fsr2.h |
| 18 |
@@ -146,6 +146,7 @@ typedef struct FfxFsr2DispatchDescription { |
| 19 |
float autoReactiveScale; ///< A value to scale the reactive mask |
| 20 |
float autoReactiveMax; ///< A value to clamp the reactive mask |
| 21 |
|
| 22 |
+ float reprojectionMatrix[16]; ///< The matrix used for reprojecting pixels with invalid motion vectors by using the depth. |
| 23 |
} FfxFsr2DispatchDescription; |
| 24 |
|
| 25 |
/// A structure encapsulating the parameters for automatic generation of a reactive mask |
| 26 |
diff --git a/thirdparty/amd-fsr2/ffx_fsr2_private.h b/thirdparty/amd-fsr2/ffx_fsr2_private.h |
| 27 |
index 6b5fbc5117..8a9aec5778 100644 |
| 28 |
--- a/thirdparty/amd-fsr2/ffx_fsr2_private.h |
| 29 |
+++ b/thirdparty/amd-fsr2/ffx_fsr2_private.h |
| 30 |
@@ -44,6 +44,9 @@ typedef struct Fsr2Constants { |
| 31 |
float deltaTime; |
| 32 |
float dynamicResChangeFactor; |
| 33 |
float viewSpaceToMetersFactor; |
| 34 |
+ |
| 35 |
+ float pad; |
| 36 |
+ float reprojectionMatrix[16]; |
| 37 |
} Fsr2Constants; |
| 38 |
|
| 39 |
struct FfxFsr2ContextDescription; |
| 40 |
diff --git a/thirdparty/amd-fsr2/shaders/ffx_fsr2_accumulate_pass.glsl b/thirdparty/amd-fsr2/shaders/ffx_fsr2_accumulate_pass.glsl |
| 41 |
index 31d68292d4..2e98c8a6c5 100644 |
| 42 |
--- a/thirdparty/amd-fsr2/shaders/ffx_fsr2_accumulate_pass.glsl |
| 43 |
+++ b/thirdparty/amd-fsr2/shaders/ffx_fsr2_accumulate_pass.glsl |
| 44 |
@@ -35,7 +35,7 @@ |
| 45 |
#endif |
| 46 |
#define FSR2_BIND_SRV_INTERNAL_UPSCALED 3 |
| 47 |
#define FSR2_BIND_SRV_LOCK_STATUS 4 |
| 48 |
-#define FSR2_BIND_SRV_INPUT_DEPTH_CLIP 5 |
| 49 |
+//#define FSR2_BIND_SRV_INPUT_DEPTH_CLIP 5 |
| 50 |
#define FSR2_BIND_SRV_PREPARED_INPUT_COLOR 6 |
| 51 |
#define FSR2_BIND_SRV_LUMA_INSTABILITY 7 |
| 52 |
#define FSR2_BIND_SRV_LANCZOS_LUT 8 |
| 53 |
@@ -52,6 +52,10 @@ |
| 54 |
|
| 55 |
#define FSR2_BIND_CB_FSR2 18 |
| 56 |
|
| 57 |
+#if FFX_FSR2_OPTION_GODOT_DERIVE_INVALID_MOTION_VECTORS |
| 58 |
+#define FSR2_BIND_SRV_INPUT_DEPTH 5 |
| 59 |
+#endif |
| 60 |
+ |
| 61 |
#include "ffx_fsr2_callbacks_glsl.h" |
| 62 |
#include "ffx_fsr2_common.h" |
| 63 |
#include "ffx_fsr2_sample.h" |
| 64 |
diff --git a/thirdparty/amd-fsr2/shaders/ffx_fsr2_callbacks_glsl.h b/thirdparty/amd-fsr2/shaders/ffx_fsr2_callbacks_glsl.h |
| 65 |
index 10da13fb81..b610037cc6 100644 |
| 66 |
--- a/thirdparty/amd-fsr2/shaders/ffx_fsr2_callbacks_glsl.h |
| 67 |
+++ b/thirdparty/amd-fsr2/shaders/ffx_fsr2_callbacks_glsl.h |
| 68 |
@@ -52,6 +52,9 @@ |
| 69 |
FfxFloat32 fDeltaTime; |
| 70 |
FfxFloat32 fDynamicResChangeFactor; |
| 71 |
FfxFloat32 fViewSpaceToMetersFactor; |
| 72 |
+ |
| 73 |
+ FfxFloat32 fPad; |
| 74 |
+ mat4 mReprojectionMatrix; |
| 75 |
} cbFSR2; |
| 76 |
#endif |
| 77 |
|
| 78 |
@@ -317,7 +320,11 @@ FfxFloat32 LoadInputDepth(FfxInt32x2 iPxPos) |
| 79 |
#if defined(FSR2_BIND_SRV_REACTIVE_MASK) |
| 80 |
FfxFloat32 LoadReactiveMask(FfxInt32x2 iPxPos) |
| 81 |
{ |
| 82 |
+#if FFX_FSR2_OPTION_GODOT_REACTIVE_MASK_CLAMP |
| 83 |
+ return min(texelFetch(r_reactive_mask, FfxInt32x2(iPxPos), 0).r, 0.9f); |
| 84 |
+#else |
| 85 |
return texelFetch(r_reactive_mask, FfxInt32x2(iPxPos), 0).r; |
| 86 |
+#endif |
| 87 |
} |
| 88 |
#endif |
| 89 |
|
| 90 |
@@ -354,6 +361,16 @@ FfxFloat32x2 LoadInputMotionVector(FfxInt32x2 iPxDilatedMotionVectorPos) |
| 91 |
{ |
| 92 |
FfxFloat32x2 fSrcMotionVector = texelFetch(r_input_motion_vectors, iPxDilatedMotionVectorPos, 0).xy; |
| 93 |
|
| 94 |
+#if FFX_FSR2_OPTION_GODOT_DERIVE_INVALID_MOTION_VECTORS |
| 95 |
+ bool bInvalidMotionVector = all(lessThanEqual(fSrcMotionVector, vec2(-1.0f, -1.0f))); |
| 96 |
+ if (bInvalidMotionVector) |
| 97 |
+ { |
| 98 |
+ FfxFloat32 fSrcDepth = LoadInputDepth(iPxDilatedMotionVectorPos); |
| 99 |
+ FfxFloat32x2 fUv = (iPxDilatedMotionVectorPos + FfxFloat32(0.5)) / RenderSize(); |
| 100 |
+ fSrcMotionVector = FFX_FSR2_OPTION_GODOT_DERIVE_INVALID_MOTION_VECTORS_FUNCTION(fUv, fSrcDepth, cbFSR2.mReprojectionMatrix); |
| 101 |
+ } |
| 102 |
+#endif |
| 103 |
+ |
| 104 |
FfxFloat32x2 fUvMotionVector = fSrcMotionVector * MotionVectorScale(); |
| 105 |
|
| 106 |
#if FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS |
| 107 |
diff --git a/thirdparty/amd-fsr2/shaders/ffx_fsr2_tcr_autogen_pass.glsl b/thirdparty/amd-fsr2/shaders/ffx_fsr2_tcr_autogen_pass.glsl |
| 108 |
index 7d6a66b8ac..5c042c332a 100644 |
| 109 |
--- a/thirdparty/amd-fsr2/shaders/ffx_fsr2_tcr_autogen_pass.glsl |
| 110 |
+++ b/thirdparty/amd-fsr2/shaders/ffx_fsr2_tcr_autogen_pass.glsl |
| 111 |
@@ -40,6 +40,10 @@ |
| 112 |
#define FSR2_BIND_CB_FSR2 11 |
| 113 |
#define FSR2_BIND_CB_REACTIVE 12 |
| 114 |
|
| 115 |
+#if FFX_FSR2_OPTION_GODOT_DERIVE_INVALID_MOTION_VECTORS |
| 116 |
+#define FSR2_BIND_SRV_INPUT_DEPTH 13 |
| 117 |
+#endif |
| 118 |
+ |
| 119 |
#include "ffx_fsr2_callbacks_glsl.h" |
| 120 |
#include "ffx_fsr2_common.h" |
| 121 |
|