| 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_RECONSTRUCT_DILATED_VELOCITY_AND_PREVIOUS_DEPTH_H |
| 23 |
#define FFX_FSR2_RECONSTRUCT_DILATED_VELOCITY_AND_PREVIOUS_DEPTH_H |
| 24 |
|
| 25 |
void ReconstructPrevDepth(FfxInt32x2 iPxPos, FfxFloat32 fDepth, FfxFloat32x2 fMotionVector, FfxInt32x2 iPxDepthSize) |
| 26 |
{ |
| 27 |
fMotionVector *= FfxFloat32(length(fMotionVector * DisplaySize()) > 0.1f); |
| 28 |
|
| 29 |
FfxFloat32x2 fUv = (iPxPos + FfxFloat32(0.5)) / iPxDepthSize; |
| 30 |
FfxFloat32x2 fReprojectedUv = fUv + fMotionVector; |
| 31 |
|
| 32 |
BilinearSamplingData bilinearInfo = GetBilinearSamplingData(fReprojectedUv, RenderSize()); |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
for (FfxInt32 iSampleIndex = 0; iSampleIndex < 4; iSampleIndex++) { |
| 37 |
|
| 38 |
const FfxInt32x2 iOffset = bilinearInfo.iOffsets[iSampleIndex]; |
| 39 |
FfxFloat32 fWeight = bilinearInfo.fWeights[iSampleIndex]; |
| 40 |
|
| 41 |
if (fWeight > fReconstructedDepthBilinearWeightThreshold) { |
| 42 |
|
| 43 |
FfxInt32x2 iStorePos = bilinearInfo.iBasePos + iOffset; |
| 44 |
if (IsOnScreen(iStorePos, iPxDepthSize)) { |
| 45 |
StoreReconstructedDepth(iStorePos, fDepth); |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
void FindNearestDepth(FFX_PARAMETER_IN FfxInt32x2 iPxPos, FFX_PARAMETER_IN FfxInt32x2 iPxSize, FFX_PARAMETER_OUT FfxFloat32 fNearestDepth, FFX_PARAMETER_OUT FfxInt32x2 fNearestDepthCoord) |
| 52 |
{ |
| 53 |
const FfxInt32 iSampleCount = 9; |
| 54 |
const FfxInt32x2 iSampleOffsets[iSampleCount] = { |
| 55 |
FfxInt32x2(+0, +0), |
| 56 |
FfxInt32x2(+1, +0), |
| 57 |
FfxInt32x2(+0, +1), |
| 58 |
FfxInt32x2(+0, -1), |
| 59 |
FfxInt32x2(-1, +0), |
| 60 |
FfxInt32x2(-1, +1), |
| 61 |
FfxInt32x2(+1, +1), |
| 62 |
FfxInt32x2(-1, -1), |
| 63 |
FfxInt32x2(+1, -1), |
| 64 |
}; |
| 65 |
|
| 66 |
|
| 67 |
FfxFloat32 depth[9]; |
| 68 |
FfxInt32 iSampleIndex = 0; |
| 69 |
FFX_UNROLL |
| 70 |
for (iSampleIndex = 0; iSampleIndex < iSampleCount; ++iSampleIndex) { |
| 71 |
|
| 72 |
FfxInt32x2 iPos = iPxPos + iSampleOffsets[iSampleIndex]; |
| 73 |
depth[iSampleIndex] = LoadInputDepth(iPos); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
fNearestDepthCoord = iPxPos; |
| 78 |
fNearestDepth = depth[0]; |
| 79 |
FFX_UNROLL |
| 80 |
for (iSampleIndex = 1; iSampleIndex < iSampleCount; ++iSampleIndex) { |
| 81 |
|
| 82 |
FfxInt32x2 iPos = iPxPos + iSampleOffsets[iSampleIndex]; |
| 83 |
if (IsOnScreen(iPos, iPxSize)) { |
| 84 |
|
| 85 |
FfxFloat32 fNdDepth = depth[iSampleIndex]; |
| 86 |
#if FFX_FSR2_OPTION_INVERTED_DEPTH |
| 87 |
if (fNdDepth > fNearestDepth) { |
| 88 |
#else |
| 89 |
if (fNdDepth < fNearestDepth) { |
| 90 |
#endif |
| 91 |
fNearestDepthCoord = iPos; |
| 92 |
fNearestDepth = fNdDepth; |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
FfxFloat32 ComputeLockInputLuma(FfxInt32x2 iPxLrPos) |
| 99 |
{ |
| 100 |
|
| 101 |
|
| 102 |
FfxFloat32x3 fRgb = ffxMax(FfxFloat32x3(0, 0, 0), LoadInputColor(iPxLrPos)); |
| 103 |
|
| 104 |
|
| 105 |
fRgb /= PreExposure(); |
| 106 |
fRgb *= Exposure(); |
| 107 |
|
| 108 |
#if FFX_FSR2_OPTION_HDR_COLOR_INPUT |
| 109 |
fRgb = Tonemap(fRgb); |
| 110 |
#endif |
| 111 |
|
| 112 |
|
| 113 |
const FfxFloat32 fLockInputLuma = ffxPow(RGBToPerceivedLuma(fRgb), FfxFloat32(1.0 / 6.0)); |
| 114 |
|
| 115 |
return fLockInputLuma; |
| 116 |
} |
| 117 |
|
| 118 |
void ReconstructAndDilate(FfxInt32x2 iPxLrPos) |
| 119 |
{ |
| 120 |
FfxFloat32 fDilatedDepth; |
| 121 |
FfxInt32x2 iNearestDepthCoord; |
| 122 |
|
| 123 |
FindNearestDepth(iPxLrPos, RenderSize(), fDilatedDepth, iNearestDepthCoord); |
| 124 |
|
| 125 |
#if FFX_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS |
| 126 |
FfxInt32x2 iSamplePos = iPxLrPos; |
| 127 |
FfxInt32x2 iMotionVectorPos = iNearestDepthCoord; |
| 128 |
#else |
| 129 |
FfxInt32x2 iSamplePos = ComputeHrPosFromLrPos(iPxLrPos); |
| 130 |
FfxInt32x2 iMotionVectorPos = ComputeHrPosFromLrPos(iNearestDepthCoord); |
| 131 |
#endif |
| 132 |
|
| 133 |
FfxFloat32x2 fDilatedMotionVector = LoadInputMotionVector(iMotionVectorPos); |
| 134 |
|
| 135 |
StoreDilatedDepth(iPxLrPos, fDilatedDepth); |
| 136 |
StoreDilatedMotionVector(iPxLrPos, fDilatedMotionVector); |
| 137 |
|
| 138 |
ReconstructPrevDepth(iPxLrPos, fDilatedDepth, fDilatedMotionVector, RenderSize()); |
| 139 |
|
| 140 |
FfxFloat32 fLockInputLuma = ComputeLockInputLuma(iPxLrPos); |
| 141 |
StoreLockInputLuma(iPxLrPos, fLockInputLuma); |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
#endif |