Path: blob/master/thirdparty/amd-fsr2/shaders/ffx_fsr2_reproject.h
9899 views
// This file is part of the FidelityFX SDK.1//2// Copyright (c) 2022-2023 Advanced Micro Devices, Inc. All rights reserved.3//4// Permission is hereby granted, free of charge, to any person obtaining a copy5// of this software and associated documentation files (the "Software"), to deal6// in the Software without restriction, including without limitation the rights7// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell8// copies of the Software, and to permit persons to whom the Software is9// furnished to do so, subject to the following conditions:10// The above copyright notice and this permission notice shall be included in11// all copies or substantial portions of the Software.12//13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN19// THE SOFTWARE.2021#ifndef FFX_FSR2_REPROJECT_H22#define FFX_FSR2_REPROJECT_H2324#ifndef FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE25#define FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE 0 // Reference26#endif2728FfxFloat32x4 WrapHistory(FfxInt32x2 iPxSample)29{30return LoadHistory(iPxSample);31}3233#if FFX_HALF34FFX_MIN16_F4 WrapHistory(FFX_MIN16_I2 iPxSample)35{36return FFX_MIN16_F4(LoadHistory(iPxSample));37}38#endif394041#if FFX_FSR2_OPTION_REPROJECT_SAMPLERS_USE_DATA_HALF && FFX_HALF42DeclareCustomFetchBicubicSamplesMin16(FetchHistorySamples, WrapHistory)43DeclareCustomTextureSampleMin16(HistorySample, FFX_FSR2_GET_LANCZOS_SAMPLER1D(FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE), FetchHistorySamples)44#else45DeclareCustomFetchBicubicSamples(FetchHistorySamples, WrapHistory)46DeclareCustomTextureSample(HistorySample, FFX_FSR2_GET_LANCZOS_SAMPLER1D(FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE), FetchHistorySamples)47#endif4849FfxFloat32x4 WrapLockStatus(FfxInt32x2 iPxSample)50{51FfxFloat32x4 fSample = FfxFloat32x4(LoadLockStatus(iPxSample), 0.0f, 0.0f);52return fSample;53}5455#if FFX_HALF56FFX_MIN16_F4 WrapLockStatus(FFX_MIN16_I2 iPxSample)57{58FFX_MIN16_F4 fSample = FFX_MIN16_F4(LoadLockStatus(iPxSample), 0.0, 0.0);5960return fSample;61}62#endif6364#if 165#if FFX_FSR2_OPTION_REPROJECT_SAMPLERS_USE_DATA_HALF && FFX_HALF66DeclareCustomFetchBilinearSamplesMin16(FetchLockStatusSamples, WrapLockStatus)67DeclareCustomTextureSampleMin16(LockStatusSample, Bilinear, FetchLockStatusSamples)68#else69DeclareCustomFetchBilinearSamples(FetchLockStatusSamples, WrapLockStatus)70DeclareCustomTextureSample(LockStatusSample, Bilinear, FetchLockStatusSamples)71#endif72#else73#if FFX_FSR2_OPTION_REPROJECT_SAMPLERS_USE_DATA_HALF && FFX_HALF74DeclareCustomFetchBicubicSamplesMin16(FetchLockStatusSamples, WrapLockStatus)75DeclareCustomTextureSampleMin16(LockStatusSample, FFX_FSR2_GET_LANCZOS_SAMPLER1D(FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE), FetchLockStatusSamples)76#else77DeclareCustomFetchBicubicSamples(FetchLockStatusSamples, WrapLockStatus)78DeclareCustomTextureSample(LockStatusSample, FFX_FSR2_GET_LANCZOS_SAMPLER1D(FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE), FetchLockStatusSamples)79#endif80#endif8182FfxFloat32x2 GetMotionVector(FfxInt32x2 iPxHrPos, FfxFloat32x2 fHrUv)83{84#if FFX_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS85FfxFloat32x2 fDilatedMotionVector = LoadDilatedMotionVector(FFX_MIN16_I2(fHrUv * RenderSize()));86#else87FfxFloat32x2 fDilatedMotionVector = LoadInputMotionVector(iPxHrPos);88#endif8990return fDilatedMotionVector;91}9293FfxBoolean IsUvInside(FfxFloat32x2 fUv)94{95return (fUv.x >= 0.0f && fUv.x <= 1.0f) && (fUv.y >= 0.0f && fUv.y <= 1.0f);96}9798void ComputeReprojectedUVs(const AccumulationPassCommonParams params, FFX_PARAMETER_OUT FfxFloat32x2 fReprojectedHrUv, FFX_PARAMETER_OUT FfxBoolean bIsExistingSample)99{100fReprojectedHrUv = params.fHrUv + params.fMotionVector;101102bIsExistingSample = IsUvInside(fReprojectedHrUv);103}104105void ReprojectHistoryColor(const AccumulationPassCommonParams params, FFX_PARAMETER_OUT FfxFloat32x3 fHistoryColor, FFX_PARAMETER_OUT FfxFloat32 fTemporalReactiveFactor, FFX_PARAMETER_OUT FfxBoolean bInMotionLastFrame)106{107FfxFloat32x4 fHistory = HistorySample(params.fReprojectedHrUv, DisplaySize());108109fHistoryColor = PrepareRgb(fHistory.rgb, Exposure(), PreviousFramePreExposure());110111fHistoryColor = RGBToYCoCg(fHistoryColor);112113//Compute temporal reactivity info114fTemporalReactiveFactor = ffxSaturate(abs(fHistory.w));115bInMotionLastFrame = (fHistory.w < 0.0f);116}117118LockState ReprojectHistoryLockStatus(const AccumulationPassCommonParams params, FFX_PARAMETER_OUT FfxFloat32x2 fReprojectedLockStatus)119{120LockState state = { FFX_FALSE, FFX_FALSE };121const FfxFloat32 fNewLockIntensity = LoadRwNewLocks(params.iPxHrPos);122state.NewLock = fNewLockIntensity > (127.0f / 255.0f);123124FfxFloat32 fInPlaceLockLifetime = state.NewLock ? fNewLockIntensity : 0;125126fReprojectedLockStatus = SampleLockStatus(params.fReprojectedHrUv);127128if (fReprojectedLockStatus[LOCK_LIFETIME_REMAINING] != FfxFloat32(0.0f)) {129state.WasLockedPrevFrame = true;130}131132return state;133}134135#endif //!defined( FFX_FSR2_REPROJECT_H )136137138