| 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_POSTPROCESS_LOCK_STATUS_H |
| 23 |
#define FFX_FSR2_POSTPROCESS_LOCK_STATUS_H |
| 24 |
|
| 25 |
FfxFloat32x4 WrapShadingChangeLuma(FfxInt32x2 iPxSample) |
| 26 |
{ |
| 27 |
return FfxFloat32x4(LoadMipLuma(iPxSample, LumaMipLevelToUse()), 0, 0, 0); |
| 28 |
} |
| 29 |
|
| 30 |
#if FFX_HALF |
| 31 |
FFX_MIN16_F4 WrapShadingChangeLuma(FFX_MIN16_I2 iPxSample) |
| 32 |
{ |
| 33 |
return FFX_MIN16_F4(LoadMipLuma(iPxSample, LumaMipLevelToUse()), 0, 0, 0); |
| 34 |
} |
| 35 |
#endif |
| 36 |
|
| 37 |
#if FFX_FSR2_OPTION_POSTPROCESSLOCKSTATUS_SAMPLERS_USE_DATA_HALF && FFX_HALF |
| 38 |
DeclareCustomFetchBilinearSamplesMin16(FetchShadingChangeLumaSamples, WrapShadingChangeLuma) |
| 39 |
#else |
| 40 |
DeclareCustomFetchBicubicSamples(FetchShadingChangeLumaSamples, WrapShadingChangeLuma) |
| 41 |
#endif |
| 42 |
DeclareCustomTextureSample(ShadingChangeLumaSample, Lanczos2, FetchShadingChangeLumaSamples) |
| 43 |
|
| 44 |
FfxFloat32 GetShadingChangeLuma(FfxInt32x2 iPxHrPos, FfxFloat32x2 fUvCoord) |
| 45 |
{ |
| 46 |
FfxFloat32 fShadingChangeLuma = 0; |
| 47 |
|
| 48 |
#if 0 |
| 49 |
fShadingChangeLuma = Exposure() * exp(ShadingChangeLumaSample(fUvCoord, LumaMipDimensions()).x); |
| 50 |
#else |
| 51 |
|
| 52 |
const FfxFloat32 fDiv = FfxFloat32(2 << LumaMipLevelToUse()); |
| 53 |
FfxInt32x2 iMipRenderSize = FfxInt32x2(RenderSize() / fDiv); |
| 54 |
|
| 55 |
fUvCoord = ClampUv(fUvCoord, iMipRenderSize, LumaMipDimensions()); |
| 56 |
fShadingChangeLuma = Exposure() * exp(FfxFloat32(SampleMipLuma(fUvCoord, LumaMipLevelToUse()))); |
| 57 |
#endif |
| 58 |
|
| 59 |
fShadingChangeLuma = ffxPow(fShadingChangeLuma, 1.0f / 6.0f); |
| 60 |
|
| 61 |
return fShadingChangeLuma; |
| 62 |
} |
| 63 |
|
| 64 |
void UpdateLockStatus(AccumulationPassCommonParams params, |
| 65 |
FFX_PARAMETER_INOUT FfxFloat32 fReactiveFactor, LockState state, |
| 66 |
FFX_PARAMETER_INOUT FfxFloat32x2 fLockStatus, |
| 67 |
FFX_PARAMETER_OUT FfxFloat32 fLockContributionThisFrame, |
| 68 |
FFX_PARAMETER_OUT FfxFloat32 fLuminanceDiff) { |
| 69 |
|
| 70 |
const FfxFloat32 fShadingChangeLuma = GetShadingChangeLuma(params.iPxHrPos, params.fHrUv); |
| 71 |
|
| 72 |
|
| 73 |
fLockStatus[LOCK_TEMPORAL_LUMA] = (fLockStatus[LOCK_TEMPORAL_LUMA] == FfxFloat32(0.0f)) ? fShadingChangeLuma : fLockStatus[LOCK_TEMPORAL_LUMA]; |
| 74 |
|
| 75 |
FfxFloat32 fPreviousShadingChangeLuma = fLockStatus[LOCK_TEMPORAL_LUMA]; |
| 76 |
|
| 77 |
fLuminanceDiff = 1.0f - MinDividedByMax(fPreviousShadingChangeLuma, fShadingChangeLuma); |
| 78 |
|
| 79 |
if (state.NewLock) { |
| 80 |
fLockStatus[LOCK_TEMPORAL_LUMA] = fShadingChangeLuma; |
| 81 |
|
| 82 |
fLockStatus[LOCK_LIFETIME_REMAINING] = (fLockStatus[LOCK_LIFETIME_REMAINING] != 0.0f) ? 2.0f : 1.0f; |
| 83 |
} |
| 84 |
else if(fLockStatus[LOCK_LIFETIME_REMAINING] <= 1.0f) { |
| 85 |
fLockStatus[LOCK_TEMPORAL_LUMA] = ffxLerp(fLockStatus[LOCK_TEMPORAL_LUMA], FfxFloat32(fShadingChangeLuma), 0.5f); |
| 86 |
} |
| 87 |
else { |
| 88 |
if (fLuminanceDiff > 0.1f) { |
| 89 |
KillLock(fLockStatus); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
fReactiveFactor = ffxMax(fReactiveFactor, ffxSaturate((fLuminanceDiff - 0.1f) * 10.0f)); |
| 94 |
fLockStatus[LOCK_LIFETIME_REMAINING] *= (1.0f - fReactiveFactor); |
| 95 |
|
| 96 |
fLockStatus[LOCK_LIFETIME_REMAINING] *= ffxSaturate(1.0f - params.fAccumulationMask); |
| 97 |
fLockStatus[LOCK_LIFETIME_REMAINING] *= FfxFloat32(params.fDepthClipFactor < 0.1f); |
| 98 |
|
| 99 |
|
| 100 |
const FfxFloat32 fLifetimeContribution = ffxSaturate(fLockStatus[LOCK_LIFETIME_REMAINING] - 1.0f); |
| 101 |
const FfxFloat32 fShadingChangeContribution = ffxSaturate(MinDividedByMax(fLockStatus[LOCK_TEMPORAL_LUMA], fShadingChangeLuma)); |
| 102 |
|
| 103 |
fLockContributionThisFrame = ffxSaturate(ffxSaturate(fLifetimeContribution * 4.0f) * fShadingChangeContribution); |
| 104 |
} |
| 105 |
|
| 106 |
#endif |