Browse Source
Added FSR 3.1 implementation and moved it plus FSR 2.2 into a separate package.
fsr3.1
Added FSR 3.1 implementation and moved it plus FSR 2.2 into a separate package.
fsr3.1
217 changed files with 10560 additions and 2313 deletions
-
26Assets/FSR3 Upscaler Assets.asset
-
0Assets/FSR3 Upscaler Assets.asset.meta
-
23Assets/Fsr3UpscalerAssets.asset
-
80Assets/Scripts/Core/Fsr3ShaderIDs.cs
-
11Assets/Scripts/Fsr3UpscalerImageEffect.cs
-
7Assets/Shaders/FSR3/shaders/ffx_fsr3upscaler_depth_clip_pass.hlsl.meta
-
7Assets/Shaders/FSR3/shaders/ffx_fsr3upscaler_lock_pass.hlsl.meta
-
7Assets/Shaders/FSR3/shaders/ffx_fsr3upscaler_reconstruct_previous_depth_pass.hlsl.meta
-
338Assets/Shaders/FSR3/shaders/fsr3upscaler/ffx_core_cpu.h
-
65Assets/Shaders/FSR3/shaders/fsr3upscaler/ffx_fsr3upscaler_compute_luminance_pyramid.h.meta
-
65Assets/Shaders/FSR3/shaders/fsr3upscaler/ffx_fsr3upscaler_depth_clip.h.meta
-
65Assets/Shaders/FSR3/shaders/fsr3upscaler/ffx_fsr3upscaler_lock.h.meta
-
65Assets/Shaders/FSR3/shaders/fsr3upscaler/ffx_fsr3upscaler_postprocess_lock_status.h.meta
-
65Assets/Shaders/FSR3/shaders/fsr3upscaler/ffx_fsr3upscaler_reconstruct_dilated_velocity_and_previous_depth.h.meta
-
67Assets/Shaders/FSR3/shaders/fsr3upscaler/fsr1/ffx_fsr1.h.meta
-
67Assets/Shaders/FSR3/shaders/fsr3upscaler/spd/ffx_spd.h.meta
-
2Packages/fidelityfx.fsr/Runtime.meta
-
8Packages/fidelityfx.fsr/Runtime/Common.meta
-
55Packages/fidelityfx.fsr/Runtime/Common/ResourceView.cs
-
11Packages/fidelityfx.fsr/Runtime/Common/ResourceView.cs.meta
-
8Packages/fidelityfx.fsr/Runtime/FSR2.meta
-
302Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2.cs
-
0Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2.cs.meta
-
41Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Assets.cs
-
0Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Assets.cs.meta
-
81Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Callbacks.cs
-
0Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Callbacks.cs.meta
-
618Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Context.cs
-
0Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Context.cs.meta
-
380Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Pass.cs
-
0Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Pass.cs.meta
-
38Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Resources.cs
-
0Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Resources.cs.meta
-
80Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2ShaderIDs.cs
-
0Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2ShaderIDs.cs.meta
-
2Packages/fidelityfx.fsr/Runtime/FSR3.meta
-
91Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3ShaderIDs.cs
-
3Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3ShaderIDs.cs.meta
-
70Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3Upscaler.cs
-
3Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3Upscaler.cs.meta
-
177Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerAssets.cs
-
11Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerAssets.cs.meta
-
4Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerCallbacks.cs
-
11Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerCallbacks.cs.meta
-
166Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerContext.cs
-
3Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerContext.cs.meta
-
254Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerPass.cs
-
3Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerPass.cs.meta
-
245Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerResources.cs
-
3Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerResources.cs.meta
-
14Packages/fidelityfx.fsr/Runtime/FidelityFX.FSR.asmdef
-
7Packages/fidelityfx.fsr/Runtime/FidelityFX.FSR.asmdef.meta
-
2Packages/fidelityfx.fsr/Shaders.meta
-
41Packages/fidelityfx.fsr/Shaders/ffx_fsr2_accumulate_pass.compute
-
8Packages/fidelityfx.fsr/Shaders/ffx_fsr2_accumulate_pass.compute.meta
-
14Packages/fidelityfx.fsr/Shaders/ffx_fsr2_autogen_reactive_pass.compute
-
8Packages/fidelityfx.fsr/Shaders/ffx_fsr2_autogen_reactive_pass.compute.meta
-
14Packages/fidelityfx.fsr/Shaders/ffx_fsr2_compute_luminance_pyramid_pass.compute
-
8Packages/fidelityfx.fsr/Shaders/ffx_fsr2_compute_luminance_pyramid_pass.compute.meta
-
32Packages/fidelityfx.fsr/Shaders/ffx_fsr2_depth_clip_pass.compute
-
8Packages/fidelityfx.fsr/Shaders/ffx_fsr2_depth_clip_pass.compute.meta
-
32Packages/fidelityfx.fsr/Shaders/ffx_fsr2_lock_pass.compute
-
8Packages/fidelityfx.fsr/Shaders/ffx_fsr2_lock_pass.compute.meta
-
31Packages/fidelityfx.fsr/Shaders/ffx_fsr2_rcas_pass.compute
-
8Packages/fidelityfx.fsr/Shaders/ffx_fsr2_rcas_pass.compute.meta
-
33Packages/fidelityfx.fsr/Shaders/ffx_fsr2_reconstruct_previous_depth_pass.compute
-
8Packages/fidelityfx.fsr/Shaders/ffx_fsr2_reconstruct_previous_depth_pass.compute.meta
-
32Packages/fidelityfx.fsr/Shaders/ffx_fsr2_tcr_autogen_pass.compute
-
8Packages/fidelityfx.fsr/Shaders/ffx_fsr2_tcr_autogen_pass.compute.meta
-
8Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_accumulate_pass.compute
-
0Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_accumulate_pass.compute.meta
-
9Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_autogen_reactive_pass.compute
-
0Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_autogen_reactive_pass.compute.meta
-
29Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_debug_view_pass.compute
-
8Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_debug_view_pass.compute.meta
-
29Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_luma_instability_pass.compute
-
0Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_luma_instability_pass.compute.meta
-
22Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_luma_pyramid_pass.compute
-
0Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_luma_pyramid_pass.compute.meta
-
9Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_prepare_inputs_pass.compute
-
0Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_prepare_inputs_pass.compute.meta
-
29Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_prepare_reactivity_pass.compute
-
0Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_prepare_reactivity_pass.compute.meta
-
10Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_rcas_pass.compute
-
0Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_rcas_pass.compute.meta
-
29Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_shading_change_pass.compute
-
8Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_shading_change_pass.compute.meta
-
32Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_shading_change_pyramid_pass.compute
-
8Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_shading_change_pyramid_pass.compute.meta
-
8Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_tcr_autogen_pass.compute
-
0Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_tcr_autogen_pass.compute.meta
-
60Packages/fidelityfx.fsr/Shaders/ffx_fsr_unity_common.cginc
-
0Packages/fidelityfx.fsr/Shaders/ffx_fsr_unity_common.cginc.meta
-
2Packages/fidelityfx.fsr/Shaders/shaders.meta
-
54Packages/fidelityfx.fsr/Shaders/shaders/ffx_common_types.h
-
11Packages/fidelityfx.fsr/Shaders/shaders/ffx_common_types.h.meta
-
14Packages/fidelityfx.fsr/Shaders/shaders/ffx_core.h
-
11Packages/fidelityfx.fsr/Shaders/shaders/ffx_core.h.meta
-
318Packages/fidelityfx.fsr/Shaders/shaders/ffx_core_gpu_common.h
-
11Packages/fidelityfx.fsr/Shaders/shaders/ffx_core_gpu_common.h.meta
@ -0,0 +1,26 @@ |
|||||
|
%YAML 1.1 |
||||
|
%TAG !u! tag:unity3d.com,2011: |
||||
|
--- !u!114 &11400000 |
||||
|
MonoBehaviour: |
||||
|
m_ObjectHideFlags: 0 |
||||
|
m_CorrespondingSourceObject: {fileID: 0} |
||||
|
m_PrefabInstance: {fileID: 0} |
||||
|
m_PrefabAsset: {fileID: 0} |
||||
|
m_GameObject: {fileID: 0} |
||||
|
m_Enabled: 1 |
||||
|
m_EditorHideFlags: 0 |
||||
|
m_Script: {fileID: 11500000, guid: 2dbcc608a4754d049a14a0bcce2eb40b, type: 3} |
||||
|
m_Name: FSR3 Upscaler Assets |
||||
|
m_EditorClassIdentifier: |
||||
|
shaders: |
||||
|
prepareInputsPass: {fileID: 7200000, guid: 4f59e5b9179d74844ae06a30ae1e0629, type: 3} |
||||
|
lumaPyramidPass: {fileID: 7200000, guid: d253be05abcdc80428503d3e4cce3a36, type: 3} |
||||
|
shadingChangePyramidPass: {fileID: 7200000, guid: 251e663738905fa4d8817001682d802f, type: 3} |
||||
|
shadingChangePass: {fileID: 7200000, guid: 9a2bff2f97619ed4989d9b0577ba0641, type: 3} |
||||
|
prepareReactivityPass: {fileID: 7200000, guid: 20e44016ed34b0d4b8de499d1b566c69, type: 3} |
||||
|
lumaInstabilityPass: {fileID: 7200000, guid: a135306e6d1857e43a86ef20db2a47fe, type: 3} |
||||
|
accumulatePass: {fileID: 7200000, guid: c9b45f0ae7673694ba57a4aadfe212e9, type: 3} |
||||
|
sharpenPass: {fileID: 7200000, guid: 7aaf5cfff022de2499e9b0412f947f6c, type: 3} |
||||
|
autoGenReactivePass: {fileID: 7200000, guid: 5716b91fdaa4e9e439df6b96a796fe6e, type: 3} |
||||
|
tcrAutoGenPass: {fileID: 7200000, guid: 75cdc6ef23f08ed498d4da511923fcea, type: 3} |
||||
|
debugViewPass: {fileID: 7200000, guid: cb24a71d54164c54eb5e86839acd48c5, type: 3} |
||||
@ -1,23 +0,0 @@ |
|||||
%YAML 1.1 |
|
||||
%TAG !u! tag:unity3d.com,2011: |
|
||||
--- !u!114 &11400000 |
|
||||
MonoBehaviour: |
|
||||
m_ObjectHideFlags: 0 |
|
||||
m_CorrespondingSourceObject: {fileID: 0} |
|
||||
m_PrefabInstance: {fileID: 0} |
|
||||
m_PrefabAsset: {fileID: 0} |
|
||||
m_GameObject: {fileID: 0} |
|
||||
m_Enabled: 1 |
|
||||
m_EditorHideFlags: 0 |
|
||||
m_Script: {fileID: 11500000, guid: db26e15a33db6ab42a38daab0ba2712f, type: 3} |
|
||||
m_Name: Fsr3UpscalerAssets |
|
||||
m_EditorClassIdentifier: |
|
||||
shaders: |
|
||||
computeLuminancePyramidPass: {fileID: 7200000, guid: d253be05abcdc80428503d3e4cce3a36, type: 3} |
|
||||
reconstructPreviousDepthPass: {fileID: 7200000, guid: 4f59e5b9179d74844ae06a30ae1e0629, type: 3} |
|
||||
depthClipPass: {fileID: 7200000, guid: 20e44016ed34b0d4b8de499d1b566c69, type: 3} |
|
||||
lockPass: {fileID: 7200000, guid: a135306e6d1857e43a86ef20db2a47fe, type: 3} |
|
||||
accumulatePass: {fileID: 7200000, guid: c9b45f0ae7673694ba57a4aadfe212e9, type: 3} |
|
||||
sharpenPass: {fileID: 7200000, guid: 7aaf5cfff022de2499e9b0412f947f6c, type: 3} |
|
||||
autoGenReactivePass: {fileID: 7200000, guid: 5716b91fdaa4e9e439df6b96a796fe6e, type: 3} |
|
||||
tcrAutoGenPass: {fileID: 7200000, guid: 75cdc6ef23f08ed498d4da511923fcea, type: 3} |
|
||||
@ -1,80 +0,0 @@ |
|||||
// Copyright (c) 2023 Nico de Poel
|
|
||||
//
|
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
|
||||
// in the Software without restriction, including without limitation the rights
|
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
|
||||
// furnished to do so, subject to the following conditions:
|
|
||||
//
|
|
||||
// The above copyright notice and this permission notice shall be included in all
|
|
||||
// copies or substantial portions of the Software.
|
|
||||
//
|
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||
// THE SOFTWARE.
|
|
||||
|
|
||||
using UnityEngine; |
|
||||
|
|
||||
namespace FidelityFX |
|
||||
{ |
|
||||
internal static class Fsr3ShaderIDs |
|
||||
{ |
|
||||
// Shader resource views, i.e. read-only bindings
|
|
||||
internal static readonly int SrvInputColor = Shader.PropertyToID("r_input_color_jittered"); |
|
||||
internal static readonly int SrvOpaqueOnly = Shader.PropertyToID("r_input_opaque_only"); |
|
||||
internal static readonly int SrvInputMotionVectors = Shader.PropertyToID("r_input_motion_vectors"); |
|
||||
internal static readonly int SrvInputDepth = Shader.PropertyToID("r_input_depth"); |
|
||||
internal static readonly int SrvInputExposure = Shader.PropertyToID("r_input_exposure"); |
|
||||
internal static readonly int SrvAutoExposure = Shader.PropertyToID("r_auto_exposure"); |
|
||||
internal static readonly int SrvReactiveMask = Shader.PropertyToID("r_reactive_mask"); |
|
||||
internal static readonly int SrvTransparencyAndCompositionMask = Shader.PropertyToID("r_transparency_and_composition_mask"); |
|
||||
internal static readonly int SrvReconstructedPrevNearestDepth = Shader.PropertyToID("r_reconstructed_previous_nearest_depth"); |
|
||||
internal static readonly int SrvDilatedMotionVectors = Shader.PropertyToID("r_dilated_motion_vectors"); |
|
||||
internal static readonly int SrvPrevDilatedMotionVectors = Shader.PropertyToID("r_previous_dilated_motion_vectors"); |
|
||||
internal static readonly int SrvDilatedDepth = Shader.PropertyToID("r_dilated_depth"); |
|
||||
internal static readonly int SrvInternalUpscaled = Shader.PropertyToID("r_internal_upscaled_color"); |
|
||||
internal static readonly int SrvLockStatus = Shader.PropertyToID("r_lock_status"); |
|
||||
internal static readonly int SrvLockInputLuma = Shader.PropertyToID("r_lock_input_luma"); |
|
||||
internal static readonly int SrvPreparedInputColor = Shader.PropertyToID("r_prepared_input_color"); |
|
||||
internal static readonly int SrvLumaHistory = Shader.PropertyToID("r_luma_history"); |
|
||||
internal static readonly int SrvRcasInput = Shader.PropertyToID("r_rcas_input"); |
|
||||
internal static readonly int SrvLanczosLut = Shader.PropertyToID("r_lanczos_lut"); |
|
||||
internal static readonly int SrvSceneLuminanceMips = Shader.PropertyToID("r_imgMips"); |
|
||||
internal static readonly int SrvUpscaleMaximumBiasLut = Shader.PropertyToID("r_upsample_maximum_bias_lut"); |
|
||||
internal static readonly int SrvDilatedReactiveMasks = Shader.PropertyToID("r_dilated_reactive_masks"); |
|
||||
internal static readonly int SrvPrevColorPreAlpha = Shader.PropertyToID("r_input_prev_color_pre_alpha"); |
|
||||
internal static readonly int SrvPrevColorPostAlpha = Shader.PropertyToID("r_input_prev_color_post_alpha"); |
|
||||
|
|
||||
// Unordered access views, i.e. random read/write bindings
|
|
||||
internal static readonly int UavReconstructedPrevNearestDepth = Shader.PropertyToID("rw_reconstructed_previous_nearest_depth"); |
|
||||
internal static readonly int UavDilatedMotionVectors = Shader.PropertyToID("rw_dilated_motion_vectors"); |
|
||||
internal static readonly int UavDilatedDepth = Shader.PropertyToID("rw_dilated_depth"); |
|
||||
internal static readonly int UavInternalUpscaled = Shader.PropertyToID("rw_internal_upscaled_color"); |
|
||||
internal static readonly int UavLockStatus = Shader.PropertyToID("rw_lock_status"); |
|
||||
internal static readonly int UavLockInputLuma = Shader.PropertyToID("rw_lock_input_luma"); |
|
||||
internal static readonly int UavNewLocks = Shader.PropertyToID("rw_new_locks"); |
|
||||
internal static readonly int UavPreparedInputColor = Shader.PropertyToID("rw_prepared_input_color"); |
|
||||
internal static readonly int UavLumaHistory = Shader.PropertyToID("rw_luma_history"); |
|
||||
internal static readonly int UavUpscaledOutput = Shader.PropertyToID("rw_upscaled_output"); |
|
||||
internal static readonly int UavExposureMipLumaChange = Shader.PropertyToID("rw_img_mip_shading_change"); |
|
||||
internal static readonly int UavExposureMip5 = Shader.PropertyToID("rw_img_mip_5"); |
|
||||
internal static readonly int UavDilatedReactiveMasks = Shader.PropertyToID("rw_dilated_reactive_masks"); |
|
||||
internal static readonly int UavAutoExposure = Shader.PropertyToID("rw_auto_exposure"); |
|
||||
internal static readonly int UavSpdAtomicCount = Shader.PropertyToID("rw_spd_global_atomic"); |
|
||||
internal static readonly int UavAutoReactive = Shader.PropertyToID("rw_output_autoreactive"); |
|
||||
internal static readonly int UavAutoComposition = Shader.PropertyToID("rw_output_autocomposition"); |
|
||||
internal static readonly int UavPrevColorPreAlpha = Shader.PropertyToID("rw_output_prev_color_pre_alpha"); |
|
||||
internal static readonly int UavPrevColorPostAlpha = Shader.PropertyToID("rw_output_prev_color_post_alpha"); |
|
||||
|
|
||||
// Constant buffer bindings
|
|
||||
internal static readonly int CbFsr3Upscaler = Shader.PropertyToID("cbFSR3Upscaler"); |
|
||||
internal static readonly int CbSpd = Shader.PropertyToID("cbSPD"); |
|
||||
internal static readonly int CbRcas = Shader.PropertyToID("cbRCAS"); |
|
||||
internal static readonly int CbGenReactive = Shader.PropertyToID("cbGenerateReactive"); |
|
||||
} |
|
||||
} |
|
||||
@ -1,7 +0,0 @@ |
|||||
fileFormatVersion: 2 |
|
||||
guid: da435b71cf57e2247b80ae0f0f86d1f8 |
|
||||
ShaderIncludeImporter: |
|
||||
externalObjects: {} |
|
||||
userData: |
|
||||
assetBundleName: |
|
||||
assetBundleVariant: |
|
||||
@ -1,7 +0,0 @@ |
|||||
fileFormatVersion: 2 |
|
||||
guid: 98d2cbbda5e90dd4ebd1d70abbb63a09 |
|
||||
ShaderIncludeImporter: |
|
||||
externalObjects: {} |
|
||||
userData: |
|
||||
assetBundleName: |
|
||||
assetBundleVariant: |
|
||||
@ -1,7 +0,0 @@ |
|||||
fileFormatVersion: 2 |
|
||||
guid: bafb3726a76b97a49bb343d8a4323754 |
|
||||
ShaderIncludeImporter: |
|
||||
externalObjects: {} |
|
||||
userData: |
|
||||
assetBundleName: |
|
||||
assetBundleVariant: |
|
||||
@ -1,338 +0,0 @@ |
|||||
// This file is part of the FidelityFX SDK. |
|
||||
// |
|
||||
// Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved. |
|
||||
// |
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy |
|
||||
// of this software and associated documentation files (the "Software"), to deal |
|
||||
// in the Software without restriction, including without limitation the rights |
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
||||
// copies of the Software, and to permit persons to whom the Software is |
|
||||
// furnished to do so, subject to the following conditions: |
|
||||
// The above copyright notice and this permission notice shall be included in |
|
||||
// all copies or substantial portions of the Software. |
|
||||
// |
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
||||
// THE SOFTWARE. |
|
||||
|
|
||||
|
|
||||
/// A define for a true value in a boolean expression. |
|
||||
/// |
|
||||
/// @ingroup CPUTypes |
|
||||
#define FFX_TRUE (1) |
|
||||
|
|
||||
/// A define for a false value in a boolean expression. |
|
||||
/// |
|
||||
/// @ingroup CPUTypes |
|
||||
#define FFX_FALSE (0) |
|
||||
|
|
||||
#if !defined(FFX_STATIC) |
|
||||
/// A define to abstract declaration of static variables and functions. |
|
||||
/// |
|
||||
/// @ingroup CPUTypes |
|
||||
#define FFX_STATIC static |
|
||||
#endif // #if !defined(FFX_STATIC) |
|
||||
|
|
||||
/// @defgroup CPUCore CPU Core |
|
||||
/// Core CPU-side defines and functions |
|
||||
/// |
|
||||
/// @ingroup ffxHost |
|
||||
|
|
||||
#ifdef __clang__ |
|
||||
#pragma clang diagnostic ignored "-Wunused-variable" |
|
||||
#endif |
|
||||
|
|
||||
/// Interpret the bit layout of an IEEE-754 floating point value as an unsigned integer. |
|
||||
/// |
|
||||
/// @param [in] x A 32bit floating value. |
|
||||
/// |
|
||||
/// @returns |
|
||||
/// An unsigned 32bit integer value containing the bit pattern of <c><i>x</i></c>. |
|
||||
/// |
|
||||
/// @ingroup CPUCore |
|
||||
FFX_STATIC FfxUInt32 ffxAsUInt32(FfxFloat32 x) |
|
||||
{ |
|
||||
union |
|
||||
{ |
|
||||
FfxFloat32 f; |
|
||||
FfxUInt32 u; |
|
||||
} bits; |
|
||||
|
|
||||
bits.f = x; |
|
||||
return bits.u; |
|
||||
} |
|
||||
|
|
||||
FFX_STATIC FfxFloat32 ffxDot2(FfxFloat32x2 a, FfxFloat32x2 b) |
|
||||
{ |
|
||||
return a[0] * b[0] + a[1] * b[1]; |
|
||||
} |
|
||||
|
|
||||
FFX_STATIC FfxFloat32 ffxDot3(FfxFloat32x3 a, FfxFloat32x3 b) |
|
||||
{ |
|
||||
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; |
|
||||
} |
|
||||
|
|
||||
FFX_STATIC FfxFloat32 ffxDot4(FfxFloat32x4 a, FfxFloat32x4 b) |
|
||||
{ |
|
||||
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; |
|
||||
} |
|
||||
|
|
||||
/// Compute the linear interopation between two values. |
|
||||
/// |
|
||||
/// Implemented by calling the GLSL <c><i>mix</i></c> instrinsic function. Implements the |
|
||||
/// following math: |
|
||||
/// |
|
||||
/// (1 - t) * x + t * y |
|
||||
/// |
|
||||
/// @param [in] x The first value to lerp between. |
|
||||
/// @param [in] y The second value to lerp between. |
|
||||
/// @param [in] t The value to determine how much of <c><i>x</i></c> and how much of <c><i>y</i></c>. |
|
||||
/// |
|
||||
/// @returns |
|
||||
/// A linearly interpolated value between <c><i>x</i></c> and <c><i>y</i></c> according to <c><i>t</i></c>. |
|
||||
/// |
|
||||
/// @ingroup CPUCore |
|
||||
FFX_STATIC FfxFloat32 ffxLerp(FfxFloat32 x, FfxFloat32 y, FfxFloat32 t) |
|
||||
{ |
|
||||
return y * t + (-x * t + x); |
|
||||
} |
|
||||
|
|
||||
/// Compute the reciprocal of a value. |
|
||||
/// |
|
||||
/// @param [in] x The value to compute the reciprocal for. |
|
||||
/// |
|
||||
/// @returns |
|
||||
/// The reciprocal value of <c><i>x</i></c>. |
|
||||
/// |
|
||||
/// @ingroup CPUCore |
|
||||
FFX_STATIC FfxFloat32 ffxReciprocal(FfxFloat32 x) |
|
||||
{ |
|
||||
return 1.0f / x; |
|
||||
} |
|
||||
|
|
||||
/// Compute the square root of a value. |
|
||||
/// |
|
||||
/// @param [in] x The first value to compute the min of. |
|
||||
/// |
|
||||
/// @returns |
|
||||
/// The the square root of <c><i>x</i></c>. |
|
||||
/// |
|
||||
/// @ingroup CPUCore |
|
||||
FFX_STATIC FfxFloat32 ffxSqrt(FfxFloat32 x) |
|
||||
{ |
|
||||
return sqrt(x); |
|
||||
} |
|
||||
|
|
||||
FFX_STATIC FfxUInt32 AShrSU1(FfxUInt32 a, FfxUInt32 b) |
|
||||
{ |
|
||||
return FfxUInt32(FfxInt32(a) >> FfxInt32(b)); |
|
||||
} |
|
||||
|
|
||||
/// Compute the factional part of a decimal value. |
|
||||
/// |
|
||||
/// This function calculates <c><i>x - floor(x)</i></c>. |
|
||||
/// |
|
||||
/// @param [in] x The value to compute the fractional part from. |
|
||||
/// |
|
||||
/// @returns |
|
||||
/// The fractional part of <c><i>x</i></c>. |
|
||||
/// |
|
||||
/// @ingroup CPUCore |
|
||||
FFX_STATIC FfxFloat32 ffxFract(FfxFloat32 x) |
|
||||
{ |
|
||||
return x - floor(x); |
|
||||
} |
|
||||
|
|
||||
/// Compute the reciprocal square root of a value. |
|
||||
/// |
|
||||
/// @param [in] x The value to compute the reciprocal for. |
|
||||
/// |
|
||||
/// @returns |
|
||||
/// The reciprocal square root value of <c><i>x</i></c>. |
|
||||
/// |
|
||||
/// @ingroup CPUCore |
|
||||
FFX_STATIC FfxFloat32 rsqrt(FfxFloat32 x) |
|
||||
{ |
|
||||
return ffxReciprocal(ffxSqrt(x)); |
|
||||
} |
|
||||
|
|
||||
FFX_STATIC FfxFloat32 ffxMin(FfxFloat32 x, FfxFloat32 y) |
|
||||
{ |
|
||||
return x < y ? x : y; |
|
||||
} |
|
||||
|
|
||||
FFX_STATIC FfxUInt32 ffxMin(FfxUInt32 x, FfxUInt32 y) |
|
||||
{ |
|
||||
return x < y ? x : y; |
|
||||
} |
|
||||
|
|
||||
FFX_STATIC FfxFloat32 ffxMax(FfxFloat32 x, FfxFloat32 y) |
|
||||
{ |
|
||||
return x > y ? x : y; |
|
||||
} |
|
||||
|
|
||||
FFX_STATIC FfxUInt32 ffxMax(FfxUInt32 x, FfxUInt32 y) |
|
||||
{ |
|
||||
return x > y ? x : y; |
|
||||
} |
|
||||
|
|
||||
/// Clamp a value to a [0..1] range. |
|
||||
/// |
|
||||
/// @param [in] x The value to clamp to [0..1] range. |
|
||||
/// |
|
||||
/// @returns |
|
||||
/// The clamped version of <c><i>x</i></c>. |
|
||||
/// |
|
||||
/// @ingroup CPUCore |
|
||||
FFX_STATIC FfxFloat32 ffxSaturate(FfxFloat32 x) |
|
||||
{ |
|
||||
return ffxMin(1.0f, ffxMax(0.0f, x)); |
|
||||
} |
|
||||
|
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
||||
|
|
||||
FFX_STATIC void opAAddOneF3(FfxFloat32x3 d, FfxFloat32x3 a, FfxFloat32 b) |
|
||||
{ |
|
||||
d[0] = a[0] + b; |
|
||||
d[1] = a[1] + b; |
|
||||
d[2] = a[2] + b; |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
FFX_STATIC void opACpyF3(FfxFloat32x3 d, FfxFloat32x3 a) |
|
||||
{ |
|
||||
d[0] = a[0]; |
|
||||
d[1] = a[1]; |
|
||||
d[2] = a[2]; |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
FFX_STATIC void opAMulF3(FfxFloat32x3 d, FfxFloat32x3 a, FfxFloat32x3 b) |
|
||||
{ |
|
||||
d[0] = a[0] * b[0]; |
|
||||
d[1] = a[1] * b[1]; |
|
||||
d[2] = a[2] * b[2]; |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
FFX_STATIC void opAMulOneF3(FfxFloat32x3 d, FfxFloat32x3 a, FfxFloat32 b) |
|
||||
{ |
|
||||
d[0] = a[0] * b; |
|
||||
d[1] = a[1] * b; |
|
||||
d[2] = a[2] * b; |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
FFX_STATIC void opARcpF3(FfxFloat32x3 d, FfxFloat32x3 a) |
|
||||
{ |
|
||||
d[0] = ffxReciprocal(a[0]); |
|
||||
d[1] = ffxReciprocal(a[1]); |
|
||||
d[2] = ffxReciprocal(a[2]); |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
/// Convert FfxFloat32 to half (in lower 16-bits of output). |
|
||||
/// |
|
||||
/// This function implements the same fast technique that is documented here: ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf |
|
||||
/// |
|
||||
/// The function supports denormals. |
|
||||
/// |
|
||||
/// Some conversion rules are to make computations possibly "safer" on the GPU, |
|
||||
/// -INF & -NaN -> -65504 |
|
||||
/// +INF & +NaN -> +65504 |
|
||||
/// |
|
||||
/// @param [in] f The 32bit floating point value to convert. |
|
||||
/// |
|
||||
/// @returns |
|
||||
/// The closest 16bit floating point value to <c><i>f</i></c>. |
|
||||
/// |
|
||||
/// @ingroup CPUCore |
|
||||
FFX_STATIC FfxUInt32 f32tof16(FfxFloat32 f) |
|
||||
{ |
|
||||
static FfxUInt16 base[512] = { |
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400, |
|
||||
0x0800, 0x0c00, 0x1000, 0x1400, 0x1800, 0x1c00, 0x2000, 0x2400, 0x2800, 0x2c00, 0x3000, 0x3400, 0x3800, 0x3c00, 0x4000, 0x4400, 0x4800, 0x4c00, 0x5000, |
|
||||
0x5400, 0x5800, 0x5c00, 0x6000, 0x6400, 0x6800, 0x6c00, 0x7000, 0x7400, 0x7800, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, |
|
||||
0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, |
|
||||
0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, |
|
||||
0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, |
|
||||
0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, |
|
||||
0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, |
|
||||
0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, |
|
||||
0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, |
|
||||
0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, |
|
||||
0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, |
|
||||
0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, |
|
||||
0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8001, 0x8002, |
|
||||
0x8004, 0x8008, 0x8010, 0x8020, 0x8040, 0x8080, 0x8100, 0x8200, 0x8400, 0x8800, 0x8c00, 0x9000, 0x9400, 0x9800, 0x9c00, 0xa000, 0xa400, 0xa800, 0xac00, |
|
||||
0xb000, 0xb400, 0xb800, 0xbc00, 0xc000, 0xc400, 0xc800, 0xcc00, 0xd000, 0xd400, 0xd800, 0xdc00, 0xe000, 0xe400, 0xe800, 0xec00, 0xf000, 0xf400, 0xf800, |
|
||||
0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, |
|
||||
0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, |
|
||||
0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, |
|
||||
0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, |
|
||||
0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, |
|
||||
0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff |
|
||||
}; |
|
||||
|
|
||||
static FfxUInt8 shift[512] = { |
|
||||
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, |
|
||||
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, |
|
||||
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, |
|
||||
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, |
|
||||
0x18, 0x18, 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x0f, 0x0e, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, |
|
||||
0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, |
|
||||
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, |
|
||||
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, |
|
||||
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, |
|
||||
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, |
|
||||
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, |
|
||||
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, |
|
||||
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, |
|
||||
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, |
|
||||
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x0f, 0x0e, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, |
|
||||
0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x18, |
|
||||
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, |
|
||||
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, |
|
||||
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, |
|
||||
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, |
|
||||
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18 |
|
||||
}; |
|
||||
|
|
||||
union |
|
||||
{ |
|
||||
FfxFloat32 f; |
|
||||
FfxUInt32 u; |
|
||||
} bits; |
|
||||
|
|
||||
bits.f = f; |
|
||||
FfxUInt32 u = bits.u; |
|
||||
FfxUInt32 i = u >> 23; |
|
||||
return (FfxUInt32)(base[i]) + ((u & 0x7fffff) >> shift[i]); |
|
||||
} |
|
||||
|
|
||||
/// Pack 2x32-bit floating point values in a single 32bit value. |
|
||||
/// |
|
||||
/// This function first converts each component of <c><i>value</i></c> into their nearest 16-bit floating |
|
||||
/// point representation, and then stores the X and Y components in the lower and upper 16 bits of the |
|
||||
/// 32bit unsigned integer respectively. |
|
||||
/// |
|
||||
/// @param [in] x A 2-dimensional floating point value to convert and pack. |
|
||||
/// |
|
||||
/// @returns |
|
||||
/// A packed 32bit value containing 2 16bit floating point values. |
|
||||
/// |
|
||||
/// @ingroup CPUCore |
|
||||
FFX_STATIC FfxUInt32 packHalf2x16(FfxFloat32x2 x) |
|
||||
{ |
|
||||
return f32tof16(x[0]) + (f32tof16(x[1]) << 16); |
|
||||
} |
|
||||
@ -1,65 +0,0 @@ |
|||||
fileFormatVersion: 2 |
|
||||
guid: 61bd10363d44ee2478461c9e9efbcb67 |
|
||||
PluginImporter: |
|
||||
externalObjects: {} |
|
||||
serializedVersion: 2 |
|
||||
iconMap: {} |
|
||||
executionOrder: {} |
|
||||
defineConstraints: [] |
|
||||
isPreloaded: 0 |
|
||||
isOverridable: 0 |
|
||||
isExplicitlyReferenced: 0 |
|
||||
validateReferences: 1 |
|
||||
platformData: |
|
||||
- first: |
|
||||
: Any |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
Exclude Editor: 1 |
|
||||
Exclude GameCoreScarlett: 1 |
|
||||
Exclude GameCoreXboxOne: 1 |
|
||||
Exclude Linux64: 1 |
|
||||
Exclude OSXUniversal: 1 |
|
||||
Exclude PS4: 1 |
|
||||
Exclude PS5: 1 |
|
||||
Exclude Win: 1 |
|
||||
Exclude Win64: 1 |
|
||||
- first: |
|
||||
Any: |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: {} |
|
||||
- first: |
|
||||
Editor: Editor |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
DefaultValueInitialized: true |
|
||||
- first: |
|
||||
Standalone: Linux64 |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
- first: |
|
||||
Standalone: OSXUniversal |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
- first: |
|
||||
Standalone: Win |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
- first: |
|
||||
Standalone: Win64 |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
userData: |
|
||||
assetBundleName: |
|
||||
assetBundleVariant: |
|
||||
@ -1,65 +0,0 @@ |
|||||
fileFormatVersion: 2 |
|
||||
guid: 7c662249d70c4434da4f2da00e432c38 |
|
||||
PluginImporter: |
|
||||
externalObjects: {} |
|
||||
serializedVersion: 2 |
|
||||
iconMap: {} |
|
||||
executionOrder: {} |
|
||||
defineConstraints: [] |
|
||||
isPreloaded: 0 |
|
||||
isOverridable: 0 |
|
||||
isExplicitlyReferenced: 0 |
|
||||
validateReferences: 1 |
|
||||
platformData: |
|
||||
- first: |
|
||||
: Any |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
Exclude Editor: 1 |
|
||||
Exclude GameCoreScarlett: 1 |
|
||||
Exclude GameCoreXboxOne: 1 |
|
||||
Exclude Linux64: 1 |
|
||||
Exclude OSXUniversal: 1 |
|
||||
Exclude PS4: 1 |
|
||||
Exclude PS5: 1 |
|
||||
Exclude Win: 1 |
|
||||
Exclude Win64: 1 |
|
||||
- first: |
|
||||
Any: |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: {} |
|
||||
- first: |
|
||||
Editor: Editor |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
DefaultValueInitialized: true |
|
||||
- first: |
|
||||
Standalone: Linux64 |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
- first: |
|
||||
Standalone: OSXUniversal |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
- first: |
|
||||
Standalone: Win |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
- first: |
|
||||
Standalone: Win64 |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
userData: |
|
||||
assetBundleName: |
|
||||
assetBundleVariant: |
|
||||
@ -1,65 +0,0 @@ |
|||||
fileFormatVersion: 2 |
|
||||
guid: c7e9f53dd040b2645af5ccd936a94b0e |
|
||||
PluginImporter: |
|
||||
externalObjects: {} |
|
||||
serializedVersion: 2 |
|
||||
iconMap: {} |
|
||||
executionOrder: {} |
|
||||
defineConstraints: [] |
|
||||
isPreloaded: 0 |
|
||||
isOverridable: 0 |
|
||||
isExplicitlyReferenced: 0 |
|
||||
validateReferences: 1 |
|
||||
platformData: |
|
||||
- first: |
|
||||
: Any |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
Exclude Editor: 1 |
|
||||
Exclude GameCoreScarlett: 1 |
|
||||
Exclude GameCoreXboxOne: 1 |
|
||||
Exclude Linux64: 1 |
|
||||
Exclude OSXUniversal: 1 |
|
||||
Exclude PS4: 1 |
|
||||
Exclude PS5: 1 |
|
||||
Exclude Win: 1 |
|
||||
Exclude Win64: 1 |
|
||||
- first: |
|
||||
Any: |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: {} |
|
||||
- first: |
|
||||
Editor: Editor |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
DefaultValueInitialized: true |
|
||||
- first: |
|
||||
Standalone: Linux64 |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
- first: |
|
||||
Standalone: OSXUniversal |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
- first: |
|
||||
Standalone: Win |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
- first: |
|
||||
Standalone: Win64 |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
userData: |
|
||||
assetBundleName: |
|
||||
assetBundleVariant: |
|
||||
@ -1,65 +0,0 @@ |
|||||
fileFormatVersion: 2 |
|
||||
guid: 67a8b72ceb93d634f883b086fdccb348 |
|
||||
PluginImporter: |
|
||||
externalObjects: {} |
|
||||
serializedVersion: 2 |
|
||||
iconMap: {} |
|
||||
executionOrder: {} |
|
||||
defineConstraints: [] |
|
||||
isPreloaded: 0 |
|
||||
isOverridable: 0 |
|
||||
isExplicitlyReferenced: 0 |
|
||||
validateReferences: 1 |
|
||||
platformData: |
|
||||
- first: |
|
||||
: Any |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
Exclude Editor: 1 |
|
||||
Exclude GameCoreScarlett: 1 |
|
||||
Exclude GameCoreXboxOne: 1 |
|
||||
Exclude Linux64: 1 |
|
||||
Exclude OSXUniversal: 1 |
|
||||
Exclude PS4: 1 |
|
||||
Exclude PS5: 1 |
|
||||
Exclude Win: 1 |
|
||||
Exclude Win64: 1 |
|
||||
- first: |
|
||||
Any: |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: {} |
|
||||
- first: |
|
||||
Editor: Editor |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
DefaultValueInitialized: true |
|
||||
- first: |
|
||||
Standalone: Linux64 |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
- first: |
|
||||
Standalone: OSXUniversal |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
- first: |
|
||||
Standalone: Win |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
- first: |
|
||||
Standalone: Win64 |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
userData: |
|
||||
assetBundleName: |
|
||||
assetBundleVariant: |
|
||||
@ -1,65 +0,0 @@ |
|||||
fileFormatVersion: 2 |
|
||||
guid: c8b3854bad30a8b40babc5a9805f294e |
|
||||
PluginImporter: |
|
||||
externalObjects: {} |
|
||||
serializedVersion: 2 |
|
||||
iconMap: {} |
|
||||
executionOrder: {} |
|
||||
defineConstraints: [] |
|
||||
isPreloaded: 0 |
|
||||
isOverridable: 0 |
|
||||
isExplicitlyReferenced: 0 |
|
||||
validateReferences: 1 |
|
||||
platformData: |
|
||||
- first: |
|
||||
: Any |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
Exclude Editor: 1 |
|
||||
Exclude GameCoreScarlett: 1 |
|
||||
Exclude GameCoreXboxOne: 1 |
|
||||
Exclude Linux64: 1 |
|
||||
Exclude OSXUniversal: 1 |
|
||||
Exclude PS4: 1 |
|
||||
Exclude PS5: 1 |
|
||||
Exclude Win: 1 |
|
||||
Exclude Win64: 1 |
|
||||
- first: |
|
||||
Any: |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: {} |
|
||||
- first: |
|
||||
Editor: Editor |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
DefaultValueInitialized: true |
|
||||
- first: |
|
||||
Standalone: Linux64 |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
- first: |
|
||||
Standalone: OSXUniversal |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
- first: |
|
||||
Standalone: Win |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
- first: |
|
||||
Standalone: Win64 |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
userData: |
|
||||
assetBundleName: |
|
||||
assetBundleVariant: |
|
||||
@ -1,67 +0,0 @@ |
|||||
fileFormatVersion: 2 |
|
||||
guid: 628e23510f46ef44bbf0035ce9a63be0 |
|
||||
PluginImporter: |
|
||||
externalObjects: {} |
|
||||
serializedVersion: 2 |
|
||||
iconMap: {} |
|
||||
executionOrder: {} |
|
||||
defineConstraints: [] |
|
||||
isPreloaded: 0 |
|
||||
isOverridable: 0 |
|
||||
isExplicitlyReferenced: 0 |
|
||||
validateReferences: 1 |
|
||||
platformData: |
|
||||
- first: |
|
||||
: Any |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
Exclude Editor: 1 |
|
||||
Exclude GameCoreScarlett: 1 |
|
||||
Exclude GameCoreXboxOne: 1 |
|
||||
Exclude Linux64: 1 |
|
||||
Exclude OSXUniversal: 1 |
|
||||
Exclude PS4: 1 |
|
||||
Exclude PS5: 1 |
|
||||
Exclude Win: 1 |
|
||||
Exclude Win64: 1 |
|
||||
- first: |
|
||||
Any: |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: {} |
|
||||
- first: |
|
||||
Editor: Editor |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: AnyCPU |
|
||||
DefaultValueInitialized: true |
|
||||
OS: AnyOS |
|
||||
- first: |
|
||||
Standalone: Linux64 |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
- first: |
|
||||
Standalone: OSXUniversal |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
- first: |
|
||||
Standalone: Win |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
- first: |
|
||||
Standalone: Win64 |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
userData: |
|
||||
assetBundleName: |
|
||||
assetBundleVariant: |
|
||||
@ -1,67 +0,0 @@ |
|||||
fileFormatVersion: 2 |
|
||||
guid: face65176ee3b82498bd0b8fed0ddacd |
|
||||
PluginImporter: |
|
||||
externalObjects: {} |
|
||||
serializedVersion: 2 |
|
||||
iconMap: {} |
|
||||
executionOrder: {} |
|
||||
defineConstraints: [] |
|
||||
isPreloaded: 0 |
|
||||
isOverridable: 0 |
|
||||
isExplicitlyReferenced: 0 |
|
||||
validateReferences: 1 |
|
||||
platformData: |
|
||||
- first: |
|
||||
: Any |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
Exclude Editor: 1 |
|
||||
Exclude GameCoreScarlett: 1 |
|
||||
Exclude GameCoreXboxOne: 1 |
|
||||
Exclude Linux64: 1 |
|
||||
Exclude OSXUniversal: 1 |
|
||||
Exclude PS4: 1 |
|
||||
Exclude PS5: 1 |
|
||||
Exclude Win: 1 |
|
||||
Exclude Win64: 1 |
|
||||
- first: |
|
||||
Any: |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: {} |
|
||||
- first: |
|
||||
Editor: Editor |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: AnyCPU |
|
||||
DefaultValueInitialized: true |
|
||||
OS: AnyOS |
|
||||
- first: |
|
||||
Standalone: Linux64 |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
- first: |
|
||||
Standalone: OSXUniversal |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
- first: |
|
||||
Standalone: Win |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
- first: |
|
||||
Standalone: Win64 |
|
||||
second: |
|
||||
enabled: 0 |
|
||||
settings: |
|
||||
CPU: None |
|
||||
userData: |
|
||||
assetBundleName: |
|
||||
assetBundleVariant: |
|
||||
@ -1,5 +1,5 @@ |
|||||
fileFormatVersion: 2 |
fileFormatVersion: 2 |
||||
guid: 975411b519480574290d74d7e34d119d |
|
||||
|
guid: b64c5aa2a705139438e2bcc551a02b97 |
||||
folderAsset: yes |
folderAsset: yes |
||||
DefaultImporter: |
DefaultImporter: |
||||
externalObjects: {} |
externalObjects: {} |
||||
@ -0,0 +1,8 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: e87a0efd0d1d4644abdef16b5a28bd0f |
||||
|
folderAsset: yes |
||||
|
DefaultImporter: |
||||
|
externalObjects: {} |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
@ -0,0 +1,55 @@ |
|||||
|
// Copyright (c) 2024 Nico de Poel
|
||||
|
//
|
||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
// in the Software without restriction, including without limitation the rights
|
||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||
|
// furnished to do so, subject to the following conditions:
|
||||
|
//
|
||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||
|
// copies or substantial portions of the Software.
|
||||
|
//
|
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
|
// THE SOFTWARE.
|
||||
|
|
||||
|
using UnityEngine.Rendering; |
||||
|
|
||||
|
namespace FidelityFX |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// An immutable structure wrapping all of the necessary information to bind a specific buffer or attachment of a render target to a compute shader.
|
||||
|
/// </summary>
|
||||
|
public readonly struct ResourceView |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// This value is the equivalent of not setting any value at all; all struct fields will have their default values.
|
||||
|
/// It does not refer to a valid texture, therefore any variable set to this value should be checked for IsValid and reassigned before being bound to a shader.
|
||||
|
/// </summary>
|
||||
|
public static readonly ResourceView Unassigned = new ResourceView(default); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// This value contains a valid texture reference that can be bound to a shader, however it is just an empty placeholder texture.
|
||||
|
/// Binding this to a shader can be seen as setting the texture variable inside the shader to null.
|
||||
|
/// </summary>
|
||||
|
public static readonly ResourceView None = new ResourceView(BuiltinRenderTextureType.None); |
||||
|
|
||||
|
public ResourceView(in RenderTargetIdentifier renderTarget, RenderTextureSubElement subElement = RenderTextureSubElement.Default, int mipLevel = 0) |
||||
|
{ |
||||
|
RenderTarget = renderTarget; |
||||
|
SubElement = subElement; |
||||
|
MipLevel = mipLevel; |
||||
|
} |
||||
|
|
||||
|
public bool IsValid => !RenderTarget.Equals(default); |
||||
|
|
||||
|
public readonly RenderTargetIdentifier RenderTarget; |
||||
|
public readonly RenderTextureSubElement SubElement; |
||||
|
public readonly int MipLevel; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: eb9fdfac33a070740b66520d88f43ab7 |
||||
|
MonoImporter: |
||||
|
externalObjects: {} |
||||
|
serializedVersion: 2 |
||||
|
defaultReferences: [] |
||||
|
executionOrder: 0 |
||||
|
icon: {instanceID: 0} |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
@ -0,0 +1,8 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: cce3e495c6ece2145b041d0a6e43bb26 |
||||
|
folderAsset: yes |
||||
|
DefaultImporter: |
||||
|
externalObjects: {} |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
@ -0,0 +1,302 @@ |
|||||
|
// Copyright (c) 2024 Nico de Poel
|
||||
|
//
|
||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
// in the Software without restriction, including without limitation the rights
|
||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||
|
// furnished to do so, subject to the following conditions:
|
||||
|
//
|
||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||
|
// copies or substantial portions of the Software.
|
||||
|
//
|
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
|
// THE SOFTWARE.
|
||||
|
|
||||
|
using System; |
||||
|
using System.Runtime.InteropServices; |
||||
|
using UnityEngine; |
||||
|
using UnityEngine.Rendering; |
||||
|
|
||||
|
namespace FidelityFX |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// A collection of helper functions and data structures required by the FSR2 process.
|
||||
|
/// </summary>
|
||||
|
public static class Fsr2 |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Creates a new FSR2 context with standard parameters that are appropriate for the current platform.
|
||||
|
/// </summary>
|
||||
|
public static Fsr2Context CreateContext(Vector2Int displaySize, Vector2Int maxRenderSize, Fsr2Shaders shaders, InitializationFlags flags = 0) |
||||
|
{ |
||||
|
if (SystemInfo.usesReversedZBuffer) |
||||
|
flags |= InitializationFlags.EnableDepthInverted; |
||||
|
else |
||||
|
flags &= ~InitializationFlags.EnableDepthInverted; |
||||
|
|
||||
|
#if UNITY_EDITOR || DEVELOPMENT_BUILD
|
||||
|
flags |= InitializationFlags.EnableDebugChecking; |
||||
|
#endif
|
||||
|
|
||||
|
Debug.Log($"Setting up FSR2 with render size: {maxRenderSize.x}x{maxRenderSize.y}, display size: {displaySize.x}x{displaySize.y}, flags: {flags}"); |
||||
|
|
||||
|
var contextDescription = new ContextDescription |
||||
|
{ |
||||
|
Flags = flags, |
||||
|
DisplaySize = displaySize, |
||||
|
MaxRenderSize = maxRenderSize, |
||||
|
Shaders = shaders, |
||||
|
}; |
||||
|
|
||||
|
var context = new Fsr2Context(); |
||||
|
context.Create(contextDescription); |
||||
|
return context; |
||||
|
} |
||||
|
|
||||
|
public static float GetUpscaleRatioFromQualityMode(QualityMode qualityMode) |
||||
|
{ |
||||
|
switch (qualityMode) |
||||
|
{ |
||||
|
case QualityMode.NativeAA: |
||||
|
return 1.0f; |
||||
|
case QualityMode.UltraQuality: |
||||
|
return 1.2f; |
||||
|
case QualityMode.Quality: |
||||
|
return 1.5f; |
||||
|
case QualityMode.Balanced: |
||||
|
return 1.7f; |
||||
|
case QualityMode.Performance: |
||||
|
return 2.0f; |
||||
|
case QualityMode.UltraPerformance: |
||||
|
return 3.0f; |
||||
|
default: |
||||
|
return 1.0f; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static void GetRenderResolutionFromQualityMode( |
||||
|
out int renderWidth, out int renderHeight, |
||||
|
int displayWidth, int displayHeight, QualityMode qualityMode) |
||||
|
{ |
||||
|
float ratio = GetUpscaleRatioFromQualityMode(qualityMode); |
||||
|
renderWidth = Mathf.RoundToInt(displayWidth / ratio); |
||||
|
renderHeight = Mathf.RoundToInt(displayHeight / ratio); |
||||
|
} |
||||
|
|
||||
|
public static float GetMipmapBiasOffset(int renderWidth, int displayWidth) |
||||
|
{ |
||||
|
return Mathf.Log((float)renderWidth / displayWidth, 2.0f) - 1.0f; |
||||
|
} |
||||
|
|
||||
|
public static int GetJitterPhaseCount(int renderWidth, int displayWidth) |
||||
|
{ |
||||
|
const float basePhaseCount = 8.0f; |
||||
|
int jitterPhaseCount = (int)(basePhaseCount * Mathf.Pow((float)displayWidth / renderWidth, 2.0f)); |
||||
|
return jitterPhaseCount; |
||||
|
} |
||||
|
|
||||
|
public static void GetJitterOffset(out float outX, out float outY, int index, int phaseCount) |
||||
|
{ |
||||
|
outX = Halton((index % phaseCount) + 1, 2) - 0.5f; |
||||
|
outY = Halton((index % phaseCount) + 1, 3) - 0.5f; |
||||
|
} |
||||
|
|
||||
|
// Calculate halton number for index and base.
|
||||
|
private static float Halton(int index, int @base) |
||||
|
{ |
||||
|
float f = 1.0f, result = 0.0f; |
||||
|
|
||||
|
for (int currentIndex = index; currentIndex > 0;) { |
||||
|
|
||||
|
f /= @base; |
||||
|
result += f * (currentIndex % @base); |
||||
|
currentIndex = (int)Mathf.Floor((float)currentIndex / @base); |
||||
|
} |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
public static float Lanczos2(float value) |
||||
|
{ |
||||
|
return Mathf.Abs(value) < Mathf.Epsilon ? 1.0f : Mathf.Sin(Mathf.PI * value) / (Mathf.PI * value) * (Mathf.Sin(0.5f * Mathf.PI * value) / (0.5f * Mathf.PI * value)); |
||||
|
} |
||||
|
|
||||
|
#if !UNITY_2021_1_OR_NEWER
|
||||
|
internal static void SetBufferData(this CommandBuffer commandBuffer, ComputeBuffer computeBuffer, Array data) |
||||
|
{ |
||||
|
commandBuffer.SetComputeBufferData(computeBuffer, data); |
||||
|
} |
||||
|
#endif
|
||||
|
|
||||
|
public enum QualityMode |
||||
|
{ |
||||
|
NativeAA = 0, |
||||
|
UltraQuality = 1, |
||||
|
Quality = 2, |
||||
|
Balanced = 3, |
||||
|
Performance = 4, |
||||
|
UltraPerformance = 5, |
||||
|
} |
||||
|
|
||||
|
[Flags] |
||||
|
public enum InitializationFlags |
||||
|
{ |
||||
|
EnableHighDynamicRange = 1 << 0, |
||||
|
EnableDisplayResolutionMotionVectors = 1 << 1, |
||||
|
EnableMotionVectorsJitterCancellation = 1 << 2, |
||||
|
EnableDepthInverted = 1 << 3, |
||||
|
EnableDepthInfinite = 1 << 4, |
||||
|
EnableAutoExposure = 1 << 5, |
||||
|
EnableDynamicResolution = 1 << 6, |
||||
|
EnableFP16Usage = 1 << 7, |
||||
|
EnableDebugChecking = 1 << 8, |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// A structure encapsulating the parameters required to initialize FidelityFX Super Resolution 2 upscaling.
|
||||
|
/// </summary>
|
||||
|
public struct ContextDescription |
||||
|
{ |
||||
|
public InitializationFlags Flags; |
||||
|
public Vector2Int MaxRenderSize; |
||||
|
public Vector2Int DisplaySize; |
||||
|
public Fsr2Shaders Shaders; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// A structure encapsulating the parameters for dispatching the various passes of FidelityFX Super Resolution 2.
|
||||
|
/// </summary>
|
||||
|
public class DispatchDescription |
||||
|
{ |
||||
|
public ResourceView Color; |
||||
|
public ResourceView Depth; |
||||
|
public ResourceView MotionVectors; |
||||
|
public ResourceView Exposure; // optional
|
||||
|
public ResourceView Reactive; // optional
|
||||
|
public ResourceView TransparencyAndComposition; // optional
|
||||
|
public ResourceView Output; |
||||
|
public Vector2 JitterOffset; |
||||
|
public Vector2 MotionVectorScale; |
||||
|
public Vector2Int RenderSize; |
||||
|
public Vector2Int InputResourceSize; |
||||
|
public bool EnableSharpening; |
||||
|
public float Sharpness; |
||||
|
public float FrameTimeDelta; // in seconds
|
||||
|
public float PreExposure; |
||||
|
public bool Reset; |
||||
|
public float CameraNear; |
||||
|
public float CameraFar; |
||||
|
public float CameraFovAngleVertical; |
||||
|
public float ViewSpaceToMetersFactor; |
||||
|
public bool UseTextureArrays; // Enable texture array bindings, primarily used for HDRP and XR
|
||||
|
|
||||
|
// EXPERIMENTAL reactive mask generation parameters
|
||||
|
public bool EnableAutoReactive; |
||||
|
public ResourceView ColorOpaqueOnly; |
||||
|
public float AutoTcThreshold = 0.05f; |
||||
|
public float AutoTcScale = 1.0f; |
||||
|
public float AutoReactiveScale = 5.0f; |
||||
|
public float AutoReactiveMax = 0.9f; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// A structure encapsulating the parameters for automatic generation of a reactive mask.
|
||||
|
/// The default values for Scale, CutoffThreshold, BinaryValue and Flags were taken from the FSR2 demo project.
|
||||
|
/// </summary>
|
||||
|
public class GenerateReactiveDescription |
||||
|
{ |
||||
|
public ResourceView ColorOpaqueOnly; |
||||
|
public ResourceView ColorPreUpscale; |
||||
|
public ResourceView OutReactive; |
||||
|
public Vector2Int RenderSize; |
||||
|
public float Scale = 0.5f; |
||||
|
public float CutoffThreshold = 0.2f; |
||||
|
public float BinaryValue = 0.9f; |
||||
|
public GenerateReactiveFlags Flags = GenerateReactiveFlags.ApplyTonemap | GenerateReactiveFlags.ApplyThreshold | GenerateReactiveFlags.UseComponentsMax; |
||||
|
} |
||||
|
|
||||
|
[Flags] |
||||
|
public enum GenerateReactiveFlags |
||||
|
{ |
||||
|
ApplyTonemap = 1 << 0, |
||||
|
ApplyInverseTonemap = 1 << 1, |
||||
|
ApplyThreshold = 1 << 2, |
||||
|
UseComponentsMax = 1 << 3, |
||||
|
} |
||||
|
|
||||
|
[Serializable, StructLayout(LayoutKind.Sequential)] |
||||
|
internal struct UpscalerConstants |
||||
|
{ |
||||
|
public Vector2Int renderSize; |
||||
|
public Vector2Int maxRenderSize; |
||||
|
public Vector2Int displaySize; |
||||
|
public Vector2Int inputColorResourceDimensions; |
||||
|
public Vector2Int lumaMipDimensions; |
||||
|
public int lumaMipLevelToUse; |
||||
|
public int frameIndex; |
||||
|
|
||||
|
public Vector4 deviceToViewDepth; |
||||
|
public Vector2 jitterOffset; |
||||
|
public Vector2 motionVectorScale; |
||||
|
public Vector2 downscaleFactor; |
||||
|
public Vector2 motionVectorJitterCancellation; |
||||
|
public float preExposure; |
||||
|
public float previousFramePreExposure; |
||||
|
public float tanHalfFOV; |
||||
|
public float jitterPhaseCount; |
||||
|
public float deltaTime; |
||||
|
public float dynamicResChangeFactor; |
||||
|
public float viewSpaceToMetersFactor; |
||||
|
public float padding; |
||||
|
} |
||||
|
|
||||
|
[Serializable, StructLayout(LayoutKind.Sequential)] |
||||
|
internal struct SpdConstants |
||||
|
{ |
||||
|
public uint mips; |
||||
|
public uint numWorkGroups; |
||||
|
public uint workGroupOffsetX, workGroupOffsetY; |
||||
|
public uint renderSizeX, renderSizeY; |
||||
|
} |
||||
|
|
||||
|
[Serializable, StructLayout(LayoutKind.Sequential)] |
||||
|
internal struct GenerateReactiveConstants |
||||
|
{ |
||||
|
public float scale; |
||||
|
public float threshold; |
||||
|
public float binaryValue; |
||||
|
public uint flags; |
||||
|
} |
||||
|
|
||||
|
[Serializable, StructLayout(LayoutKind.Sequential)] |
||||
|
internal struct GenerateReactiveConstants2 |
||||
|
{ |
||||
|
public float autoTcThreshold; |
||||
|
public float autoTcScale; |
||||
|
public float autoReactiveScale; |
||||
|
public float autoReactiveMax; |
||||
|
} |
||||
|
|
||||
|
[Serializable, StructLayout(LayoutKind.Sequential)] |
||||
|
internal struct RcasConstants |
||||
|
{ |
||||
|
public RcasConstants(uint sharpness, uint halfSharp) |
||||
|
{ |
||||
|
this.sharpness = sharpness; |
||||
|
this.halfSharp = halfSharp; |
||||
|
dummy0 = dummy1 = 0; |
||||
|
} |
||||
|
|
||||
|
public readonly uint sharpness; |
||||
|
public readonly uint halfSharp; |
||||
|
public readonly uint dummy0; |
||||
|
public readonly uint dummy1; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,81 @@ |
|||||
|
// Copyright (c) 2024 Nico de Poel
|
||||
|
//
|
||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
// in the Software without restriction, including without limitation the rights
|
||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||
|
// furnished to do so, subject to the following conditions:
|
||||
|
//
|
||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||
|
// copies or substantial portions of the Software.
|
||||
|
//
|
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
|
// THE SOFTWARE.
|
||||
|
|
||||
|
using UnityEngine; |
||||
|
|
||||
|
namespace FidelityFX |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// A collection of callbacks required by the FSR2 process.
|
||||
|
/// This allows some customization by the game dev on how to integrate FSR2 upscaling into their own game setup.
|
||||
|
/// </summary>
|
||||
|
public interface IFsr2Callbacks |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Apply a mipmap bias to in-game textures to prevent them from becoming blurry as the internal rendering resolution lowers.
|
||||
|
/// This will need to be customized on a per-game basis, as there is no clear universal way to determine what are "in-game" textures.
|
||||
|
/// The default implementation will simply apply a mipmap bias to all 2D textures, which will include things like UI textures and which might miss things like terrain texture arrays.
|
||||
|
///
|
||||
|
/// Depending on how your game organizes its assets, you will want to create a filter that more specifically selects the textures that need to have this mipmap bias applied.
|
||||
|
/// You may also want to store the bias offset value and apply it to any assets that are loaded in on demand.
|
||||
|
/// </summary>
|
||||
|
void ApplyMipmapBias(float biasOffset); |
||||
|
|
||||
|
void UndoMipmapBias(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Default implementation of IFsr2Callbacks.
|
||||
|
/// These are fine for testing but a proper game will want to extend and override these methods.
|
||||
|
/// </summary>
|
||||
|
public class Fsr2CallbacksBase: IFsr2Callbacks |
||||
|
{ |
||||
|
protected float CurrentBiasOffset = 0; |
||||
|
|
||||
|
public virtual void ApplyMipmapBias(float biasOffset) |
||||
|
{ |
||||
|
if (float.IsNaN(biasOffset) || float.IsInfinity(biasOffset)) |
||||
|
return; |
||||
|
|
||||
|
CurrentBiasOffset += biasOffset; |
||||
|
|
||||
|
if (Mathf.Approximately(CurrentBiasOffset, 0f)) |
||||
|
{ |
||||
|
CurrentBiasOffset = 0f; |
||||
|
} |
||||
|
|
||||
|
foreach (var texture in Resources.FindObjectsOfTypeAll<Texture2D>()) |
||||
|
{ |
||||
|
if (texture.mipmapCount <= 1) |
||||
|
continue; |
||||
|
|
||||
|
texture.mipMapBias += biasOffset; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public virtual void UndoMipmapBias() |
||||
|
{ |
||||
|
if (CurrentBiasOffset == 0f) |
||||
|
return; |
||||
|
|
||||
|
ApplyMipmapBias(-CurrentBiasOffset); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,618 @@ |
|||||
|
// Copyright (c) 2024 Nico de Poel
|
||||
|
//
|
||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
// in the Software without restriction, including without limitation the rights
|
||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||
|
// furnished to do so, subject to the following conditions:
|
||||
|
//
|
||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||
|
// copies or substantial portions of the Software.
|
||||
|
//
|
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
|
// THE SOFTWARE.
|
||||
|
|
||||
|
using System; |
||||
|
using System.Runtime.InteropServices; |
||||
|
using UnityEngine; |
||||
|
using UnityEngine.Rendering; |
||||
|
|
||||
|
namespace FidelityFX |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// This class loosely matches the FfxFsr2Context struct from the original FSR2 codebase.
|
||||
|
/// It manages the various resources and compute passes required by the FSR2 process.
|
||||
|
/// Note that this class does not know anything about Unity render pipelines; all it knows is CommandBuffers and RenderTargetIdentifiers.
|
||||
|
/// This should make it suitable for integration with any of the available Unity render pipelines.
|
||||
|
/// </summary>
|
||||
|
public class Fsr2Context |
||||
|
{ |
||||
|
private const int MaxQueuedFrames = 16; |
||||
|
|
||||
|
private Fsr2.ContextDescription _contextDescription; |
||||
|
private CommandBuffer _commandBuffer; |
||||
|
|
||||
|
private Fsr2Pass _computeLuminancePyramidPass; |
||||
|
private Fsr2Pass _reconstructPreviousDepthPass; |
||||
|
private Fsr2Pass _depthClipPass; |
||||
|
private Fsr2Pass _lockPass; |
||||
|
private Fsr2Pass _accumulatePass; |
||||
|
private Fsr2Pass _sharpenPass; |
||||
|
private Fsr2Pass _generateReactivePass; |
||||
|
private Fsr2Pass _tcrAutogeneratePass; |
||||
|
|
||||
|
private readonly Fsr2Resources _resources = new Fsr2Resources(); |
||||
|
|
||||
|
private ComputeBuffer _upscalerConstantsBuffer; |
||||
|
private readonly Fsr2.UpscalerConstants[] _upscalerConstantsArray = { new Fsr2.UpscalerConstants() }; |
||||
|
private ref Fsr2.UpscalerConstants UpscalerConsts => ref _upscalerConstantsArray[0]; |
||||
|
|
||||
|
private ComputeBuffer _spdConstantsBuffer; |
||||
|
private readonly Fsr2.SpdConstants[] _spdConstantsArray = { new Fsr2.SpdConstants() }; |
||||
|
private ref Fsr2.SpdConstants SpdConsts => ref _spdConstantsArray[0]; |
||||
|
|
||||
|
private ComputeBuffer _rcasConstantsBuffer; |
||||
|
private readonly Fsr2.RcasConstants[] _rcasConstantsArray = new Fsr2.RcasConstants[1]; |
||||
|
private ref Fsr2.RcasConstants RcasConsts => ref _rcasConstantsArray[0]; |
||||
|
|
||||
|
private ComputeBuffer _generateReactiveConstantsBuffer; |
||||
|
private readonly Fsr2.GenerateReactiveConstants[] _generateReactiveConstantsArray = { new Fsr2.GenerateReactiveConstants() }; |
||||
|
private ref Fsr2.GenerateReactiveConstants GenReactiveConsts => ref _generateReactiveConstantsArray[0]; |
||||
|
|
||||
|
private ComputeBuffer _tcrAutogenerateConstantsBuffer; |
||||
|
private readonly Fsr2.GenerateReactiveConstants2[] _tcrAutogenerateConstantsArray = { new Fsr2.GenerateReactiveConstants2() }; |
||||
|
private ref Fsr2.GenerateReactiveConstants2 TcrAutoGenConsts => ref _tcrAutogenerateConstantsArray[0]; |
||||
|
|
||||
|
private bool _firstExecution; |
||||
|
private Vector2 _previousJitterOffset; |
||||
|
private int _resourceFrameIndex; |
||||
|
|
||||
|
public void Create(Fsr2.ContextDescription contextDescription) |
||||
|
{ |
||||
|
_contextDescription = contextDescription; |
||||
|
_commandBuffer = new CommandBuffer { name = "FSR2" }; |
||||
|
|
||||
|
_upscalerConstantsBuffer = CreateConstantBuffer<Fsr2.UpscalerConstants>(); |
||||
|
_spdConstantsBuffer = CreateConstantBuffer<Fsr2.SpdConstants>(); |
||||
|
_rcasConstantsBuffer = CreateConstantBuffer<Fsr2.RcasConstants>(); |
||||
|
_generateReactiveConstantsBuffer = CreateConstantBuffer<Fsr2.GenerateReactiveConstants>(); |
||||
|
_tcrAutogenerateConstantsBuffer = CreateConstantBuffer<Fsr2.GenerateReactiveConstants2>(); |
||||
|
|
||||
|
// Set defaults
|
||||
|
_firstExecution = true; |
||||
|
_resourceFrameIndex = 0; |
||||
|
|
||||
|
UpscalerConsts.displaySize = _contextDescription.DisplaySize; |
||||
|
|
||||
|
_resources.Create(_contextDescription); |
||||
|
CreatePasses(); |
||||
|
} |
||||
|
|
||||
|
private void CreatePasses() |
||||
|
{ |
||||
|
_computeLuminancePyramidPass = new Fsr2ComputeLuminancePyramidPass(_contextDescription, _resources, _upscalerConstantsBuffer, _spdConstantsBuffer); |
||||
|
_reconstructPreviousDepthPass = new Fsr2ReconstructPreviousDepthPass(_contextDescription, _resources, _upscalerConstantsBuffer); |
||||
|
_depthClipPass = new Fsr2DepthClipPass(_contextDescription, _resources, _upscalerConstantsBuffer); |
||||
|
_lockPass = new Fsr2LockPass(_contextDescription, _resources, _upscalerConstantsBuffer); |
||||
|
_accumulatePass = new Fsr2AccumulatePass(_contextDescription, _resources, _upscalerConstantsBuffer); |
||||
|
_sharpenPass = new Fsr2SharpenPass(_contextDescription, _resources, _upscalerConstantsBuffer, _rcasConstantsBuffer); |
||||
|
_generateReactivePass = new Fsr2GenerateReactivePass(_contextDescription, _resources, _generateReactiveConstantsBuffer); |
||||
|
_tcrAutogeneratePass = new Fsr2TcrAutogeneratePass(_contextDescription, _resources, _upscalerConstantsBuffer, _tcrAutogenerateConstantsBuffer); |
||||
|
} |
||||
|
|
||||
|
public void Destroy() |
||||
|
{ |
||||
|
DestroyPass(ref _tcrAutogeneratePass); |
||||
|
DestroyPass(ref _generateReactivePass); |
||||
|
DestroyPass(ref _sharpenPass); |
||||
|
DestroyPass(ref _accumulatePass); |
||||
|
DestroyPass(ref _lockPass); |
||||
|
DestroyPass(ref _depthClipPass); |
||||
|
DestroyPass(ref _reconstructPreviousDepthPass); |
||||
|
DestroyPass(ref _computeLuminancePyramidPass); |
||||
|
|
||||
|
_resources.Destroy(); |
||||
|
|
||||
|
DestroyConstantBuffer(ref _tcrAutogenerateConstantsBuffer); |
||||
|
DestroyConstantBuffer(ref _generateReactiveConstantsBuffer); |
||||
|
DestroyConstantBuffer(ref _rcasConstantsBuffer); |
||||
|
DestroyConstantBuffer(ref _spdConstantsBuffer); |
||||
|
DestroyConstantBuffer(ref _upscalerConstantsBuffer); |
||||
|
|
||||
|
if (_commandBuffer != null) |
||||
|
{ |
||||
|
_commandBuffer.Dispose(); |
||||
|
_commandBuffer = null; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public void Dispatch(Fsr2.DispatchDescription dispatchParams) |
||||
|
{ |
||||
|
_commandBuffer.Clear(); |
||||
|
Dispatch(dispatchParams, _commandBuffer); |
||||
|
Graphics.ExecuteCommandBuffer(_commandBuffer); |
||||
|
} |
||||
|
|
||||
|
public void Dispatch(Fsr2.DispatchDescription dispatchParams, CommandBuffer commandBuffer) |
||||
|
{ |
||||
|
if ((_contextDescription.Flags & Fsr2.InitializationFlags.EnableDebugChecking) != 0) |
||||
|
{ |
||||
|
DebugCheckDispatch(dispatchParams); |
||||
|
} |
||||
|
|
||||
|
if (dispatchParams.UseTextureArrays) |
||||
|
commandBuffer.EnableShaderKeyword("UNITY_FSR_TEXTURE2D_X_ARRAY"); |
||||
|
|
||||
|
if (_firstExecution) |
||||
|
{ |
||||
|
commandBuffer.SetRenderTarget(_resources.LockStatus[0]); |
||||
|
commandBuffer.ClearRenderTarget(false, true, Color.clear); |
||||
|
commandBuffer.SetRenderTarget(_resources.LockStatus[1]); |
||||
|
commandBuffer.ClearRenderTarget(false, true, Color.clear); |
||||
|
} |
||||
|
|
||||
|
int frameIndex = _resourceFrameIndex % 2; |
||||
|
bool resetAccumulation = dispatchParams.Reset || _firstExecution; |
||||
|
_firstExecution = false; |
||||
|
|
||||
|
// If auto exposure is enabled use the auto exposure SRV, otherwise what the app sends
|
||||
|
if ((_contextDescription.Flags & Fsr2.InitializationFlags.EnableAutoExposure) != 0) |
||||
|
dispatchParams.Exposure = new ResourceView(_resources.AutoExposure); |
||||
|
else if (!dispatchParams.Exposure.IsValid) |
||||
|
dispatchParams.Exposure = new ResourceView(_resources.DefaultExposure); |
||||
|
|
||||
|
if (dispatchParams.EnableAutoReactive) |
||||
|
{ |
||||
|
// Create the auto-TCR resources only when we need them
|
||||
|
if (_resources.AutoReactive == null) |
||||
|
_resources.CreateTcrAutogenResources(_contextDescription); |
||||
|
|
||||
|
if (resetAccumulation) |
||||
|
{ |
||||
|
RenderTargetIdentifier opaqueOnly = dispatchParams.ColorOpaqueOnly.IsValid ? dispatchParams.ColorOpaqueOnly.RenderTarget : Fsr2ShaderIDs.SrvOpaqueOnly; |
||||
|
commandBuffer.Blit(_resources.PrevPreAlpha[frameIndex ^ 1], opaqueOnly); |
||||
|
} |
||||
|
} |
||||
|
else if (_resources.AutoReactive != null) |
||||
|
{ |
||||
|
// Destroy the auto-TCR resources if we don't use the feature
|
||||
|
_resources.DestroyTcrAutogenResources(); |
||||
|
} |
||||
|
|
||||
|
if (!dispatchParams.Reactive.IsValid) dispatchParams.Reactive = new ResourceView(_resources.DefaultReactive); |
||||
|
if (!dispatchParams.TransparencyAndComposition.IsValid) dispatchParams.TransparencyAndComposition = new ResourceView(_resources.DefaultReactive); |
||||
|
Fsr2Resources.CreateAliasableResources(commandBuffer, _contextDescription, dispatchParams); |
||||
|
|
||||
|
SetupConstants(dispatchParams, resetAccumulation); |
||||
|
|
||||
|
// Reactive mask bias
|
||||
|
const int threadGroupWorkRegionDim = 8; |
||||
|
int dispatchSrcX = (UpscalerConsts.renderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; |
||||
|
int dispatchSrcY = (UpscalerConsts.renderSize.y + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; |
||||
|
int dispatchDstX = (_contextDescription.DisplaySize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; |
||||
|
int dispatchDstY = (_contextDescription.DisplaySize.y + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; |
||||
|
|
||||
|
// Clear reconstructed depth for max depth store
|
||||
|
if (resetAccumulation) |
||||
|
{ |
||||
|
commandBuffer.SetRenderTarget(_resources.LockStatus[frameIndex ^ 1]); |
||||
|
commandBuffer.ClearRenderTarget(false, true, Color.clear); |
||||
|
|
||||
|
commandBuffer.SetRenderTarget(_resources.InternalUpscaled[frameIndex ^ 1]); |
||||
|
commandBuffer.ClearRenderTarget(false, true, Color.clear); |
||||
|
|
||||
|
commandBuffer.SetRenderTarget(_resources.SceneLuminance); |
||||
|
commandBuffer.ClearRenderTarget(false, true, Color.clear); |
||||
|
|
||||
|
// Auto exposure always used to track luma changes in locking logic
|
||||
|
commandBuffer.SetRenderTarget(_resources.AutoExposure); |
||||
|
commandBuffer.ClearRenderTarget(false, true, new Color(0f, 1e8f, 0f, 0f)); |
||||
|
|
||||
|
// Reset atomic counter to 0
|
||||
|
commandBuffer.SetRenderTarget(_resources.SpdAtomicCounter); |
||||
|
commandBuffer.ClearRenderTarget(false, true, Color.clear); |
||||
|
} |
||||
|
|
||||
|
// FSR3: need to clear here since we need the content of this surface for frame interpolation, so clearing in the lock pass is not an option
|
||||
|
bool depthInverted = (_contextDescription.Flags & Fsr2.InitializationFlags.EnableDepthInverted) == Fsr2.InitializationFlags.EnableDepthInverted; |
||||
|
commandBuffer.SetRenderTarget(Fsr2ShaderIDs.UavReconstructedPrevNearestDepth); |
||||
|
commandBuffer.ClearRenderTarget(false, true, depthInverted ? Color.clear : Color.white); |
||||
|
|
||||
|
// Auto exposure
|
||||
|
SetupSpdConstants(dispatchParams, out var dispatchThreadGroupCount); |
||||
|
|
||||
|
// Initialize constant buffers data
|
||||
|
commandBuffer.SetBufferData(_upscalerConstantsBuffer, _upscalerConstantsArray); |
||||
|
commandBuffer.SetBufferData(_spdConstantsBuffer, _spdConstantsArray); |
||||
|
|
||||
|
// Auto reactive
|
||||
|
if (dispatchParams.EnableAutoReactive) |
||||
|
{ |
||||
|
GenerateTransparencyCompositionReactive(dispatchParams, commandBuffer, frameIndex); |
||||
|
dispatchParams.Reactive = new ResourceView(_resources.AutoReactive); |
||||
|
dispatchParams.TransparencyAndComposition = new ResourceView(_resources.AutoComposition); |
||||
|
} |
||||
|
|
||||
|
// Compute luminance pyramid
|
||||
|
_computeLuminancePyramidPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchThreadGroupCount.x, dispatchThreadGroupCount.y); |
||||
|
|
||||
|
// Reconstruct previous depth
|
||||
|
_reconstructPreviousDepthPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY); |
||||
|
|
||||
|
// Depth clip
|
||||
|
_depthClipPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY); |
||||
|
|
||||
|
// Create locks
|
||||
|
_lockPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY); |
||||
|
|
||||
|
// Accumulate
|
||||
|
_accumulatePass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchDstX, dispatchDstY); |
||||
|
|
||||
|
if (dispatchParams.EnableSharpening) |
||||
|
{ |
||||
|
// Compute the constants
|
||||
|
SetupRcasConstants(dispatchParams); |
||||
|
commandBuffer.SetBufferData(_rcasConstantsBuffer, _rcasConstantsArray); |
||||
|
|
||||
|
// Dispatch RCAS
|
||||
|
const int threadGroupWorkRegionDimRcas = 16; |
||||
|
int threadGroupsX = (Screen.width + threadGroupWorkRegionDimRcas - 1) / threadGroupWorkRegionDimRcas; |
||||
|
int threadGroupsY = (Screen.height + threadGroupWorkRegionDimRcas - 1) / threadGroupWorkRegionDimRcas; |
||||
|
_sharpenPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, threadGroupsX, threadGroupsY); |
||||
|
} |
||||
|
|
||||
|
_resourceFrameIndex = (_resourceFrameIndex + 1) % MaxQueuedFrames; |
||||
|
|
||||
|
Fsr2Resources.DestroyAliasableResources(commandBuffer); |
||||
|
|
||||
|
commandBuffer.DisableShaderKeyword("UNITY_FSR_TEXTURE2D_X_ARRAY"); |
||||
|
} |
||||
|
|
||||
|
public void GenerateReactiveMask(Fsr2.GenerateReactiveDescription dispatchParams) |
||||
|
{ |
||||
|
_commandBuffer.Clear(); |
||||
|
GenerateReactiveMask(dispatchParams, _commandBuffer); |
||||
|
Graphics.ExecuteCommandBuffer(_commandBuffer); |
||||
|
} |
||||
|
|
||||
|
public void GenerateReactiveMask(Fsr2.GenerateReactiveDescription dispatchParams, CommandBuffer commandBuffer) |
||||
|
{ |
||||
|
const int threadGroupWorkRegionDim = 8; |
||||
|
int dispatchSrcX = (dispatchParams.RenderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; |
||||
|
int dispatchSrcY = (dispatchParams.RenderSize.y + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; |
||||
|
|
||||
|
GenReactiveConsts.scale = dispatchParams.Scale; |
||||
|
GenReactiveConsts.threshold = dispatchParams.CutoffThreshold; |
||||
|
GenReactiveConsts.binaryValue = dispatchParams.BinaryValue; |
||||
|
GenReactiveConsts.flags = (uint)dispatchParams.Flags; |
||||
|
commandBuffer.SetBufferData(_generateReactiveConstantsBuffer, _generateReactiveConstantsArray); |
||||
|
|
||||
|
((Fsr2GenerateReactivePass)_generateReactivePass).ScheduleDispatch(commandBuffer, dispatchParams, dispatchSrcX, dispatchSrcY); |
||||
|
} |
||||
|
|
||||
|
private void GenerateTransparencyCompositionReactive(Fsr2.DispatchDescription dispatchParams, CommandBuffer commandBuffer, int frameIndex) |
||||
|
{ |
||||
|
const int threadGroupWorkRegionDim = 8; |
||||
|
int dispatchSrcX = (dispatchParams.RenderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; |
||||
|
int dispatchSrcY = (dispatchParams.RenderSize.y + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; |
||||
|
|
||||
|
TcrAutoGenConsts.autoTcThreshold = dispatchParams.AutoTcThreshold; |
||||
|
TcrAutoGenConsts.autoTcScale = dispatchParams.AutoTcScale; |
||||
|
TcrAutoGenConsts.autoReactiveScale = dispatchParams.AutoReactiveScale; |
||||
|
TcrAutoGenConsts.autoReactiveMax = dispatchParams.AutoReactiveMax; |
||||
|
commandBuffer.SetBufferData(_tcrAutogenerateConstantsBuffer, _tcrAutogenerateConstantsArray); |
||||
|
|
||||
|
_tcrAutogeneratePass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY); |
||||
|
} |
||||
|
|
||||
|
private void SetupConstants(Fsr2.DispatchDescription dispatchParams, bool resetAccumulation) |
||||
|
{ |
||||
|
ref Fsr2.UpscalerConstants constants = ref UpscalerConsts; |
||||
|
|
||||
|
constants.jitterOffset = dispatchParams.JitterOffset; |
||||
|
constants.renderSize = dispatchParams.RenderSize; |
||||
|
constants.maxRenderSize = _contextDescription.MaxRenderSize; |
||||
|
constants.inputColorResourceDimensions = dispatchParams.InputResourceSize; |
||||
|
|
||||
|
// Compute the horizontal FOV for the shader from the vertical one
|
||||
|
float aspectRatio = (float)dispatchParams.RenderSize.x / dispatchParams.RenderSize.y; |
||||
|
float cameraAngleHorizontal = Mathf.Atan(Mathf.Tan(dispatchParams.CameraFovAngleVertical / 2.0f) * aspectRatio) * 2.0f; |
||||
|
constants.tanHalfFOV = Mathf.Tan(cameraAngleHorizontal * 0.5f); |
||||
|
constants.viewSpaceToMetersFactor = (dispatchParams.ViewSpaceToMetersFactor > 0.0f) ? dispatchParams.ViewSpaceToMetersFactor : 1.0f; |
||||
|
|
||||
|
// Compute params to enable device depth to view space depth computation in shader
|
||||
|
constants.deviceToViewDepth = SetupDeviceDepthToViewSpaceDepthParams(dispatchParams); |
||||
|
|
||||
|
// To be updated if resource is larger than the actual image size
|
||||
|
constants.downscaleFactor = new Vector2((float)constants.renderSize.x / _contextDescription.DisplaySize.x, (float)constants.renderSize.y / _contextDescription.DisplaySize.y); |
||||
|
constants.previousFramePreExposure = constants.preExposure; |
||||
|
constants.preExposure = (dispatchParams.PreExposure != 0) ? dispatchParams.PreExposure : 1.0f; |
||||
|
|
||||
|
// Motion vector data
|
||||
|
Vector2Int motionVectorsTargetSize = (_contextDescription.Flags & Fsr2.InitializationFlags.EnableDisplayResolutionMotionVectors) != 0 ? constants.displaySize : constants.renderSize; |
||||
|
constants.motionVectorScale = dispatchParams.MotionVectorScale / motionVectorsTargetSize; |
||||
|
|
||||
|
// Compute jitter cancellation
|
||||
|
if ((_contextDescription.Flags & Fsr2.InitializationFlags.EnableMotionVectorsJitterCancellation) != 0) |
||||
|
{ |
||||
|
constants.motionVectorJitterCancellation = (_previousJitterOffset - constants.jitterOffset) / motionVectorsTargetSize; |
||||
|
_previousJitterOffset = constants.jitterOffset; |
||||
|
} |
||||
|
|
||||
|
int jitterPhaseCount = Fsr2.GetJitterPhaseCount(dispatchParams.RenderSize.x, _contextDescription.DisplaySize.x); |
||||
|
if (resetAccumulation || constants.jitterPhaseCount == 0) |
||||
|
{ |
||||
|
constants.jitterPhaseCount = jitterPhaseCount; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
int jitterPhaseCountDelta = (int)(jitterPhaseCount - constants.jitterPhaseCount); |
||||
|
if (jitterPhaseCountDelta > 0) |
||||
|
constants.jitterPhaseCount++; |
||||
|
else if (jitterPhaseCountDelta < 0) |
||||
|
constants.jitterPhaseCount--; |
||||
|
} |
||||
|
|
||||
|
// Convert delta time to seconds and clamp to [0, 1]
|
||||
|
constants.deltaTime = Mathf.Clamp01(dispatchParams.FrameTimeDelta); |
||||
|
|
||||
|
if (resetAccumulation) |
||||
|
constants.frameIndex = 0; |
||||
|
else |
||||
|
constants.frameIndex++; |
||||
|
|
||||
|
// Shading change usage of the SPD mip levels
|
||||
|
constants.lumaMipLevelToUse = Fsr2Pass.ShadingChangeMipLevel; |
||||
|
|
||||
|
float mipDiv = 2 << constants.lumaMipLevelToUse; |
||||
|
constants.lumaMipDimensions.x = (int)(constants.maxRenderSize.x / mipDiv); |
||||
|
constants.lumaMipDimensions.y = (int)(constants.maxRenderSize.y / mipDiv); |
||||
|
} |
||||
|
|
||||
|
private Vector4 SetupDeviceDepthToViewSpaceDepthParams(Fsr2.DispatchDescription dispatchParams) |
||||
|
{ |
||||
|
bool inverted = (_contextDescription.Flags & Fsr2.InitializationFlags.EnableDepthInverted) != 0; |
||||
|
bool infinite = (_contextDescription.Flags & Fsr2.InitializationFlags.EnableDepthInfinite) != 0; |
||||
|
|
||||
|
// make sure it has no impact if near and far plane values are swapped in dispatch params
|
||||
|
// the flags "inverted" and "infinite" will decide what transform to use
|
||||
|
float min = Mathf.Min(dispatchParams.CameraNear, dispatchParams.CameraFar); |
||||
|
float max = Mathf.Max(dispatchParams.CameraNear, dispatchParams.CameraFar); |
||||
|
|
||||
|
if (inverted) |
||||
|
{ |
||||
|
(min, max) = (max, min); |
||||
|
} |
||||
|
|
||||
|
float q = max / (min - max); |
||||
|
float d = -1.0f; |
||||
|
|
||||
|
Vector4 matrixElemC = new Vector4(q, -1.0f - Mathf.Epsilon, q, 0.0f + Mathf.Epsilon); |
||||
|
Vector4 matrixElemE = new Vector4(q * min, -min - Mathf.Epsilon, q * min, max); |
||||
|
|
||||
|
// Revert x and y coords
|
||||
|
float aspect = (float)dispatchParams.RenderSize.x / dispatchParams.RenderSize.y; |
||||
|
float cotHalfFovY = Mathf.Cos(0.5f * dispatchParams.CameraFovAngleVertical) / Mathf.Sin(0.5f * dispatchParams.CameraFovAngleVertical); |
||||
|
|
||||
|
int matrixIndex = (inverted ? 2 : 0) + (infinite ? 1 : 0); |
||||
|
return new Vector4( |
||||
|
d * matrixElemC[matrixIndex], |
||||
|
matrixElemE[matrixIndex], |
||||
|
aspect / cotHalfFovY, |
||||
|
1.0f / cotHalfFovY); |
||||
|
} |
||||
|
|
||||
|
private void SetupRcasConstants(Fsr2.DispatchDescription dispatchParams) |
||||
|
{ |
||||
|
int sharpnessIndex = Mathf.RoundToInt(Mathf.Clamp01(dispatchParams.Sharpness) * (RcasConfigs.Length - 1)); |
||||
|
RcasConsts = RcasConfigs[sharpnessIndex]; |
||||
|
} |
||||
|
|
||||
|
private void SetupSpdConstants(Fsr2.DispatchDescription dispatchParams, out Vector2Int dispatchThreadGroupCount) |
||||
|
{ |
||||
|
RectInt rectInfo = new RectInt(0, 0, dispatchParams.RenderSize.x, dispatchParams.RenderSize.y); |
||||
|
SpdSetup(rectInfo, out dispatchThreadGroupCount, out var workGroupOffset, out var numWorkGroupsAndMips); |
||||
|
|
||||
|
// Downsample
|
||||
|
ref Fsr2.SpdConstants spdConstants = ref SpdConsts; |
||||
|
spdConstants.numWorkGroups = (uint)numWorkGroupsAndMips.x; |
||||
|
spdConstants.mips = (uint)numWorkGroupsAndMips.y; |
||||
|
spdConstants.workGroupOffsetX = (uint)workGroupOffset.x; |
||||
|
spdConstants.workGroupOffsetY = (uint)workGroupOffset.y; |
||||
|
spdConstants.renderSizeX = (uint)dispatchParams.RenderSize.x; |
||||
|
spdConstants.renderSizeY = (uint)dispatchParams.RenderSize.y; |
||||
|
} |
||||
|
|
||||
|
private static void SpdSetup(RectInt rectInfo, out Vector2Int dispatchThreadGroupCount, out Vector2Int workGroupOffset, out Vector2Int numWorkGroupsAndMips, int mips = -1) |
||||
|
{ |
||||
|
workGroupOffset = new Vector2Int(rectInfo.x / 64, rectInfo.y / 64); |
||||
|
|
||||
|
int endIndexX = (rectInfo.x + rectInfo.width - 1) / 64; |
||||
|
int endIndexY = (rectInfo.y + rectInfo.height - 1) / 64; |
||||
|
|
||||
|
dispatchThreadGroupCount = new Vector2Int(endIndexX + 1 - workGroupOffset.x, endIndexY + 1 - workGroupOffset.y); |
||||
|
|
||||
|
numWorkGroupsAndMips = new Vector2Int(dispatchThreadGroupCount.x * dispatchThreadGroupCount.y, mips); |
||||
|
if (mips < 0) |
||||
|
{ |
||||
|
float resolution = Math.Max(rectInfo.width, rectInfo.height); |
||||
|
numWorkGroupsAndMips.y = Math.Min(Mathf.FloorToInt(Mathf.Log(resolution, 2.0f)), 12); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private void DebugCheckDispatch(Fsr2.DispatchDescription dispatchParams) |
||||
|
{ |
||||
|
if (!dispatchParams.Color.IsValid) |
||||
|
{ |
||||
|
Debug.LogError("Color resource is null"); |
||||
|
} |
||||
|
|
||||
|
if (!dispatchParams.Depth.IsValid) |
||||
|
{ |
||||
|
Debug.LogError("Depth resource is null"); |
||||
|
} |
||||
|
|
||||
|
if (!dispatchParams.MotionVectors.IsValid) |
||||
|
{ |
||||
|
Debug.LogError("MotionVectors resource is null"); |
||||
|
} |
||||
|
|
||||
|
if (!dispatchParams.Output.IsValid) |
||||
|
{ |
||||
|
Debug.LogError("Output resource is null"); |
||||
|
} |
||||
|
|
||||
|
if (dispatchParams.Exposure.IsValid && (_contextDescription.Flags & Fsr2.InitializationFlags.EnableAutoExposure) != 0) |
||||
|
{ |
||||
|
Debug.LogWarning("Exposure resource provided, however auto exposure flag is present"); |
||||
|
} |
||||
|
|
||||
|
if (Mathf.Abs(dispatchParams.JitterOffset.x) > 1.0f || Mathf.Abs(dispatchParams.JitterOffset.y) > 1.0f) |
||||
|
{ |
||||
|
Debug.LogWarning("JitterOffset contains value outside of expected range [-1.0, 1.0]"); |
||||
|
} |
||||
|
|
||||
|
if (dispatchParams.MotionVectorScale.x > _contextDescription.MaxRenderSize.x || dispatchParams.MotionVectorScale.y > _contextDescription.MaxRenderSize.y) |
||||
|
{ |
||||
|
Debug.LogWarning("MotionVectorScale contains scale value greater than MaxRenderSize"); |
||||
|
} |
||||
|
|
||||
|
if (dispatchParams.MotionVectorScale.x == 0.0f || dispatchParams.MotionVectorScale.y == 0.0f) |
||||
|
{ |
||||
|
Debug.LogWarning("MotionVectorScale contains zero scale value"); |
||||
|
} |
||||
|
|
||||
|
if (dispatchParams.RenderSize.x > _contextDescription.MaxRenderSize.x || dispatchParams.RenderSize.y > _contextDescription.MaxRenderSize.y) |
||||
|
{ |
||||
|
Debug.LogWarning("RenderSize is greater than context MaxRenderSize"); |
||||
|
} |
||||
|
|
||||
|
if (dispatchParams.RenderSize.x == 0 || dispatchParams.RenderSize.y == 0) |
||||
|
{ |
||||
|
Debug.LogWarning("RenderSize contains zero dimension"); |
||||
|
} |
||||
|
|
||||
|
if (dispatchParams.FrameTimeDelta > 1.0f) |
||||
|
{ |
||||
|
Debug.LogWarning("FrameTimeDelta is greater than 1.0f - this value should be seconds (~0.0166 for 60fps)"); |
||||
|
} |
||||
|
|
||||
|
if (dispatchParams.PreExposure == 0.0f) |
||||
|
{ |
||||
|
Debug.LogError("PreExposure provided as 0.0f which is invalid"); |
||||
|
} |
||||
|
|
||||
|
bool infiniteDepth = (_contextDescription.Flags & Fsr2.InitializationFlags.EnableDepthInfinite) != 0; |
||||
|
bool inverseDepth = (_contextDescription.Flags & Fsr2.InitializationFlags.EnableDepthInverted) != 0; |
||||
|
|
||||
|
if (inverseDepth) |
||||
|
{ |
||||
|
if (dispatchParams.CameraNear < dispatchParams.CameraFar) |
||||
|
{ |
||||
|
Debug.LogWarning("EnableDepthInverted flag is present yet CameraNear is less than CameraFar"); |
||||
|
} |
||||
|
|
||||
|
if (infiniteDepth) |
||||
|
{ |
||||
|
if (dispatchParams.CameraNear < float.MaxValue) |
||||
|
{ |
||||
|
Debug.LogWarning("EnableDepthInfinite and EnableDepthInverted present, yet CameraNear != float.MaxValue"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (dispatchParams.CameraFar < 0.075f) |
||||
|
{ |
||||
|
Debug.LogWarning("EnableDepthInverted present, CameraFar value is very low which may result in depth separation artefacting"); |
||||
|
} |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
if (dispatchParams.CameraNear > dispatchParams.CameraFar) |
||||
|
{ |
||||
|
Debug.LogWarning("CameraNear is greater than CameraFar in non-inverted-depth context"); |
||||
|
} |
||||
|
|
||||
|
if (infiniteDepth) |
||||
|
{ |
||||
|
if (dispatchParams.CameraFar < float.MaxValue) |
||||
|
{ |
||||
|
Debug.LogWarning("EnableDepthInfinite present, yet CameraFar != float.MaxValue"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (dispatchParams.CameraNear < 0.075f) |
||||
|
{ |
||||
|
Debug.LogWarning("CameraNear value is very low which may result in depth separation artefacting"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (dispatchParams.CameraFovAngleVertical <= 0.0f) |
||||
|
{ |
||||
|
Debug.LogError("CameraFovAngleVertical is 0.0f - this value should be > 0.0f"); |
||||
|
} |
||||
|
|
||||
|
if (dispatchParams.CameraFovAngleVertical > Mathf.PI) |
||||
|
{ |
||||
|
Debug.LogError("CameraFovAngleVertical is greater than 180 degrees/PI"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The FSR2 C++ codebase uses floats bitwise converted to ints to pass sharpness parameters to the RCAS shader.
|
||||
|
/// This is not possible in C# without enabling unsafe code compilation, so to avoid that we instead use a table of precomputed values.
|
||||
|
/// </summary>
|
||||
|
private static readonly Fsr2.RcasConstants[] RcasConfigs = new [] |
||||
|
{ |
||||
|
new Fsr2.RcasConstants(1048576000u, 872428544u), |
||||
|
new Fsr2.RcasConstants(1049178080u, 877212745u), |
||||
|
new Fsr2.RcasConstants(1049823372u, 882390168u), |
||||
|
new Fsr2.RcasConstants(1050514979u, 887895276u), |
||||
|
new Fsr2.RcasConstants(1051256227u, 893859143u), |
||||
|
new Fsr2.RcasConstants(1052050675u, 900216232u), |
||||
|
new Fsr2.RcasConstants(1052902144u, 907032080u), |
||||
|
new Fsr2.RcasConstants(1053814727u, 914306687u), |
||||
|
new Fsr2.RcasConstants(1054792807u, 922105590u), |
||||
|
new Fsr2.RcasConstants(1055841087u, 930494326u), |
||||
|
new Fsr2.RcasConstants(1056964608u, 939538432u), |
||||
|
new Fsr2.RcasConstants(1057566688u, 944322633u), |
||||
|
new Fsr2.RcasConstants(1058211980u, 949500056u), |
||||
|
new Fsr2.RcasConstants(1058903587u, 955005164u), |
||||
|
new Fsr2.RcasConstants(1059644835u, 960969031u), |
||||
|
new Fsr2.RcasConstants(1060439283u, 967326120u), |
||||
|
new Fsr2.RcasConstants(1061290752u, 974141968u), |
||||
|
new Fsr2.RcasConstants(1062203335u, 981416575u), |
||||
|
new Fsr2.RcasConstants(1063181415u, 989215478u), |
||||
|
new Fsr2.RcasConstants(1064229695u, 997604214u), |
||||
|
new Fsr2.RcasConstants(1065353216u, 1006648320), |
||||
|
}; |
||||
|
|
||||
|
private static ComputeBuffer CreateConstantBuffer<TConstants>() where TConstants: struct |
||||
|
{ |
||||
|
return new ComputeBuffer(1, Marshal.SizeOf<TConstants>(), ComputeBufferType.Constant); |
||||
|
} |
||||
|
|
||||
|
private static void DestroyConstantBuffer(ref ComputeBuffer bufferRef) |
||||
|
{ |
||||
|
if (bufferRef == null) |
||||
|
return; |
||||
|
|
||||
|
bufferRef.Release(); |
||||
|
bufferRef = null; |
||||
|
} |
||||
|
|
||||
|
private static void DestroyPass(ref Fsr2Pass pass) |
||||
|
{ |
||||
|
if (pass == null) |
||||
|
return; |
||||
|
|
||||
|
pass.Dispose(); |
||||
|
pass = null; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,380 @@ |
|||||
|
// Copyright (c) 2024 Nico de Poel
|
||||
|
//
|
||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
// in the Software without restriction, including without limitation the rights
|
||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||
|
// furnished to do so, subject to the following conditions:
|
||||
|
//
|
||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||
|
// copies or substantial portions of the Software.
|
||||
|
//
|
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
|
// THE SOFTWARE.
|
||||
|
|
||||
|
using System; |
||||
|
using System.Runtime.InteropServices; |
||||
|
using UnityEngine; |
||||
|
using UnityEngine.Profiling; |
||||
|
using UnityEngine.Rendering; |
||||
|
|
||||
|
namespace FidelityFX |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Base class for all of the compute passes that make up the FSR2 process.
|
||||
|
/// This loosely matches the FfxPipelineState struct from the original FSR2 codebase, wrapped in an object-oriented blanket.
|
||||
|
/// These classes are responsible for loading compute shaders, managing temporary resources, binding resources to shader kernels and dispatching said shaders.
|
||||
|
/// </summary>
|
||||
|
internal abstract class Fsr2Pass: IDisposable |
||||
|
{ |
||||
|
internal const int ShadingChangeMipLevel = 4; // This matches the FFX_FSR2_SHADING_CHANGE_MIP_LEVEL define
|
||||
|
|
||||
|
protected readonly Fsr2.ContextDescription ContextDescription; |
||||
|
protected readonly Fsr2Resources Resources; |
||||
|
protected readonly ComputeBuffer Constants; |
||||
|
|
||||
|
protected ComputeShader ComputeShader; |
||||
|
protected int KernelIndex; |
||||
|
|
||||
|
protected CustomSampler Sampler; |
||||
|
|
||||
|
protected Fsr2Pass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants) |
||||
|
{ |
||||
|
ContextDescription = contextDescription; |
||||
|
Resources = resources; |
||||
|
Constants = constants; |
||||
|
} |
||||
|
|
||||
|
public virtual void Dispose() |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) |
||||
|
{ |
||||
|
commandBuffer.BeginSample(Sampler); |
||||
|
DoScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchX, dispatchY); |
||||
|
commandBuffer.EndSample(Sampler); |
||||
|
} |
||||
|
|
||||
|
protected abstract void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY); |
||||
|
|
||||
|
protected void InitComputeShader(string passName, ComputeShader shader) |
||||
|
{ |
||||
|
InitComputeShader(passName, shader, ContextDescription.Flags); |
||||
|
} |
||||
|
|
||||
|
private void InitComputeShader(string passName, ComputeShader shader, Fsr2.InitializationFlags flags) |
||||
|
{ |
||||
|
if (shader == null) |
||||
|
{ |
||||
|
throw new MissingReferenceException($"Shader for FSR2 pass '{passName}' could not be loaded! Please ensure it is included in the project correctly."); |
||||
|
} |
||||
|
|
||||
|
ComputeShader = shader; |
||||
|
KernelIndex = ComputeShader.FindKernel("CS"); |
||||
|
Sampler = CustomSampler.Create(passName); |
||||
|
|
||||
|
bool useLut = false; |
||||
|
#if UNITY_2022_1_OR_NEWER // This will also work in 2020.3.43+ and 2021.3.14+
|
||||
|
if (SystemInfo.computeSubGroupSize == 64) |
||||
|
{ |
||||
|
useLut = true; |
||||
|
} |
||||
|
#endif
|
||||
|
|
||||
|
// This matches the permutation rules from the CreatePipeline* functions
|
||||
|
if ((flags & Fsr2.InitializationFlags.EnableHighDynamicRange) != 0) ComputeShader.EnableKeyword("FFX_FSR2_OPTION_HDR_COLOR_INPUT"); |
||||
|
if ((flags & Fsr2.InitializationFlags.EnableDisplayResolutionMotionVectors) == 0) ComputeShader.EnableKeyword("FFX_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS"); |
||||
|
if ((flags & Fsr2.InitializationFlags.EnableMotionVectorsJitterCancellation) != 0) ComputeShader.EnableKeyword("FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS"); |
||||
|
if ((flags & Fsr2.InitializationFlags.EnableDepthInverted) != 0) ComputeShader.EnableKeyword("FFX_FSR2_OPTION_INVERTED_DEPTH"); |
||||
|
if (useLut) ComputeShader.EnableKeyword("FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE"); |
||||
|
if ((flags & Fsr2.InitializationFlags.EnableFP16Usage) != 0) ComputeShader.EnableKeyword("FFX_HALF"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
internal class Fsr2ComputeLuminancePyramidPass : Fsr2Pass |
||||
|
{ |
||||
|
private readonly ComputeBuffer _spdConstants; |
||||
|
|
||||
|
public Fsr2ComputeLuminancePyramidPass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants, ComputeBuffer spdConstants) |
||||
|
: base(contextDescription, resources, constants) |
||||
|
{ |
||||
|
_spdConstants = spdConstants; |
||||
|
|
||||
|
InitComputeShader("Compute Luminance Pyramid", contextDescription.Shaders.computeLuminancePyramidPass); |
||||
|
} |
||||
|
|
||||
|
protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) |
||||
|
{ |
||||
|
ref var color = ref dispatchParams.Color; |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement); |
||||
|
|
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavSpdAtomicCount, Resources.SpdAtomicCounter); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavExposureMipLumaChange, Resources.SceneLuminance, ShadingChangeMipLevel); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavExposureMip5, Resources.SceneLuminance, 5); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavAutoExposure, Resources.AutoExposure); |
||||
|
|
||||
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf<Fsr2.UpscalerConstants>()); |
||||
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbSpd, _spdConstants, 0, Marshal.SizeOf<Fsr2.SpdConstants>()); |
||||
|
|
||||
|
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
internal class Fsr2ReconstructPreviousDepthPass : Fsr2Pass |
||||
|
{ |
||||
|
public Fsr2ReconstructPreviousDepthPass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants) |
||||
|
: base(contextDescription, resources, constants) |
||||
|
{ |
||||
|
InitComputeShader("Reconstruct & Dilate", contextDescription.Shaders.reconstructPreviousDepthPass); |
||||
|
} |
||||
|
|
||||
|
protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) |
||||
|
{ |
||||
|
ref var color = ref dispatchParams.Color; |
||||
|
ref var depth = ref dispatchParams.Depth; |
||||
|
ref var motionVectors = ref dispatchParams.MotionVectors; |
||||
|
ref var exposure = ref dispatchParams.Exposure; |
||||
|
|
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputDepth, depth.RenderTarget, depth.MipLevel, depth.SubElement); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputMotionVectors, motionVectors.RenderTarget, motionVectors.MipLevel, motionVectors.SubElement); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement); |
||||
|
|
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex]); |
||||
|
|
||||
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf<Fsr2.UpscalerConstants>()); |
||||
|
|
||||
|
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
internal class Fsr2DepthClipPass : Fsr2Pass |
||||
|
{ |
||||
|
public Fsr2DepthClipPass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants) |
||||
|
: base(contextDescription, resources, constants) |
||||
|
{ |
||||
|
InitComputeShader("Depth Clip", contextDescription.Shaders.depthClipPass); |
||||
|
} |
||||
|
|
||||
|
protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) |
||||
|
{ |
||||
|
ref var color = ref dispatchParams.Color; |
||||
|
ref var depth = ref dispatchParams.Depth; |
||||
|
ref var motionVectors = ref dispatchParams.MotionVectors; |
||||
|
ref var exposure = ref dispatchParams.Exposure; |
||||
|
ref var reactive = ref dispatchParams.Reactive; |
||||
|
ref var tac = ref dispatchParams.TransparencyAndComposition; |
||||
|
|
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputDepth, depth.RenderTarget, depth.MipLevel, depth.SubElement); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputMotionVectors, motionVectors.RenderTarget, motionVectors.MipLevel, motionVectors.SubElement); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvReactiveMask, reactive.RenderTarget, reactive.MipLevel, reactive.SubElement); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvTransparencyAndCompositionMask, tac.RenderTarget, tac.MipLevel, tac.SubElement); |
||||
|
|
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvReconstructedPrevNearestDepth, Fsr2ShaderIDs.UavReconstructedPrevNearestDepth); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex]); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvDilatedDepth, Fsr2ShaderIDs.UavDilatedDepth); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvPrevDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex ^ 1]); |
||||
|
|
||||
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf<Fsr2.UpscalerConstants>()); |
||||
|
|
||||
|
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
internal class Fsr2LockPass : Fsr2Pass |
||||
|
{ |
||||
|
public Fsr2LockPass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants) |
||||
|
: base(contextDescription, resources, constants) |
||||
|
{ |
||||
|
InitComputeShader("Create Locks", contextDescription.Shaders.lockPass); |
||||
|
} |
||||
|
|
||||
|
protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) |
||||
|
{ |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvLockInputLuma, Fsr2ShaderIDs.UavLockInputLuma); |
||||
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf<Fsr2.UpscalerConstants>()); |
||||
|
|
||||
|
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
internal class Fsr2AccumulatePass : Fsr2Pass |
||||
|
{ |
||||
|
private const string SharpeningKeyword = "FFX_FSR2_OPTION_APPLY_SHARPENING"; |
||||
|
|
||||
|
#if UNITY_2021_2_OR_NEWER
|
||||
|
private readonly LocalKeyword _sharpeningKeyword; |
||||
|
#endif
|
||||
|
|
||||
|
public Fsr2AccumulatePass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants) |
||||
|
: base(contextDescription, resources, constants) |
||||
|
{ |
||||
|
InitComputeShader("Reproject & Accumulate", contextDescription.Shaders.accumulatePass); |
||||
|
#if UNITY_2021_2_OR_NEWER
|
||||
|
_sharpeningKeyword = new LocalKeyword(ComputeShader, SharpeningKeyword); |
||||
|
#endif
|
||||
|
} |
||||
|
|
||||
|
protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) |
||||
|
{ |
||||
|
#if UNITY_2021_2_OR_NEWER
|
||||
|
if (dispatchParams.EnableSharpening) |
||||
|
commandBuffer.EnableKeyword(ComputeShader, _sharpeningKeyword); |
||||
|
else |
||||
|
commandBuffer.DisableKeyword(ComputeShader, _sharpeningKeyword); |
||||
|
#else
|
||||
|
if (dispatchParams.EnableSharpening) |
||||
|
commandBuffer.EnableShaderKeyword(SharpeningKeyword); |
||||
|
else |
||||
|
commandBuffer.DisableShaderKeyword(SharpeningKeyword); |
||||
|
#endif
|
||||
|
|
||||
|
if ((ContextDescription.Flags & Fsr2.InitializationFlags.EnableDisplayResolutionMotionVectors) == 0) |
||||
|
{ |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex]); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
ref var motionVectors = ref dispatchParams.MotionVectors; |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputMotionVectors, motionVectors.RenderTarget, motionVectors.MipLevel, motionVectors.SubElement); |
||||
|
} |
||||
|
|
||||
|
ref var exposure = ref dispatchParams.Exposure; |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement); |
||||
|
|
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvDilatedReactiveMasks, Fsr2ShaderIDs.UavDilatedReactiveMasks); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInternalUpscaled, Resources.InternalUpscaled[frameIndex ^ 1]); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvLockStatus, Resources.LockStatus[frameIndex ^ 1]); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvPreparedInputColor, Fsr2ShaderIDs.UavPreparedInputColor); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvLanczosLut, Resources.LanczosLut); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvUpscaleMaximumBiasLut, Resources.MaximumBiasLut); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvSceneLuminanceMips, Resources.SceneLuminance); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvAutoExposure, Resources.AutoExposure); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvLumaHistory, Resources.LumaHistory[frameIndex ^ 1]); |
||||
|
|
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavInternalUpscaled, Resources.InternalUpscaled[frameIndex]); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavLockStatus, Resources.LockStatus[frameIndex]); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavLumaHistory, Resources.LumaHistory[frameIndex]); |
||||
|
|
||||
|
ref var output = ref dispatchParams.Output; |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavUpscaledOutput, output.RenderTarget, output.MipLevel, output.SubElement); |
||||
|
|
||||
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf<Fsr2.UpscalerConstants>()); |
||||
|
|
||||
|
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
internal class Fsr2SharpenPass : Fsr2Pass |
||||
|
{ |
||||
|
private readonly ComputeBuffer _rcasConstants; |
||||
|
|
||||
|
public Fsr2SharpenPass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants, ComputeBuffer rcasConstants) |
||||
|
: base(contextDescription, resources, constants) |
||||
|
{ |
||||
|
_rcasConstants = rcasConstants; |
||||
|
|
||||
|
InitComputeShader("RCAS Sharpening", contextDescription.Shaders.sharpenPass); |
||||
|
} |
||||
|
|
||||
|
protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) |
||||
|
{ |
||||
|
ref var exposure = ref dispatchParams.Exposure; |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvRcasInput, Resources.InternalUpscaled[frameIndex]); |
||||
|
|
||||
|
ref var output = ref dispatchParams.Output; |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavUpscaledOutput, output.RenderTarget, output.MipLevel, output.SubElement); |
||||
|
|
||||
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf<Fsr2.UpscalerConstants>()); |
||||
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbRcas, _rcasConstants, 0, Marshal.SizeOf<Fsr2.RcasConstants>()); |
||||
|
|
||||
|
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
internal class Fsr2GenerateReactivePass : Fsr2Pass |
||||
|
{ |
||||
|
private readonly ComputeBuffer _generateReactiveConstants; |
||||
|
|
||||
|
public Fsr2GenerateReactivePass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer generateReactiveConstants) |
||||
|
: base(contextDescription, resources, null) |
||||
|
{ |
||||
|
_generateReactiveConstants = generateReactiveConstants; |
||||
|
|
||||
|
InitComputeShader("Auto-Generate Reactive Mask", contextDescription.Shaders.autoGenReactivePass); |
||||
|
} |
||||
|
|
||||
|
protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.GenerateReactiveDescription dispatchParams, int dispatchX, int dispatchY) |
||||
|
{ |
||||
|
commandBuffer.BeginSample(Sampler); |
||||
|
|
||||
|
ref var opaqueOnly = ref dispatchParams.ColorOpaqueOnly; |
||||
|
ref var color = ref dispatchParams.ColorPreUpscale; |
||||
|
ref var reactive = ref dispatchParams.OutReactive; |
||||
|
|
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvOpaqueOnly, opaqueOnly.RenderTarget, opaqueOnly.MipLevel, opaqueOnly.SubElement); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavAutoReactive, reactive.RenderTarget, reactive.MipLevel, reactive.SubElement); |
||||
|
|
||||
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbGenReactive, _generateReactiveConstants, 0, Marshal.SizeOf<Fsr2.GenerateReactiveConstants>()); |
||||
|
|
||||
|
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); |
||||
|
|
||||
|
commandBuffer.EndSample(Sampler); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
internal class Fsr2TcrAutogeneratePass : Fsr2Pass |
||||
|
{ |
||||
|
private readonly ComputeBuffer _tcrAutogenerateConstants; |
||||
|
|
||||
|
public Fsr2TcrAutogeneratePass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants, ComputeBuffer tcrAutogenerateConstants) |
||||
|
: base(contextDescription, resources, constants) |
||||
|
{ |
||||
|
_tcrAutogenerateConstants = tcrAutogenerateConstants; |
||||
|
|
||||
|
InitComputeShader("Auto-Generate Transparency & Composition Mask", contextDescription.Shaders.tcrAutoGenPass); |
||||
|
} |
||||
|
|
||||
|
protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) |
||||
|
{ |
||||
|
ref var color = ref dispatchParams.Color; |
||||
|
ref var motionVectors = ref dispatchParams.MotionVectors; |
||||
|
ref var opaqueOnly = ref dispatchParams.ColorOpaqueOnly; |
||||
|
ref var reactive = ref dispatchParams.Reactive; |
||||
|
ref var tac = ref dispatchParams.TransparencyAndComposition; |
||||
|
|
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvOpaqueOnly, opaqueOnly.RenderTarget, opaqueOnly.MipLevel, opaqueOnly.SubElement); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputMotionVectors, motionVectors.RenderTarget, motionVectors.MipLevel, motionVectors.SubElement); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvPrevColorPreAlpha, Resources.PrevPreAlpha[frameIndex ^ 1]); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvPrevColorPostAlpha, Resources.PrevPostAlpha[frameIndex ^ 1]); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvReactiveMask, reactive.RenderTarget, reactive.MipLevel, reactive.SubElement); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvTransparencyAndCompositionMask, tac.RenderTarget, tac.MipLevel, tac.SubElement); |
||||
|
|
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavAutoReactive, Resources.AutoReactive); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavAutoComposition, Resources.AutoComposition); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavPrevColorPreAlpha, Resources.PrevPreAlpha[frameIndex]); |
||||
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavPrevColorPostAlpha, Resources.PrevPostAlpha[frameIndex]); |
||||
|
|
||||
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf<Fsr2.UpscalerConstants>()); |
||||
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbGenReactive, _tcrAutogenerateConstants, 0, Marshal.SizeOf<Fsr2.GenerateReactiveConstants2>()); |
||||
|
|
||||
|
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,80 @@ |
|||||
|
// Copyright (c) 2024 Nico de Poel
|
||||
|
//
|
||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
// in the Software without restriction, including without limitation the rights
|
||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||
|
// furnished to do so, subject to the following conditions:
|
||||
|
//
|
||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||
|
// copies or substantial portions of the Software.
|
||||
|
//
|
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
|
// THE SOFTWARE.
|
||||
|
|
||||
|
using UnityEngine; |
||||
|
|
||||
|
namespace FidelityFX |
||||
|
{ |
||||
|
public static class Fsr2ShaderIDs |
||||
|
{ |
||||
|
// Shader resource views, i.e. read-only bindings
|
||||
|
public static readonly int SrvInputColor = Shader.PropertyToID("r_input_color_jittered"); |
||||
|
public static readonly int SrvOpaqueOnly = Shader.PropertyToID("r_input_opaque_only"); |
||||
|
public static readonly int SrvInputMotionVectors = Shader.PropertyToID("r_input_motion_vectors"); |
||||
|
public static readonly int SrvInputDepth = Shader.PropertyToID("r_input_depth"); |
||||
|
public static readonly int SrvInputExposure = Shader.PropertyToID("r_input_exposure"); |
||||
|
public static readonly int SrvAutoExposure = Shader.PropertyToID("r_auto_exposure"); |
||||
|
public static readonly int SrvReactiveMask = Shader.PropertyToID("r_reactive_mask"); |
||||
|
public static readonly int SrvTransparencyAndCompositionMask = Shader.PropertyToID("r_transparency_and_composition_mask"); |
||||
|
public static readonly int SrvReconstructedPrevNearestDepth = Shader.PropertyToID("r_reconstructed_previous_nearest_depth"); |
||||
|
public static readonly int SrvDilatedMotionVectors = Shader.PropertyToID("r_dilated_motion_vectors"); |
||||
|
public static readonly int SrvPrevDilatedMotionVectors = Shader.PropertyToID("r_previous_dilated_motion_vectors"); |
||||
|
public static readonly int SrvDilatedDepth = Shader.PropertyToID("r_dilatedDepth"); |
||||
|
public static readonly int SrvInternalUpscaled = Shader.PropertyToID("r_internal_upscaled_color"); |
||||
|
public static readonly int SrvLockStatus = Shader.PropertyToID("r_lock_status"); |
||||
|
public static readonly int SrvLockInputLuma = Shader.PropertyToID("r_lock_input_luma"); |
||||
|
public static readonly int SrvPreparedInputColor = Shader.PropertyToID("r_prepared_input_color"); |
||||
|
public static readonly int SrvLumaHistory = Shader.PropertyToID("r_luma_history"); |
||||
|
public static readonly int SrvRcasInput = Shader.PropertyToID("r_rcas_input"); |
||||
|
public static readonly int SrvLanczosLut = Shader.PropertyToID("r_lanczos_lut"); |
||||
|
public static readonly int SrvSceneLuminanceMips = Shader.PropertyToID("r_imgMips"); |
||||
|
public static readonly int SrvUpscaleMaximumBiasLut = Shader.PropertyToID("r_upsample_maximum_bias_lut"); |
||||
|
public static readonly int SrvDilatedReactiveMasks = Shader.PropertyToID("r_dilated_reactive_masks"); |
||||
|
public static readonly int SrvPrevColorPreAlpha = Shader.PropertyToID("r_input_prev_color_pre_alpha"); |
||||
|
public static readonly int SrvPrevColorPostAlpha = Shader.PropertyToID("r_input_prev_color_post_alpha"); |
||||
|
|
||||
|
// Unordered access views, i.e. random read/write bindings
|
||||
|
public static readonly int UavReconstructedPrevNearestDepth = Shader.PropertyToID("rw_reconstructed_previous_nearest_depth"); |
||||
|
public static readonly int UavDilatedMotionVectors = Shader.PropertyToID("rw_dilated_motion_vectors"); |
||||
|
public static readonly int UavDilatedDepth = Shader.PropertyToID("rw_dilatedDepth"); |
||||
|
public static readonly int UavInternalUpscaled = Shader.PropertyToID("rw_internal_upscaled_color"); |
||||
|
public static readonly int UavLockStatus = Shader.PropertyToID("rw_lock_status"); |
||||
|
public static readonly int UavLockInputLuma = Shader.PropertyToID("rw_lock_input_luma"); |
||||
|
public static readonly int UavNewLocks = Shader.PropertyToID("rw_new_locks"); |
||||
|
public static readonly int UavPreparedInputColor = Shader.PropertyToID("rw_prepared_input_color"); |
||||
|
public static readonly int UavLumaHistory = Shader.PropertyToID("rw_luma_history"); |
||||
|
public static readonly int UavUpscaledOutput = Shader.PropertyToID("rw_upscaled_output"); |
||||
|
public static readonly int UavExposureMipLumaChange = Shader.PropertyToID("rw_img_mip_shading_change"); |
||||
|
public static readonly int UavExposureMip5 = Shader.PropertyToID("rw_img_mip_5"); |
||||
|
public static readonly int UavDilatedReactiveMasks = Shader.PropertyToID("rw_dilated_reactive_masks"); |
||||
|
public static readonly int UavAutoExposure = Shader.PropertyToID("rw_auto_exposure"); |
||||
|
public static readonly int UavSpdAtomicCount = Shader.PropertyToID("rw_spd_global_atomic"); |
||||
|
public static readonly int UavAutoReactive = Shader.PropertyToID("rw_output_autoreactive"); |
||||
|
public static readonly int UavAutoComposition = Shader.PropertyToID("rw_output_autocomposition"); |
||||
|
public static readonly int UavPrevColorPreAlpha = Shader.PropertyToID("rw_output_prev_color_pre_alpha"); |
||||
|
public static readonly int UavPrevColorPostAlpha = Shader.PropertyToID("rw_output_prev_color_post_alpha"); |
||||
|
|
||||
|
// Constant buffer bindings
|
||||
|
public static readonly int CbFsr2 = Shader.PropertyToID("cbFSR2"); |
||||
|
public static readonly int CbSpd = Shader.PropertyToID("cbSPD"); |
||||
|
public static readonly int CbRcas = Shader.PropertyToID("cbRCAS"); |
||||
|
public static readonly int CbGenReactive = Shader.PropertyToID("cbGenerateReactive"); |
||||
|
} |
||||
|
} |
||||
@ -1,5 +1,5 @@ |
|||||
fileFormatVersion: 2 |
fileFormatVersion: 2 |
||||
guid: 661ffc6dbd7389b4da99fb9f749745de |
|
||||
|
guid: 16d16ad51c3bc2a429d3da6788f65e07 |
||||
folderAsset: yes |
folderAsset: yes |
||||
DefaultImporter: |
DefaultImporter: |
||||
externalObjects: {} |
externalObjects: {} |
||||
@ -0,0 +1,91 @@ |
|||||
|
// Copyright (c) 2024 Nico de Poel
|
||||
|
//
|
||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
// in the Software without restriction, including without limitation the rights
|
||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||
|
// furnished to do so, subject to the following conditions:
|
||||
|
//
|
||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||
|
// copies or substantial portions of the Software.
|
||||
|
//
|
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
|
// THE SOFTWARE.
|
||||
|
|
||||
|
using UnityEngine; |
||||
|
|
||||
|
namespace FidelityFX |
||||
|
{ |
||||
|
public static class Fsr3ShaderIDs |
||||
|
{ |
||||
|
// Shader resource views, i.e. read-only bindings
|
||||
|
public static readonly int SrvInputColor = Shader.PropertyToID("r_input_color_jittered"); |
||||
|
public static readonly int SrvOpaqueOnly = Shader.PropertyToID("r_input_opaque_only"); |
||||
|
public static readonly int SrvInputMotionVectors = Shader.PropertyToID("r_input_motion_vectors"); |
||||
|
public static readonly int SrvInputDepth = Shader.PropertyToID("r_input_depth"); |
||||
|
public static readonly int SrvInputExposure = Shader.PropertyToID("r_input_exposure"); |
||||
|
public static readonly int SrvFrameInfo = Shader.PropertyToID("r_frame_info"); |
||||
|
public static readonly int SrvReactiveMask = Shader.PropertyToID("r_reactive_mask"); |
||||
|
public static readonly int SrvTransparencyAndCompositionMask = Shader.PropertyToID("r_transparency_and_composition_mask"); |
||||
|
public static readonly int SrvReconstructedPrevNearestDepth = Shader.PropertyToID("r_reconstructed_previous_nearest_depth"); |
||||
|
public static readonly int SrvDilatedMotionVectors = Shader.PropertyToID("r_dilated_motion_vectors"); |
||||
|
public static readonly int SrvDilatedDepth = Shader.PropertyToID("r_dilated_depth"); |
||||
|
public static readonly int SrvInternalUpscaled = Shader.PropertyToID("r_internal_upscaled_color"); |
||||
|
public static readonly int SrvAccumulation = Shader.PropertyToID("r_accumulation"); |
||||
|
public static readonly int SrvLumaHistory = Shader.PropertyToID("r_luma_history"); |
||||
|
public static readonly int SrvRcasInput = Shader.PropertyToID("r_rcas_input"); |
||||
|
public static readonly int SrvLanczosLut = Shader.PropertyToID("r_lanczos_lut"); |
||||
|
public static readonly int SrvSpdMips = Shader.PropertyToID("r_spd_mips"); |
||||
|
public static readonly int SrvDilatedReactiveMasks = Shader.PropertyToID("r_dilated_reactive_masks"); |
||||
|
public static readonly int SrvNewLocks = Shader.PropertyToID("r_new_locks"); |
||||
|
public static readonly int SrvFarthestDepth = Shader.PropertyToID("r_farthest_depth"); |
||||
|
public static readonly int SrvFarthestDepthMip1 = Shader.PropertyToID("r_farthest_depth_mip1"); |
||||
|
public static readonly int SrvShadingChange = Shader.PropertyToID("r_shading_change"); |
||||
|
public static readonly int SrvCurrentLuma = Shader.PropertyToID("r_current_luma"); |
||||
|
public static readonly int SrvPreviousLuma = Shader.PropertyToID("r_previous_luma"); |
||||
|
public static readonly int SrvLumaInstability = Shader.PropertyToID("r_luma_instability"); |
||||
|
public static readonly int SrvPrevColorPreAlpha = Shader.PropertyToID("r_input_prev_color_pre_alpha"); |
||||
|
public static readonly int SrvPrevColorPostAlpha = Shader.PropertyToID("r_input_prev_color_post_alpha"); |
||||
|
|
||||
|
// Unordered access views, i.e. random read/write bindings
|
||||
|
public static readonly int UavReconstructedPrevNearestDepth = Shader.PropertyToID("rw_reconstructed_previous_nearest_depth"); |
||||
|
public static readonly int UavDilatedMotionVectors = Shader.PropertyToID("rw_dilated_motion_vectors"); |
||||
|
public static readonly int UavDilatedDepth = Shader.PropertyToID("rw_dilated_depth"); |
||||
|
public static readonly int UavInternalUpscaled = Shader.PropertyToID("rw_internal_upscaled_color"); |
||||
|
public static readonly int UavAccumulation = Shader.PropertyToID("rw_accumulation"); |
||||
|
public static readonly int UavLumaHistory = Shader.PropertyToID("rw_luma_history"); |
||||
|
public static readonly int UavUpscaledOutput = Shader.PropertyToID("rw_upscaled_output"); |
||||
|
public static readonly int UavDilatedReactiveMasks = Shader.PropertyToID("rw_dilated_reactive_masks"); |
||||
|
public static readonly int UavFrameInfo = Shader.PropertyToID("rw_frame_info"); |
||||
|
public static readonly int UavSpdAtomicCount = Shader.PropertyToID("rw_spd_global_atomic"); |
||||
|
public static readonly int UavNewLocks = Shader.PropertyToID("rw_new_locks"); |
||||
|
public static readonly int UavAutoReactive = Shader.PropertyToID("rw_output_autoreactive"); |
||||
|
public static readonly int UavShadingChange = Shader.PropertyToID("rw_shading_change"); |
||||
|
public static readonly int UavFarthestDepth = Shader.PropertyToID("rw_farthest_depth"); |
||||
|
public static readonly int UavFarthestDepthMip1 = Shader.PropertyToID("rw_farthest_depth_mip1"); |
||||
|
public static readonly int UavCurrentLuma = Shader.PropertyToID("rw_current_luma"); |
||||
|
public static readonly int UavLumaInstability = Shader.PropertyToID("rw_luma_instability"); |
||||
|
public static readonly int UavIntermediate = Shader.PropertyToID("rw_intermediate_fp16x1"); |
||||
|
public static readonly int UavSpdMip0 = Shader.PropertyToID("rw_spd_mip0"); |
||||
|
public static readonly int UavSpdMip1 = Shader.PropertyToID("rw_spd_mip1"); |
||||
|
public static readonly int UavSpdMip2 = Shader.PropertyToID("rw_spd_mip2"); |
||||
|
public static readonly int UavSpdMip3 = Shader.PropertyToID("rw_spd_mip3"); |
||||
|
public static readonly int UavSpdMip4 = Shader.PropertyToID("rw_spd_mip4"); |
||||
|
public static readonly int UavSpdMip5 = Shader.PropertyToID("rw_spd_mip5"); |
||||
|
public static readonly int UavAutoComposition = Shader.PropertyToID("rw_output_autocomposition"); |
||||
|
public static readonly int UavPrevColorPreAlpha = Shader.PropertyToID("rw_output_prev_color_pre_alpha"); |
||||
|
public static readonly int UavPrevColorPostAlpha = Shader.PropertyToID("rw_output_prev_color_post_alpha"); |
||||
|
|
||||
|
// Constant buffer bindings
|
||||
|
public static readonly int CbFsr3Upscaler = Shader.PropertyToID("cbFSR3Upscaler"); |
||||
|
public static readonly int CbSpd = Shader.PropertyToID("cbSPD"); |
||||
|
public static readonly int CbRcas = Shader.PropertyToID("cbRCAS"); |
||||
|
public static readonly int CbGenReactive = Shader.PropertyToID("cbGenerateReactive"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,3 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: a1e3e7c189594b94897510b4a20b8a00 |
||||
|
timeCreated: 1679060863 |
||||
@ -0,0 +1,3 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: 7ee72b891c35d614eac306ca6154b66d |
||||
|
timeCreated: 1673441954 |
||||
@ -0,0 +1,177 @@ |
|||||
|
// Copyright (c) 2024 Nico de Poel
|
||||
|
//
|
||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
// in the Software without restriction, including without limitation the rights
|
||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||
|
// furnished to do so, subject to the following conditions:
|
||||
|
//
|
||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||
|
// copies or substantial portions of the Software.
|
||||
|
//
|
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
|
// THE SOFTWARE.
|
||||
|
|
||||
|
using UnityEngine; |
||||
|
using UnityEngine.Serialization; |
||||
|
|
||||
|
namespace FidelityFX |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Scriptable object containing all shader resources required by FidelityFX Super Resolution 3 (FSR3) Upscaler.
|
||||
|
/// These can be stored in an asset file and referenced from a scene or prefab, avoiding the need to load the shaders from a Resources folder.
|
||||
|
/// </summary>
|
||||
|
[CreateAssetMenu(fileName = "FSR3 Upscaler Assets", menuName = "FidelityFX/FSR3 Upscaler Assets", order = 1103)] |
||||
|
public class Fsr3UpscalerAssets : ScriptableObject |
||||
|
{ |
||||
|
public Fsr3UpscalerShaders shaders; |
||||
|
|
||||
|
#if UNITY_EDITOR
|
||||
|
private void Reset() |
||||
|
{ |
||||
|
shaders = new Fsr3UpscalerShaders |
||||
|
{ |
||||
|
prepareInputsPass = FindComputeShader("ffx_fsr3upscaler_prepare_inputs_pass"), |
||||
|
lumaPyramidPass = FindComputeShader("ffx_fsr3upscaler_luma_pyramid_pass"), |
||||
|
shadingChangePyramidPass = FindComputeShader("ffx_fsr3upscaler_shading_change_pyramid_pass"), |
||||
|
shadingChangePass = FindComputeShader("ffx_fsr3upscaler_shading_change_pass"), |
||||
|
prepareReactivityPass = FindComputeShader("ffx_fsr3upscaler_prepare_reactivity_pass"), |
||||
|
lumaInstabilityPass = FindComputeShader("ffx_fsr3upscaler_luma_instability_pass"), |
||||
|
accumulatePass = FindComputeShader("ffx_fsr3upscaler_accumulate_pass"), |
||||
|
sharpenPass = FindComputeShader("ffx_fsr3upscaler_rcas_pass"), |
||||
|
autoGenReactivePass = FindComputeShader("ffx_fsr3upscaler_autogen_reactive_pass"), |
||||
|
tcrAutoGenPass = FindComputeShader("ffx_fsr3upscaler_tcr_autogen_pass"), |
||||
|
debugViewPass = FindComputeShader("ffx_fsr3upscaler_debug_view_pass"), |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
private static ComputeShader FindComputeShader(string name) |
||||
|
{ |
||||
|
string[] assetGuids = UnityEditor.AssetDatabase.FindAssets($"t:ComputeShader {name}"); |
||||
|
if (assetGuids == null || assetGuids.Length == 0) |
||||
|
return null; |
||||
|
|
||||
|
string assetPath = UnityEditor.AssetDatabase.GUIDToAssetPath(assetGuids[0]); |
||||
|
return UnityEditor.AssetDatabase.LoadAssetAtPath<ComputeShader>(assetPath); |
||||
|
} |
||||
|
#endif
|
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// All the compute shaders used by the FSR3 Upscaler.
|
||||
|
/// </summary>
|
||||
|
[System.Serializable] |
||||
|
public class Fsr3UpscalerShaders |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// The compute shader used by the prepare inputs pass.
|
||||
|
/// </summary>
|
||||
|
public ComputeShader prepareInputsPass; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The compute shader used by the luminance pyramid computation pass.
|
||||
|
/// </summary>
|
||||
|
public ComputeShader lumaPyramidPass; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The compute shader used by the shading change pyramid pass.
|
||||
|
/// </summary>
|
||||
|
public ComputeShader shadingChangePyramidPass; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The compute shader used by the shading change pass.
|
||||
|
/// </summary>
|
||||
|
public ComputeShader shadingChangePass; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The compute shader used by the prepare reactivity pass.
|
||||
|
/// </summary>
|
||||
|
public ComputeShader prepareReactivityPass; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The compute shader used by the luma instability pass.
|
||||
|
/// </summary>
|
||||
|
public ComputeShader lumaInstabilityPass; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The compute shader used by the accumulation pass.
|
||||
|
/// </summary>
|
||||
|
public ComputeShader accumulatePass; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The compute shader used by the RCAS sharpening pass.
|
||||
|
/// </summary>
|
||||
|
public ComputeShader sharpenPass; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The compute shader used to auto-generate a reactive mask.
|
||||
|
/// </summary>
|
||||
|
public ComputeShader autoGenReactivePass; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The compute shader used to auto-generate a transparency & composition mask.
|
||||
|
/// </summary>
|
||||
|
public ComputeShader tcrAutoGenPass; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The compute shader used to display a debug view.
|
||||
|
/// </summary>
|
||||
|
public ComputeShader debugViewPass; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Returns a copy of this class and its contents.
|
||||
|
/// </summary>
|
||||
|
public Fsr3UpscalerShaders Clone() |
||||
|
{ |
||||
|
return (Fsr3UpscalerShaders)MemberwiseClone(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Returns a copy of this class with clones of all its shaders.
|
||||
|
/// This can be useful if you're running multiple FSR3 Upscaler instances with different shader configurations.
|
||||
|
/// Be sure to clean up these clones through Dispose once you're done with them.
|
||||
|
/// </summary>
|
||||
|
public Fsr3UpscalerShaders DeepCopy() |
||||
|
{ |
||||
|
return new Fsr3UpscalerShaders |
||||
|
{ |
||||
|
prepareInputsPass = Object.Instantiate(prepareInputsPass), |
||||
|
lumaPyramidPass = Object.Instantiate(lumaPyramidPass), |
||||
|
shadingChangePyramidPass = Object.Instantiate(shadingChangePyramidPass), |
||||
|
shadingChangePass = Object.Instantiate(shadingChangePass), |
||||
|
prepareReactivityPass = Object.Instantiate(prepareReactivityPass), |
||||
|
lumaInstabilityPass = Object.Instantiate(lumaInstabilityPass), |
||||
|
accumulatePass = Object.Instantiate(accumulatePass), |
||||
|
sharpenPass = Object.Instantiate(sharpenPass), |
||||
|
autoGenReactivePass = Object.Instantiate(autoGenReactivePass), |
||||
|
tcrAutoGenPass = Object.Instantiate(tcrAutoGenPass), |
||||
|
debugViewPass = Object.Instantiate(debugViewPass), |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Destroy all the shaders within this instance.
|
||||
|
/// Use this only on clones created through DeepCopy.
|
||||
|
/// </summary>
|
||||
|
public void Dispose() |
||||
|
{ |
||||
|
Object.Destroy(prepareInputsPass); |
||||
|
Object.Destroy(lumaPyramidPass); |
||||
|
Object.Destroy(shadingChangePyramidPass); |
||||
|
Object.Destroy(shadingChangePass); |
||||
|
Object.Destroy(prepareReactivityPass); |
||||
|
Object.Destroy(lumaInstabilityPass); |
||||
|
Object.Destroy(accumulatePass); |
||||
|
Object.Destroy(sharpenPass); |
||||
|
Object.Destroy(autoGenReactivePass); |
||||
|
Object.Destroy(tcrAutoGenPass); |
||||
|
Object.Destroy(debugViewPass); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: 2dbcc608a4754d049a14a0bcce2eb40b |
||||
|
MonoImporter: |
||||
|
externalObjects: {} |
||||
|
serializedVersion: 2 |
||||
|
defaultReferences: [] |
||||
|
executionOrder: 0 |
||||
|
icon: {instanceID: 0} |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
@ -0,0 +1,11 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: d52448255f58a6a42bfcf1634f4dd1a8 |
||||
|
MonoImporter: |
||||
|
externalObjects: {} |
||||
|
serializedVersion: 2 |
||||
|
defaultReferences: [] |
||||
|
executionOrder: 0 |
||||
|
icon: {instanceID: 0} |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
@ -0,0 +1,3 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: 742dda30b4604d5488e7eeda3cf04d56 |
||||
|
timeCreated: 1673442225 |
||||
@ -0,0 +1,3 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: 9e0cf27d80d1d4d4c81450791a411ead |
||||
|
timeCreated: 1676885169 |
||||
@ -0,0 +1,245 @@ |
|||||
|
// Copyright (c) 2024 Nico de Poel
|
||||
|
//
|
||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
// in the Software without restriction, including without limitation the rights
|
||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||
|
// furnished to do so, subject to the following conditions:
|
||||
|
//
|
||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||
|
// copies or substantial portions of the Software.
|
||||
|
//
|
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
|
// THE SOFTWARE.
|
||||
|
|
||||
|
using System; |
||||
|
using UnityEngine; |
||||
|
using UnityEngine.Experimental.Rendering; |
||||
|
using UnityEngine.Rendering; |
||||
|
|
||||
|
namespace FidelityFX |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Helper class for bundling and managing persistent resources required by the FSR3 Upscaler process.
|
||||
|
/// This includes lookup tables, default fallback resources and double-buffered resources that get swapped between frames.
|
||||
|
/// </summary>
|
||||
|
internal class Fsr3UpscalerResources |
||||
|
{ |
||||
|
public Texture2D LanczosLut; |
||||
|
public Texture2D DefaultExposure; |
||||
|
public Texture2D DefaultReactive; |
||||
|
|
||||
|
public RenderTexture SpdAtomicCounter; |
||||
|
public RenderTexture SpdMips; |
||||
|
public RenderTexture DilatedVelocity; |
||||
|
public RenderTexture DilatedDepth; |
||||
|
public RenderTexture ReconstructedPrevNearestDepth; |
||||
|
public RenderTexture FrameInfo; |
||||
|
public RenderTexture AutoReactive; |
||||
|
public RenderTexture AutoComposition; |
||||
|
|
||||
|
public readonly RenderTexture[] Accumulation = new RenderTexture[2]; |
||||
|
public readonly RenderTexture[] Luma = new RenderTexture[2]; |
||||
|
public readonly RenderTexture[] InternalUpscaled = new RenderTexture[2]; |
||||
|
public readonly RenderTexture[] LumaHistory = new RenderTexture[2]; |
||||
|
public readonly RenderTexture[] PrevPreAlpha = new RenderTexture[2]; |
||||
|
public readonly RenderTexture[] PrevPostAlpha = new RenderTexture[2]; |
||||
|
|
||||
|
public void Create(Fsr3Upscaler.ContextDescription contextDescription) |
||||
|
{ |
||||
|
// Generate the data for the LUT
|
||||
|
const int lanczos2LutWidth = 128; |
||||
|
float[] lanczos2Weights = new float[lanczos2LutWidth]; |
||||
|
for (int currentLanczosWidthIndex = 0; currentLanczosWidthIndex < lanczos2LutWidth; ++currentLanczosWidthIndex) |
||||
|
{ |
||||
|
float x = 2.0f * currentLanczosWidthIndex / (lanczos2LutWidth - 1); |
||||
|
float y = Fsr3Upscaler.Lanczos2(x); |
||||
|
lanczos2Weights[currentLanczosWidthIndex] = y; |
||||
|
} |
||||
|
|
||||
|
Vector2Int maxRenderSize = contextDescription.MaxRenderSize; |
||||
|
Vector2Int maxRenderSizeDiv2 = maxRenderSize / 2; |
||||
|
|
||||
|
// Resource FSR3UPSCALER_LanczosLutData: FFX_RESOURCE_USAGE_READ_ONLY, FFX_SURFACE_FORMAT_R16_SNORM, FFX_RESOURCE_FLAGS_NONE
|
||||
|
// R16_SNorm textures are not supported by Unity on most platforms, strangely enough. So instead we use R32_SFloat and upload pre-normalized float data.
|
||||
|
LanczosLut = new Texture2D(lanczos2LutWidth, 1, GraphicsFormat.R32_SFloat, TextureCreationFlags.None) { name = "FSR3UPSCALER_LanczosLutData" }; |
||||
|
LanczosLut.SetPixelData(lanczos2Weights, 0); |
||||
|
LanczosLut.Apply(); |
||||
|
|
||||
|
// Resource FSR3UPSCALER_DefaultReactivityMask: FFX_RESOURCE_USAGE_READ_ONLY, FFX_SURFACE_FORMAT_R8_UNORM, FFX_RESOURCE_FLAGS_NONE
|
||||
|
DefaultReactive = new Texture2D(1, 1, GraphicsFormat.R8_UNorm, TextureCreationFlags.None) { name = "FSR3UPSCALER_DefaultReactivityMask" }; |
||||
|
DefaultReactive.SetPixel(0, 0, Color.clear); |
||||
|
DefaultReactive.Apply(); |
||||
|
|
||||
|
// Resource FSR3UPSCALER_DefaultExposure: FFX_RESOURCE_USAGE_READ_ONLY, FFX_SURFACE_FORMAT_R32G32_FLOAT, FFX_RESOURCE_FLAGS_NONE
|
||||
|
DefaultExposure = new Texture2D(1, 1, GraphicsFormat.R32G32_SFloat, TextureCreationFlags.None) { name = "FSR3UPSCALER_DefaultExposure" }; |
||||
|
DefaultExposure.SetPixel(0, 0, Color.clear); |
||||
|
DefaultExposure.Apply(); |
||||
|
|
||||
|
// Resource FSR3UPSCALER_SpdAtomicCounter: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32_UINT, FFX_RESOURCE_FLAGS_ALIASABLE
|
||||
|
// Despite what the original FSR3 codebase says, this resource really isn't aliasable. Resetting this counter to 0 every frame breaks auto-exposure on MacOS Metal.
|
||||
|
SpdAtomicCounter = new RenderTexture(1, 1, 0, GraphicsFormat.R32_UInt) { name = "FSR3UPSCALER_SpdAtomicCounter", enableRandomWrite = true }; |
||||
|
SpdAtomicCounter.Create(); |
||||
|
|
||||
|
// Resource FSR3UPSCALER_SpdMips: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16G16_FLOAT, FFX_RESOURCE_FLAGS_ALIASABLE
|
||||
|
// This is a rather special case: it's an aliasable resource, but because we require a mipmap chain and bind specific mip levels per shader, we can't easily use temporary RTs for this.
|
||||
|
int mipCount = 1 + Mathf.FloorToInt(Mathf.Log(Math.Max(maxRenderSizeDiv2.x, maxRenderSizeDiv2.y), 2.0f)); |
||||
|
SpdMips = new RenderTexture(maxRenderSizeDiv2.x, maxRenderSizeDiv2.y, 0, GraphicsFormat.R16G16_SFloat, mipCount) { name = "FSR3UPSCALER_SpdMips", enableRandomWrite = true, useMipMap = true, autoGenerateMips = false }; |
||||
|
SpdMips.Create(); |
||||
|
|
||||
|
// Resource FSR3UPSCALER_DilatedVelocity: FFX_RESOURCE_USAGE_RENDERTARGET | FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16G16_FLOAT, FFX_RESOURCE_FLAGS_NONE
|
||||
|
DilatedVelocity = new RenderTexture(maxRenderSize.x, maxRenderSize.y, 0, GraphicsFormat.R16G16_SFloat) { name = "FSR3UPSCALER_DilatedVelocity", enableRandomWrite = true }; |
||||
|
DilatedVelocity.Create(); |
||||
|
|
||||
|
// Resource FSR3UPSCALER_DilatedDepth: FFX_RESOURCE_USAGE_RENDERTARGET | FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32_FLOAT, FFX_RESOURCE_FLAGS_NONE
|
||||
|
DilatedDepth = new RenderTexture(maxRenderSize.x, maxRenderSize.y, 0, GraphicsFormat.R32_SFloat) { name = "FSR3UPSCALER_DilatedDepth", enableRandomWrite = true }; |
||||
|
DilatedDepth.Create(); |
||||
|
|
||||
|
// Resource FSR3UPSCALER_ReconstructedPrevNearestDepth: FFX_RESOURCE_USAGE_RENDERTARGET | FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32_UINT, FFX_RESOURCE_FLAGS_NONE
|
||||
|
ReconstructedPrevNearestDepth = new RenderTexture(maxRenderSize.x, maxRenderSize.y, 0, GraphicsFormat.R32_UInt) { name = "FSR3UPSCALER_ReconstructedPrevNearestDepth", enableRandomWrite = true }; |
||||
|
ReconstructedPrevNearestDepth.Create(); |
||||
|
|
||||
|
// Resource FSR3UPSCALER_FrameInfo: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32G32B32A32_FLOAT, FFX_RESOURCE_FLAGS_NONE
|
||||
|
FrameInfo = new RenderTexture(1, 1, 0, GraphicsFormat.R32G32B32A32_SFloat) { name = "FSR3UPSCALER_FrameInfo", enableRandomWrite = true }; |
||||
|
FrameInfo.Create(); |
||||
|
|
||||
|
// Resources FSR3UPSCALER_Accumulation1/2: FFX_RESOURCE_USAGE_RENDERTARGET | FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8_UNORM, FFX_RESOURCE_FLAGS_NONE
|
||||
|
CreateDoubleBufferedResource(Accumulation, "FSR3UPSCALER_Accumulation", maxRenderSize, GraphicsFormat.R8_UNorm); |
||||
|
|
||||
|
// Resources FSR3UPSCALER_Luma1/2: FFX_RESOURCE_USAGE_RENDERTARGET | FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16_FLOAT, FFX_RESOURCE_FLAGS_NONE
|
||||
|
CreateDoubleBufferedResource(Luma, "FSR3UPSCALER_Luma", maxRenderSize, GraphicsFormat.R16_SFloat); |
||||
|
|
||||
|
// Resources FSR3UPSCALER_InternalUpscaled1/2: FFX_RESOURCE_USAGE_RENDERTARGET | FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16G16B16A16_FLOAT, FFX_RESOURCE_FLAGS_NONE
|
||||
|
CreateDoubleBufferedResource(InternalUpscaled, "FSR3UPSCALER_InternalUpscaled", contextDescription.MaxUpscaleSize, GraphicsFormat.R16G16B16A16_SFloat); |
||||
|
|
||||
|
// Resources FSR3UPSCALER_LumaHistory1/2: FFX_RESOURCE_USAGE_RENDERTARGET | FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16G16B16A16_FLOAT, FFX_RESOURCE_FLAGS_NONE
|
||||
|
CreateDoubleBufferedResource(LumaHistory, "FSR3UPSCALER_LumaHistory", maxRenderSize, GraphicsFormat.R16G16B16A16_SFloat); |
||||
|
} |
||||
|
|
||||
|
public void CreateTcrAutogenResources(Fsr3Upscaler.ContextDescription contextDescription) |
||||
|
{ |
||||
|
// Resource FSR3UPSCALER_AutoReactive: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8_UNORM, FFX_RESOURCE_FLAGS_NONE
|
||||
|
AutoReactive = new RenderTexture(contextDescription.MaxRenderSize.x, contextDescription.MaxRenderSize.y, 0, GraphicsFormat.R8_UNorm) { name = "FSR3UPSCALER_AutoReactive", enableRandomWrite = true }; |
||||
|
AutoReactive.Create(); |
||||
|
|
||||
|
// Resource FSR3UPSCALER_AutoComposition: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8_UNORM, FFX_RESOURCE_FLAGS_NONE
|
||||
|
AutoComposition = new RenderTexture(contextDescription.MaxRenderSize.x, contextDescription.MaxRenderSize.y, 0, GraphicsFormat.R8_UNorm) { name = "FSR3UPSCALER_AutoComposition", enableRandomWrite = true }; |
||||
|
AutoComposition.Create(); |
||||
|
|
||||
|
// Resources FSR3UPSCALER_PrevPreAlpha0/1: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R11G11B10_FLOAT, FFX_RESOURCE_FLAGS_NONE
|
||||
|
CreateDoubleBufferedResource(PrevPreAlpha, "FSR3UPSCALER_PrevPreAlpha", contextDescription.MaxRenderSize, GraphicsFormat.B10G11R11_UFloatPack32); |
||||
|
|
||||
|
// Resources FSR3UPSCALER_PrevPostAlpha0/1: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R11G11B10_FLOAT, FFX_RESOURCE_FLAGS_NONE
|
||||
|
CreateDoubleBufferedResource(PrevPostAlpha, "FSR3UPSCALER_PrevPostAlpha", contextDescription.MaxRenderSize, GraphicsFormat.B10G11R11_UFloatPack32); |
||||
|
} |
||||
|
|
||||
|
// Set up shared aliasable resources, i.e. temporary render textures
|
||||
|
// These do not need to persist between frames, but they do need to be available between passes
|
||||
|
public static void CreateAliasableResources(CommandBuffer commandBuffer, Fsr3Upscaler.ContextDescription contextDescription, Fsr3Upscaler.DispatchDescription dispatchParams) |
||||
|
{ |
||||
|
Vector2Int maxUpscaleSize = contextDescription.MaxUpscaleSize; |
||||
|
Vector2Int maxRenderSize = contextDescription.MaxRenderSize; |
||||
|
Vector2Int maxRenderSizeDiv2 = maxRenderSize / 2; |
||||
|
|
||||
|
// FSR3UPSCALER_IntermediateFp16x1: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16_FLOAT, FFX_RESOURCE_FLAGS_ALIASABLE
|
||||
|
commandBuffer.GetTemporaryRT(Fsr3ShaderIDs.UavIntermediate, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R16_SFloat, 1, true); |
||||
|
|
||||
|
// FSR3UPSCALER_ShadingChange: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8_UNORM, FFX_RESOURCE_FLAGS_ALIASABLE
|
||||
|
commandBuffer.GetTemporaryRT(Fsr3ShaderIDs.UavShadingChange, maxRenderSizeDiv2.x, maxRenderSizeDiv2.y, 0, default, GraphicsFormat.R8_UNorm, 1, true); |
||||
|
|
||||
|
// FSR3UPSCALER_NewLocks: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8_UNORM, FFX_RESOURCE_FLAGS_ALIASABLE
|
||||
|
commandBuffer.GetTemporaryRT(Fsr3ShaderIDs.UavNewLocks, maxUpscaleSize.x, maxUpscaleSize.y, 0, default, GraphicsFormat.R8_UNorm, 1, true); |
||||
|
|
||||
|
// FSR3UPSCALER_FarthestDepthMip1: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16_FLOAT, FFX_RESOURCE_FLAGS_ALIASABLE
|
||||
|
commandBuffer.GetTemporaryRT(Fsr3ShaderIDs.UavFarthestDepthMip1, maxRenderSizeDiv2.x, maxRenderSizeDiv2.y, 0, default, GraphicsFormat.R16_SFloat, 1, true); |
||||
|
|
||||
|
// FSR3UPSCALER_DilatedReactiveMasks: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8G8B8A8_UNORM, FFX_RESOURCE_FLAGS_ALIASABLE
|
||||
|
commandBuffer.GetTemporaryRT(Fsr3ShaderIDs.UavDilatedReactiveMasks, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R8G8B8A8_UNorm, 1, true); |
||||
|
} |
||||
|
|
||||
|
public static void DestroyAliasableResources(CommandBuffer commandBuffer) |
||||
|
{ |
||||
|
// Release all of the aliasable resources used this frame
|
||||
|
commandBuffer.ReleaseTemporaryRT(Fsr3ShaderIDs.UavDilatedReactiveMasks); |
||||
|
commandBuffer.ReleaseTemporaryRT(Fsr3ShaderIDs.UavFarthestDepthMip1); |
||||
|
commandBuffer.ReleaseTemporaryRT(Fsr3ShaderIDs.UavNewLocks); |
||||
|
commandBuffer.ReleaseTemporaryRT(Fsr3ShaderIDs.UavShadingChange); |
||||
|
commandBuffer.ReleaseTemporaryRT(Fsr3ShaderIDs.UavIntermediate); |
||||
|
} |
||||
|
|
||||
|
private static void CreateDoubleBufferedResource(RenderTexture[] resource, string name, Vector2Int size, GraphicsFormat format) |
||||
|
{ |
||||
|
for (int i = 0; i < 2; ++i) |
||||
|
{ |
||||
|
resource[i] = new RenderTexture(size.x, size.y, 0, format) { name = name + (i + 1), enableRandomWrite = true }; |
||||
|
resource[i].Create(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public void Destroy() |
||||
|
{ |
||||
|
DestroyTcrAutogenResources(); |
||||
|
|
||||
|
DestroyResource(LumaHistory); |
||||
|
DestroyResource(InternalUpscaled); |
||||
|
DestroyResource(Luma); |
||||
|
DestroyResource(Accumulation); |
||||
|
|
||||
|
DestroyResource(ref FrameInfo); |
||||
|
DestroyResource(ref ReconstructedPrevNearestDepth); |
||||
|
DestroyResource(ref DilatedDepth); |
||||
|
DestroyResource(ref DilatedVelocity); |
||||
|
DestroyResource(ref SpdMips); |
||||
|
DestroyResource(ref SpdAtomicCounter); |
||||
|
|
||||
|
DestroyResource(ref DefaultReactive); |
||||
|
DestroyResource(ref DefaultExposure); |
||||
|
DestroyResource(ref LanczosLut); |
||||
|
} |
||||
|
|
||||
|
public void DestroyTcrAutogenResources() |
||||
|
{ |
||||
|
DestroyResource(PrevPostAlpha); |
||||
|
DestroyResource(PrevPreAlpha); |
||||
|
DestroyResource(ref AutoComposition); |
||||
|
DestroyResource(ref AutoReactive); |
||||
|
} |
||||
|
|
||||
|
private static void DestroyResource(ref Texture2D resource) |
||||
|
{ |
||||
|
if (resource == null) |
||||
|
return; |
||||
|
|
||||
|
#if UNITY_EDITOR
|
||||
|
if (Application.isPlaying && !UnityEditor.EditorApplication.isPaused) |
||||
|
UnityEngine.Object.Destroy(resource); |
||||
|
else |
||||
|
UnityEngine.Object.DestroyImmediate(resource); |
||||
|
#else
|
||||
|
UnityEngine.Object.Destroy(resource); |
||||
|
#endif
|
||||
|
resource = null; |
||||
|
} |
||||
|
|
||||
|
private static void DestroyResource(ref RenderTexture resource) |
||||
|
{ |
||||
|
if (resource == null) |
||||
|
return; |
||||
|
|
||||
|
resource.Release(); |
||||
|
resource = null; |
||||
|
} |
||||
|
|
||||
|
private static void DestroyResource(RenderTexture[] resource) |
||||
|
{ |
||||
|
for (int i = 0; i < resource.Length; ++i) |
||||
|
DestroyResource(ref resource[i]); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,3 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: 6749e0e55c9ac5a4f869bc73dfbb7163 |
||||
|
timeCreated: 1677236102 |
||||
@ -0,0 +1,14 @@ |
|||||
|
{ |
||||
|
"name": "FidelityFX.FSR", |
||||
|
"rootNamespace": "FidelityFX", |
||||
|
"references": [], |
||||
|
"includePlatforms": [], |
||||
|
"excludePlatforms": [], |
||||
|
"allowUnsafeCode": false, |
||||
|
"overrideReferences": false, |
||||
|
"precompiledReferences": [], |
||||
|
"autoReferenced": true, |
||||
|
"defineConstraints": [], |
||||
|
"versionDefines": [], |
||||
|
"noEngineReferences": false |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: eb1f729ceec147d4a813e8e75b65dc12 |
||||
|
AssemblyDefinitionImporter: |
||||
|
externalObjects: {} |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
@ -1,5 +1,5 @@ |
|||||
fileFormatVersion: 2 |
fileFormatVersion: 2 |
||||
guid: f1c65c7377a34fe41beb57484d87a08b |
|
||||
|
guid: af3a6660394230a4bb247808bbefe9f4 |
||||
folderAsset: yes |
folderAsset: yes |
||||
DefaultImporter: |
DefaultImporter: |
||||
externalObjects: {} |
externalObjects: {} |
||||
@ -0,0 +1,41 @@ |
|||||
|
// Copyright (c) 2024 Nico de Poel |
||||
|
// |
||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
// of this software and associated documentation files (the "Software"), to deal |
||||
|
// in the Software without restriction, including without limitation the rights |
||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
// copies of the Software, and to permit persons to whom the Software is |
||||
|
// furnished to do so, subject to the following conditions: |
||||
|
// |
||||
|
// The above copyright notice and this permission notice shall be included in all |
||||
|
// copies or substantial portions of the Software. |
||||
|
// |
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
|
// THE SOFTWARE. |
||||
|
|
||||
|
#pragma kernel CS |
||||
|
|
||||
|
#pragma multi_compile_local __ FFX_HALF |
||||
|
#pragma multi_compile_local __ FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE |
||||
|
#pragma multi_compile_local __ FFX_FSR2_OPTION_HDR_COLOR_INPUT |
||||
|
#pragma multi_compile_local __ FFX_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS |
||||
|
#pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS |
||||
|
#pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH |
||||
|
#pragma multi_compile_local __ FFX_FSR2_OPTION_APPLY_SHARPENING |
||||
|
|
||||
|
#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY |
||||
|
|
||||
|
#include "ffx_fsr_unity_common.cginc" |
||||
|
|
||||
|
// Ensure the correct value is defined for this keyword, as it is used to select one of multiple sampler functions |
||||
|
#ifdef FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE |
||||
|
#undef FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE |
||||
|
#define FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE 1 |
||||
|
#endif |
||||
|
|
||||
|
#include "shaders/ffx_fsr2_accumulate_pass.hlsl" |
||||
@ -0,0 +1,8 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: 7e791d69a5be98247a93b63897bc64df |
||||
|
ComputeShaderImporter: |
||||
|
externalObjects: {} |
||||
|
preprocessorOverride: 0 |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
@ -0,0 +1,8 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: 67ee1b32ca5e4234db9f06984c783dee |
||||
|
ComputeShaderImporter: |
||||
|
externalObjects: {} |
||||
|
preprocessorOverride: 0 |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
@ -0,0 +1,8 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: 04c3480675e29a340808141e68d4cc8b |
||||
|
ComputeShaderImporter: |
||||
|
externalObjects: {} |
||||
|
preprocessorOverride: 0 |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
@ -0,0 +1,32 @@ |
|||||
|
// Copyright (c) 2024 Nico de Poel |
||||
|
// |
||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
// of this software and associated documentation files (the "Software"), to deal |
||||
|
// in the Software without restriction, including without limitation the rights |
||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
// copies of the Software, and to permit persons to whom the Software is |
||||
|
// furnished to do so, subject to the following conditions: |
||||
|
// |
||||
|
// The above copyright notice and this permission notice shall be included in all |
||||
|
// copies or substantial portions of the Software. |
||||
|
// |
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
|
// THE SOFTWARE. |
||||
|
|
||||
|
#pragma kernel CS |
||||
|
|
||||
|
#pragma multi_compile_local __ FFX_HALF |
||||
|
#pragma multi_compile_local __ FFX_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS |
||||
|
#pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS |
||||
|
#pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH |
||||
|
|
||||
|
#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY |
||||
|
|
||||
|
#include "ffx_fsr_unity_common.cginc" |
||||
|
|
||||
|
#include "shaders/ffx_fsr2_depth_clip_pass.hlsl" |
||||
@ -0,0 +1,8 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: b207de122e2c4b844b89dcd7c5c77c80 |
||||
|
ComputeShaderImporter: |
||||
|
externalObjects: {} |
||||
|
preprocessorOverride: 0 |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
@ -0,0 +1,32 @@ |
|||||
|
// Copyright (c) 2024 Nico de Poel |
||||
|
// |
||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
// of this software and associated documentation files (the "Software"), to deal |
||||
|
// in the Software without restriction, including without limitation the rights |
||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
// copies of the Software, and to permit persons to whom the Software is |
||||
|
// furnished to do so, subject to the following conditions: |
||||
|
// |
||||
|
// The above copyright notice and this permission notice shall be included in all |
||||
|
// copies or substantial portions of the Software. |
||||
|
// |
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
|
// THE SOFTWARE. |
||||
|
|
||||
|
#pragma kernel CS |
||||
|
|
||||
|
#pragma multi_compile_local __ FFX_HALF |
||||
|
#pragma multi_compile_local __ FFX_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS |
||||
|
#pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS |
||||
|
#pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH |
||||
|
|
||||
|
#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY |
||||
|
|
||||
|
#include "ffx_fsr_unity_common.cginc" |
||||
|
|
||||
|
#include "shaders/ffx_fsr2_lock_pass.hlsl" |
||||
@ -0,0 +1,8 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: 20b7864a7e7258946aaf0f1996febad3 |
||||
|
ComputeShaderImporter: |
||||
|
externalObjects: {} |
||||
|
preprocessorOverride: 0 |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
@ -0,0 +1,31 @@ |
|||||
|
// Copyright (c) 2024 Nico de Poel |
||||
|
// |
||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
// of this software and associated documentation files (the "Software"), to deal |
||||
|
// in the Software without restriction, including without limitation the rights |
||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
// copies of the Software, and to permit persons to whom the Software is |
||||
|
// furnished to do so, subject to the following conditions: |
||||
|
// |
||||
|
// The above copyright notice and this permission notice shall be included in all |
||||
|
// copies or substantial portions of the Software. |
||||
|
// |
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
|
// THE SOFTWARE. |
||||
|
|
||||
|
#pragma kernel CS |
||||
|
|
||||
|
#pragma multi_compile_local __ FFX_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS |
||||
|
#pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS |
||||
|
#pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH |
||||
|
|
||||
|
#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY |
||||
|
|
||||
|
#include "ffx_fsr_unity_common.cginc" |
||||
|
|
||||
|
#include "shaders/ffx_fsr2_rcas_pass.hlsl" |
||||
@ -0,0 +1,8 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: 40815651f0f5d994cb73da9816a7ff9b |
||||
|
ComputeShaderImporter: |
||||
|
externalObjects: {} |
||||
|
preprocessorOverride: 0 |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
@ -0,0 +1,33 @@ |
|||||
|
// Copyright (c) 2024 Nico de Poel |
||||
|
// |
||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
// of this software and associated documentation files (the "Software"), to deal |
||||
|
// in the Software without restriction, including without limitation the rights |
||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
// copies of the Software, and to permit persons to whom the Software is |
||||
|
// furnished to do so, subject to the following conditions: |
||||
|
// |
||||
|
// The above copyright notice and this permission notice shall be included in all |
||||
|
// copies or substantial portions of the Software. |
||||
|
// |
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
|
// THE SOFTWARE. |
||||
|
|
||||
|
#pragma kernel CS |
||||
|
|
||||
|
#pragma multi_compile_local __ FFX_HALF |
||||
|
#pragma multi_compile_local __ FFX_FSR2_OPTION_HDR_COLOR_INPUT |
||||
|
#pragma multi_compile_local __ FFX_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS |
||||
|
#pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS |
||||
|
#pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH |
||||
|
|
||||
|
#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY |
||||
|
|
||||
|
#include "ffx_fsr_unity_common.cginc" |
||||
|
|
||||
|
#include "shaders/ffx_fsr2_reconstruct_previous_depth_pass.hlsl" |
||||
@ -0,0 +1,8 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: 5060dfafe45aa67459629186ceb7464e |
||||
|
ComputeShaderImporter: |
||||
|
externalObjects: {} |
||||
|
preprocessorOverride: 0 |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
@ -0,0 +1,32 @@ |
|||||
|
// Copyright (c) 2024 Nico de Poel |
||||
|
// |
||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
// of this software and associated documentation files (the "Software"), to deal |
||||
|
// in the Software without restriction, including without limitation the rights |
||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
// copies of the Software, and to permit persons to whom the Software is |
||||
|
// furnished to do so, subject to the following conditions: |
||||
|
// |
||||
|
// The above copyright notice and this permission notice shall be included in all |
||||
|
// copies or substantial portions of the Software. |
||||
|
// |
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
|
// THE SOFTWARE. |
||||
|
|
||||
|
#pragma kernel CS |
||||
|
|
||||
|
#pragma multi_compile_local __ FFX_HALF |
||||
|
#pragma multi_compile_local __ FFX_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS |
||||
|
#pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS |
||||
|
#pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH |
||||
|
|
||||
|
#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY |
||||
|
|
||||
|
#include "ffx_fsr_unity_common.cginc" |
||||
|
|
||||
|
#include "shaders/ffx_fsr2_tcr_autogen_pass.hlsl" |
||||
@ -0,0 +1,8 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: f8b1c27fb6a544b43b38903592240500 |
||||
|
ComputeShaderImporter: |
||||
|
externalObjects: {} |
||||
|
preprocessorOverride: 0 |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
@ -0,0 +1,29 @@ |
|||||
|
// Copyright (c) 2024 Nico de Poel |
||||
|
// |
||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
// of this software and associated documentation files (the "Software"), to deal |
||||
|
// in the Software without restriction, including without limitation the rights |
||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
// copies of the Software, and to permit persons to whom the Software is |
||||
|
// furnished to do so, subject to the following conditions: |
||||
|
// |
||||
|
// The above copyright notice and this permission notice shall be included in all |
||||
|
// copies or substantial portions of the Software. |
||||
|
// |
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
|
// THE SOFTWARE. |
||||
|
|
||||
|
#pragma kernel CS |
||||
|
|
||||
|
#pragma multi_compile_local __ FFX_HALF |
||||
|
|
||||
|
#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY |
||||
|
|
||||
|
#include "ffx_fsr_unity_common.cginc" |
||||
|
|
||||
|
#include "shaders/ffx_fsr3upscaler_debug_view_pass.hlsl" |
||||
@ -0,0 +1,8 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: cb24a71d54164c54eb5e86839acd48c5 |
||||
|
ComputeShaderImporter: |
||||
|
externalObjects: {} |
||||
|
preprocessorOverride: 0 |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
@ -0,0 +1,29 @@ |
|||||
|
// Copyright (c) 2024 Nico de Poel |
||||
|
// |
||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
// of this software and associated documentation files (the "Software"), to deal |
||||
|
// in the Software without restriction, including without limitation the rights |
||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
// copies of the Software, and to permit persons to whom the Software is |
||||
|
// furnished to do so, subject to the following conditions: |
||||
|
// |
||||
|
// The above copyright notice and this permission notice shall be included in all |
||||
|
// copies or substantial portions of the Software. |
||||
|
// |
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
|
// THE SOFTWARE. |
||||
|
|
||||
|
#pragma kernel CS |
||||
|
|
||||
|
#pragma multi_compile_local __ FFX_HALF |
||||
|
|
||||
|
#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY |
||||
|
|
||||
|
#include "ffx_fsr_unity_common.cginc" |
||||
|
|
||||
|
#include "shaders/ffx_fsr3upscaler_luma_instability_pass.hlsl" |
||||
@ -0,0 +1,29 @@ |
|||||
|
// Copyright (c) 2024 Nico de Poel |
||||
|
// |
||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
// of this software and associated documentation files (the "Software"), to deal |
||||
|
// in the Software without restriction, including without limitation the rights |
||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
// copies of the Software, and to permit persons to whom the Software is |
||||
|
// furnished to do so, subject to the following conditions: |
||||
|
// |
||||
|
// The above copyright notice and this permission notice shall be included in all |
||||
|
// copies or substantial portions of the Software. |
||||
|
// |
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
|
// THE SOFTWARE. |
||||
|
|
||||
|
#pragma kernel CS |
||||
|
|
||||
|
#pragma multi_compile_local __ FFX_HALF |
||||
|
|
||||
|
#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY |
||||
|
|
||||
|
#include "ffx_fsr_unity_common.cginc" |
||||
|
|
||||
|
#include "shaders/ffx_fsr3upscaler_prepare_reactivity_pass.hlsl" |
||||
@ -0,0 +1,29 @@ |
|||||
|
// Copyright (c) 2024 Nico de Poel |
||||
|
// |
||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
// of this software and associated documentation files (the "Software"), to deal |
||||
|
// in the Software without restriction, including without limitation the rights |
||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
// copies of the Software, and to permit persons to whom the Software is |
||||
|
// furnished to do so, subject to the following conditions: |
||||
|
// |
||||
|
// The above copyright notice and this permission notice shall be included in all |
||||
|
// copies or substantial portions of the Software. |
||||
|
// |
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
|
// THE SOFTWARE. |
||||
|
|
||||
|
#pragma kernel CS |
||||
|
|
||||
|
#pragma multi_compile_local __ FFX_HALF |
||||
|
|
||||
|
#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY |
||||
|
|
||||
|
#include "ffx_fsr_unity_common.cginc" |
||||
|
|
||||
|
#include "shaders/ffx_fsr3upscaler_shading_change_pass.hlsl" |
||||
@ -0,0 +1,8 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: 9a2bff2f97619ed4989d9b0577ba0641 |
||||
|
ComputeShaderImporter: |
||||
|
externalObjects: {} |
||||
|
preprocessorOverride: 0 |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
@ -0,0 +1,32 @@ |
|||||
|
// Copyright (c) 2024 Nico de Poel |
||||
|
// |
||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
// of this software and associated documentation files (the "Software"), to deal |
||||
|
// in the Software without restriction, including without limitation the rights |
||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
// copies of the Software, and to permit persons to whom the Software is |
||||
|
// furnished to do so, subject to the following conditions: |
||||
|
// |
||||
|
// The above copyright notice and this permission notice shall be included in all |
||||
|
// copies or substantial portions of the Software. |
||||
|
// |
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
|
// THE SOFTWARE. |
||||
|
|
||||
|
#pragma kernel CS |
||||
|
|
||||
|
#pragma multi_compile_local __ FFX_HALF |
||||
|
|
||||
|
#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY |
||||
|
|
||||
|
#include "ffx_fsr_unity_common.cginc" |
||||
|
|
||||
|
// Wave operations require shader model 6.0; this can only be enabled when using DXC on D3D12 |
||||
|
#define FFX_SPD_NO_WAVE_OPERATIONS |
||||
|
|
||||
|
#include "shaders/ffx_fsr3upscaler_shading_change_pyramid_pass.hlsl" |
||||
@ -0,0 +1,8 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: 251e663738905fa4d8817001682d802f |
||||
|
ComputeShaderImporter: |
||||
|
externalObjects: {} |
||||
|
preprocessorOverride: 0 |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
@ -1,5 +1,5 @@ |
|||||
fileFormatVersion: 2 |
fileFormatVersion: 2 |
||||
guid: 8364d4f86c613ec4d999d062f5f773b8 |
|
||||
|
guid: c3f8af1cab72f0e46acba11c5820d923 |
||||
folderAsset: yes |
folderAsset: yes |
||||
DefaultImporter: |
DefaultImporter: |
||||
externalObjects: {} |
externalObjects: {} |
||||
Some files were not shown because too many files changed in this diff
Write
Preview
Loading…
Cancel
Save
Reference in new issue