| 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_LOCK_H |
| 23 |
#define FFX_FSR2_LOCK_H |
| 24 |
|
| 25 |
void ClearResourcesForNextFrame(in FfxInt32x2 iPxHrPos) |
| 26 |
{ |
| 27 |
if (all(FFX_LESS_THAN(iPxHrPos, FfxInt32x2(RenderSize())))) |
| 28 |
{ |
| 29 |
#if FFX_FSR2_OPTION_INVERTED_DEPTH |
| 30 |
const FfxUInt32 farZ = 0x0; |
| 31 |
#else |
| 32 |
const FfxUInt32 farZ = 0x3f800000; |
| 33 |
#endif |
| 34 |
SetReconstructedDepth(iPxHrPos, farZ); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
FfxBoolean ComputeThinFeatureConfidence(FfxInt32x2 pos) |
| 39 |
{ |
| 40 |
const FfxInt32 RADIUS = 1; |
| 41 |
|
| 42 |
FfxFloat32 fNucleus = LoadLockInputLuma(pos); |
| 43 |
|
| 44 |
FfxFloat32 similar_threshold = 1.05f; |
| 45 |
FfxFloat32 dissimilarLumaMin = FSR2_FLT_MAX; |
| 46 |
FfxFloat32 dissimilarLumaMax = 0; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
#define SETBIT(x) (1U << x) |
| 55 |
|
| 56 |
FfxUInt32 mask = SETBIT(4); |
| 57 |
|
| 58 |
const FfxUInt32 uNumRejectionMasks = 4; |
| 59 |
const FfxUInt32 uRejectionMasks[uNumRejectionMasks] = { |
| 60 |
SETBIT(0) | SETBIT(1) | SETBIT(3) | SETBIT(4), |
| 61 |
SETBIT(1) | SETBIT(2) | SETBIT(4) | SETBIT(5), |
| 62 |
SETBIT(3) | SETBIT(4) | SETBIT(6) | SETBIT(7), |
| 63 |
SETBIT(4) | SETBIT(5) | SETBIT(7) | SETBIT(8), |
| 64 |
}; |
| 65 |
|
| 66 |
FfxInt32 idx = 0; |
| 67 |
FFX_UNROLL |
| 68 |
for (FfxInt32 y = -RADIUS; y <= RADIUS; y++) { |
| 69 |
FFX_UNROLL |
| 70 |
for (FfxInt32 x = -RADIUS; x <= RADIUS; x++, idx++) { |
| 71 |
if (x == 0 && y == 0) continue; |
| 72 |
|
| 73 |
FfxInt32x2 samplePos = ClampLoad(pos, FfxInt32x2(x, y), FfxInt32x2(RenderSize())); |
| 74 |
|
| 75 |
FfxFloat32 sampleLuma = LoadLockInputLuma(samplePos); |
| 76 |
FfxFloat32 difference = ffxMax(sampleLuma, fNucleus) / ffxMin(sampleLuma, fNucleus); |
| 77 |
|
| 78 |
if (difference > 0 && (difference < similar_threshold)) { |
| 79 |
mask |= SETBIT(idx); |
| 80 |
} else { |
| 81 |
dissimilarLumaMin = ffxMin(dissimilarLumaMin, sampleLuma); |
| 82 |
dissimilarLumaMax = ffxMax(dissimilarLumaMax, sampleLuma); |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
FfxBoolean isRidge = fNucleus > dissimilarLumaMax || fNucleus < dissimilarLumaMin; |
| 88 |
|
| 89 |
if (FFX_FALSE == isRidge) { |
| 90 |
|
| 91 |
return false; |
| 92 |
} |
| 93 |
|
| 94 |
FFX_UNROLL |
| 95 |
for (FfxInt32 i = 0; i < 4; i++) { |
| 96 |
|
| 97 |
if ((mask & uRejectionMasks[i]) == uRejectionMasks[i]) { |
| 98 |
return false; |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
return true; |
| 103 |
} |
| 104 |
|
| 105 |
void ComputeLock(FfxInt32x2 iPxLrPos) |
| 106 |
{ |
| 107 |
if (ComputeThinFeatureConfidence(iPxLrPos)) |
| 108 |
{ |
| 109 |
StoreNewLocks(ComputeHrPosFromLrPos(iPxLrPos), 1.f); |
| 110 |
} |
| 111 |
|
| 112 |
ClearResourcesForNextFrame(iPxLrPos); |
| 113 |
} |
| 114 |
|
| 115 |
#endif |