| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#ifndef FFX_FSR2_REPROJECT_H |
| 23 |
#define FFX_FSR2_REPROJECT_H |
| 24 |
|
| 25 |
#ifndef FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE |
| 26 |
#define FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE 0 // Reference |
| 27 |
#endif |
| 28 |
|
| 29 |
FfxFloat32x4 WrapHistory(FfxInt32x2 iPxSample) |
| 30 |
{ |
| 31 |
return LoadHistory(iPxSample); |
| 32 |
} |
| 33 |
|
| 34 |
#if FFX_HALF |
| 35 |
FFX_MIN16_F4 WrapHistory(FFX_MIN16_I2 iPxSample) |
| 36 |
{ |
| 37 |
return FFX_MIN16_F4(LoadHistory(iPxSample)); |
| 38 |
} |
| 39 |
#endif |
| 40 |
|
| 41 |
|
| 42 |
#if FFX_FSR2_OPTION_REPROJECT_SAMPLERS_USE_DATA_HALF && FFX_HALF |
| 43 |
DeclareCustomFetchBicubicSamplesMin16(FetchHistorySamples, WrapHistory) |
| 44 |
DeclareCustomTextureSampleMin16(HistorySample, FFX_FSR2_GET_LANCZOS_SAMPLER1D(FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE), FetchHistorySamples) |
| 45 |
#else |
| 46 |
DeclareCustomFetchBicubicSamples(FetchHistorySamples, WrapHistory) |
| 47 |
DeclareCustomTextureSample(HistorySample, FFX_FSR2_GET_LANCZOS_SAMPLER1D(FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE), FetchHistorySamples) |
| 48 |
#endif |
| 49 |
|
| 50 |
FfxFloat32x4 WrapLockStatus(FfxInt32x2 iPxSample) |
| 51 |
{ |
| 52 |
FfxFloat32x4 fSample = FfxFloat32x4(LoadLockStatus(iPxSample), 0.0f, 0.0f); |
| 53 |
return fSample; |
| 54 |
} |
| 55 |
|
| 56 |
#if FFX_HALF |
| 57 |
FFX_MIN16_F4 WrapLockStatus(FFX_MIN16_I2 iPxSample) |
| 58 |
{ |
| 59 |
FFX_MIN16_F4 fSample = FFX_MIN16_F4(LoadLockStatus(iPxSample), 0.0, 0.0); |
| 60 |
|
| 61 |
return fSample; |
| 62 |
} |
| 63 |
#endif |
| 64 |
|
| 65 |
#if 1 |
| 66 |
#if FFX_FSR2_OPTION_REPROJECT_SAMPLERS_USE_DATA_HALF && FFX_HALF |
| 67 |
DeclareCustomFetchBilinearSamplesMin16(FetchLockStatusSamples, WrapLockStatus) |
| 68 |
DeclareCustomTextureSampleMin16(LockStatusSample, Bilinear, FetchLockStatusSamples) |
| 69 |
#else |
| 70 |
DeclareCustomFetchBilinearSamples(FetchLockStatusSamples, WrapLockStatus) |
| 71 |
DeclareCustomTextureSample(LockStatusSample, Bilinear, FetchLockStatusSamples) |
| 72 |
#endif |
| 73 |
#else |
| 74 |
#if FFX_FSR2_OPTION_REPROJECT_SAMPLERS_USE_DATA_HALF && FFX_HALF |
| 75 |
DeclareCustomFetchBicubicSamplesMin16(FetchLockStatusSamples, WrapLockStatus) |
| 76 |
DeclareCustomTextureSampleMin16(LockStatusSample, FFX_FSR2_GET_LANCZOS_SAMPLER1D(FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE), FetchLockStatusSamples) |
| 77 |
#else |
| 78 |
DeclareCustomFetchBicubicSamples(FetchLockStatusSamples, WrapLockStatus) |
| 79 |
DeclareCustomTextureSample(LockStatusSample, FFX_FSR2_GET_LANCZOS_SAMPLER1D(FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE), FetchLockStatusSamples) |
| 80 |
#endif |
| 81 |
#endif |
| 82 |
|
| 83 |
FfxFloat32x2 GetMotionVector(FfxInt32x2 iPxHrPos, FfxFloat32x2 fHrUv) |
| 84 |
{ |
| 85 |
#if FFX_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS |
| 86 |
FfxFloat32x2 fDilatedMotionVector = LoadDilatedMotionVector(FFX_MIN16_I2(fHrUv * RenderSize())); |
| 87 |
#else |
| 88 |
FfxFloat32x2 fDilatedMotionVector = LoadInputMotionVector(iPxHrPos); |
| 89 |
#endif |
| 90 |
|
| 91 |
return fDilatedMotionVector; |
| 92 |
} |
| 93 |
|
| 94 |
FfxBoolean IsUvInside(FfxFloat32x2 fUv) |
| 95 |
{ |
| 96 |
return (fUv.x >= 0.0f && fUv.x <= 1.0f) && (fUv.y >= 0.0f && fUv.y <= 1.0f); |
| 97 |
} |
| 98 |
|
| 99 |
void ComputeReprojectedUVs(const AccumulationPassCommonParams params, FFX_PARAMETER_OUT FfxFloat32x2 fReprojectedHrUv, FFX_PARAMETER_OUT FfxBoolean bIsExistingSample) |
| 100 |
{ |
| 101 |
fReprojectedHrUv = params.fHrUv + params.fMotionVector; |
| 102 |
|
| 103 |
bIsExistingSample = IsUvInside(fReprojectedHrUv); |
| 104 |
} |
| 105 |
|
| 106 |
void ReprojectHistoryColor(const AccumulationPassCommonParams params, FFX_PARAMETER_OUT FfxFloat32x3 fHistoryColor, FFX_PARAMETER_OUT FfxFloat32 fTemporalReactiveFactor, FFX_PARAMETER_OUT FfxBoolean bInMotionLastFrame) |
| 107 |
{ |
| 108 |
FfxFloat32x4 fHistory = HistorySample(params.fReprojectedHrUv, DisplaySize()); |
| 109 |
|
| 110 |
fHistoryColor = PrepareRgb(fHistory.rgb, Exposure(), PreviousFramePreExposure()); |
| 111 |
|
| 112 |
fHistoryColor = RGBToYCoCg(fHistoryColor); |
| 113 |
|
| 114 |
|
| 115 |
fTemporalReactiveFactor = ffxSaturate(abs(fHistory.w)); |
| 116 |
bInMotionLastFrame = (fHistory.w < 0.0f); |
| 117 |
} |
| 118 |
|
| 119 |
LockState ReprojectHistoryLockStatus(const AccumulationPassCommonParams params, FFX_PARAMETER_OUT FfxFloat32x2 fReprojectedLockStatus) |
| 120 |
{ |
| 121 |
LockState state = { FFX_FALSE, FFX_FALSE }; |
| 122 |
const FfxFloat32 fNewLockIntensity = LoadRwNewLocks(params.iPxHrPos); |
| 123 |
state.NewLock = fNewLockIntensity > (127.0f / 255.0f); |
| 124 |
|
| 125 |
FfxFloat32 fInPlaceLockLifetime = state.NewLock ? fNewLockIntensity : 0; |
| 126 |
|
| 127 |
fReprojectedLockStatus = SampleLockStatus(params.fReprojectedHrUv); |
| 128 |
|
| 129 |
if (fReprojectedLockStatus[LOCK_LIFETIME_REMAINING] != FfxFloat32(0.0f)) { |
| 130 |
state.WasLockedPrevFrame = true; |
| 131 |
} |
| 132 |
|
| 133 |
return state; |
| 134 |
} |
| 135 |
|
| 136 |
#endif |