Debian Codegraph @

thirdparty/amd-fsr2/shaders/ffx_fsr2_postprocess_lock_status.h

raw symbols SCIP
1 // This file is part of the FidelityFX SDK.
2 //
3 // Copyright (c) 2022-2023 Advanced Micro Devices, Inc. All rights reserved.
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 // THE SOFTWARE.
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 //init temporal shading change factor, init to -1 or so in reproject to know if "true new"?
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 // Compute this frame lock contribution
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 //!defined( FFX_FSR2_POSTPROCESS_LOCK_STATUS_H )