mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 17:29:18 +02:00
Some renaming
This commit is contained in:
77
betterRenderer/thirdparty/fsr2/include/FidelityFX/gpu/cacao/CMakeCompileCACAOShaders.txt
vendored
Normal file
77
betterRenderer/thirdparty/fsr2/include/FidelityFX/gpu/cacao/CMakeCompileCACAOShaders.txt
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
# This file is part of the FidelityFX SDK.
|
||||
#
|
||||
# Copyright (C) 2024 Advanced Micro Devices, Inc.
|
||||
#
|
||||
# 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.
|
||||
|
||||
set(CACAO_BASE_ARGS
|
||||
-reflection -deps=gcc -DFFX_GPU=1)
|
||||
|
||||
set(CACAO_PERMUTATION_ARGS
|
||||
-DFFX_CACAO_OPTION_APPLY_SMART={0,1}
|
||||
)
|
||||
|
||||
set(CACAO_INCLUDE_ARGS
|
||||
"${FFX_GPU_PATH}"
|
||||
"${FFX_GPU_PATH}/cacao")
|
||||
|
||||
if (NOT CACAO_SHADER_EXT)
|
||||
set(CACAO_SHADER_EXT *)
|
||||
endif()
|
||||
|
||||
file(GLOB CACAO_SHADERS
|
||||
"shaders/cacao/ffx_cacao_apply_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_apply_non_smart_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_apply_non_smart_half_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_clear_load_counter_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_edge_sensitive_blur_1_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_edge_sensitive_blur_2_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_edge_sensitive_blur_3_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_edge_sensitive_blur_4_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_edge_sensitive_blur_5_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_edge_sensitive_blur_6_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_edge_sensitive_blur_7_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_edge_sensitive_blur_8_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_generate_importance_map_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_generate_importance_map_a_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_generate_importance_map_b_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_generate_q0_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_generate_q1_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_generate_q2_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_generate_q3_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_generate_q3_base_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_prepare_downsampled_depths_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_prepare_downsampled_depths_and_mips_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_prepare_downsampled_depths_half_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_prepare_downsampled_normals_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_prepare_downsampled_normals_from_input_normals_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_prepare_native_depths_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_prepare_native_depths_and_mips_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_prepare_native_depths_half_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_prepare_native_normals_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_prepare_native_normals_from_input_normals_pass.${CACAO_SHADER_EXT}"
|
||||
"shaders/cacao/ffx_cacao_upscale_bilateral_5x5_pass.${CACAO_SHADER_EXT}")
|
||||
|
||||
compile_shaders_with_depfile(
|
||||
"${FFX_SC_EXECUTABLE}"
|
||||
"${CACAO_BASE_ARGS}" "${CACAO_API_BASE_ARGS}"
|
||||
"${CACAO_PERMUTATION_ARGS}" "${CACAO_INCLUDE_ARGS}"
|
||||
"${CACAO_SHADERS}" "${FFX_PASS_SHADER_OUTPUT_PATH}" CACAO_PERMUTATION_OUTPUTS)
|
||||
|
||||
add_shader_output("${CACAO_PERMUTATION_OUTPUTS}")
|
||||
105
betterRenderer/thirdparty/fsr2/include/FidelityFX/gpu/cacao/ffx_cacao_apply.h
vendored
Normal file
105
betterRenderer/thirdparty/fsr2/include/FidelityFX/gpu/cacao/ffx_cacao_apply.h
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
// This file is part of the FidelityFX SDK.
|
||||
//
|
||||
// Copyright (C) 2024 Advanced Micro Devices, Inc.
|
||||
//
|
||||
// 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.
|
||||
|
||||
#include "ffx_core.h"
|
||||
#include "ffx_cacao_defines.h"
|
||||
#include "ffx_cacao_utils.h"
|
||||
|
||||
void FFX_CACAO_Apply(FfxUInt32x2 coord)
|
||||
{
|
||||
FfxFloat32 ao;
|
||||
FfxFloat32x2 inPos = coord;
|
||||
FfxUInt32x2 pixPos = coord;
|
||||
FfxUInt32x2 pixPosHalf = pixPos / FfxUInt32x2(2, 2);
|
||||
|
||||
// calculate index in the four deinterleaved source array texture
|
||||
FfxInt32 mx = FfxInt32(pixPos.x % 2);
|
||||
FfxInt32 my = FfxInt32(pixPos.y % 2);
|
||||
FfxInt32 ic = mx + my * 2; // center index
|
||||
FfxInt32 ih = (1 - mx) + my * 2; // neighbouring, horizontal
|
||||
FfxInt32 iv = mx + (1 - my) * 2; // neighbouring, vertical
|
||||
FfxInt32 id = (1 - mx) + (1 - my) * 2; // diagonal
|
||||
|
||||
FfxFloat32x2 centerVal = FFX_CACAO_Apply_LoadSSAOPass(FfxInt32x2(pixPosHalf), ic);
|
||||
|
||||
ao = centerVal.x;
|
||||
|
||||
#if 1 // change to 0 if you want to disable last pass high-res blur (for debugging purposes, etc.)
|
||||
FfxFloat32x4 edgesLRTB = FFX_CACAO_UnpackEdges(centerVal.y);
|
||||
|
||||
// return 1.0 - FfxFloat32x4( edgesLRTB.x, edgesLRTB.y * 0.5 + edgesLRTB.w * 0.5, edgesLRTB.z, 0.0 ); // debug show edges
|
||||
|
||||
// convert index shifts to sampling offsets
|
||||
FfxFloat32 fmx = FfxFloat32(mx);
|
||||
FfxFloat32 fmy = FfxFloat32(my);
|
||||
|
||||
// in case of an edge, push sampling offsets away from the edge (towards pixel center)
|
||||
FfxFloat32 fmxe = (edgesLRTB.y - edgesLRTB.x);
|
||||
FfxFloat32 fmye = (edgesLRTB.w - edgesLRTB.z);
|
||||
|
||||
// calculate final sampling offsets and sample using bilinear filter
|
||||
FfxFloat32x2 uvH = (inPos.xy + FfxFloat32x2(fmx + fmxe - 0.5, 0.5 - fmy)) * 0.5 * SSAOBufferInverseDimensions();
|
||||
FfxFloat32 aoH = FFX_CACAO_Apply_SampleSSAOUVPass(uvH, ih);
|
||||
FfxFloat32x2 uvV = (inPos.xy + FfxFloat32x2(0.5 - fmx, fmy - 0.5 + fmye)) * 0.5 * SSAOBufferInverseDimensions();
|
||||
FfxFloat32 aoV = FFX_CACAO_Apply_SampleSSAOUVPass(uvV, iv);
|
||||
FfxFloat32x2 uvD = (inPos.xy + FfxFloat32x2(fmx - 0.5 + fmxe, fmy - 0.5 + fmye)) * 0.5 * SSAOBufferInverseDimensions();
|
||||
FfxFloat32 aoD = FFX_CACAO_Apply_SampleSSAOUVPass(uvD, id);
|
||||
|
||||
// reduce weight for samples near edge - if the edge is on both sides, weight goes to 0
|
||||
FfxFloat32x4 blendWeights;
|
||||
blendWeights.x = 1.0;
|
||||
blendWeights.y = (edgesLRTB.x + edgesLRTB.y) * 0.5;
|
||||
blendWeights.z = (edgesLRTB.z + edgesLRTB.w) * 0.5;
|
||||
blendWeights.w = (blendWeights.y + blendWeights.z) * 0.5;
|
||||
|
||||
// calculate weighted average
|
||||
FfxFloat32 blendWeightsSum = dot(blendWeights, FfxFloat32x4(1.0, 1.0, 1.0, 1.0));
|
||||
ao = dot(FfxFloat32x4(ao, aoH, aoV, aoD), blendWeights) / blendWeightsSum;
|
||||
#endif
|
||||
ao.x = pow(ao.x, 2.2);
|
||||
FFX_CACAO_Apply_StoreOutput(FfxInt32x2(coord), ao.x);
|
||||
}
|
||||
|
||||
|
||||
// edge-ignorant blur & apply (for the lowest quality level 0)
|
||||
void FFX_CACAO_NonSmartApply(FfxUInt32x2 tid)
|
||||
{
|
||||
FfxFloat32x2 inUV = FfxFloat32x2(tid) * OutputBufferInverseDimensions();
|
||||
FfxFloat32 a = FFX_CACAO_Apply_SampleSSAOUVPass(inUV.xy, 0);
|
||||
FfxFloat32 b = FFX_CACAO_Apply_SampleSSAOUVPass(inUV.xy, 1);
|
||||
FfxFloat32 c = FFX_CACAO_Apply_SampleSSAOUVPass(inUV.xy, 2);
|
||||
FfxFloat32 d = FFX_CACAO_Apply_SampleSSAOUVPass(inUV.xy, 3);
|
||||
FfxFloat32 avg = (a + b + c + d) * 0.25f;
|
||||
|
||||
FFX_CACAO_Apply_StoreOutput(FfxInt32x2(tid), avg);
|
||||
}
|
||||
|
||||
// edge-ignorant blur & apply, skipping half pixels in checkerboard pattern (for the Lowest quality level 0 and Settings::SkipHalfPixelsOnLowQualityLevel == true )
|
||||
void FFX_CACAO_NonSmartHalfApply(FfxUInt32x2 tid)
|
||||
{
|
||||
FfxFloat32x2 inUV = FfxFloat32x2(tid) * OutputBufferInverseDimensions();
|
||||
FfxFloat32 a = FFX_CACAO_Apply_SampleSSAOUVPass(inUV.xy, 0);
|
||||
FfxFloat32 d = FFX_CACAO_Apply_SampleSSAOUVPass(inUV.xy, 3);
|
||||
FfxFloat32 avg = (a + d) * 0.5f;
|
||||
|
||||
FFX_CACAO_Apply_StoreOutput(FfxInt32x2(tid), avg);
|
||||
}
|
||||
774
betterRenderer/thirdparty/fsr2/include/FidelityFX/gpu/cacao/ffx_cacao_callbacks_glsl.h
vendored
Normal file
774
betterRenderer/thirdparty/fsr2/include/FidelityFX/gpu/cacao/ffx_cacao_callbacks_glsl.h
vendored
Normal file
@@ -0,0 +1,774 @@
|
||||
// This file is part of the FidelityFX SDK.
|
||||
//
|
||||
// Copyright (C) 2024 Advanced Micro Devices, Inc.
|
||||
//
|
||||
// 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.
|
||||
|
||||
#include "ffx_cacao_resources.h"
|
||||
|
||||
#if defined(FFX_GPU)
|
||||
#include "ffx_core.h"
|
||||
|
||||
#ifndef FFX_PREFER_WAVE64
|
||||
#define FFX_PREFER_WAVE64
|
||||
#endif // #ifndef FFX_PREFER_WAVE64
|
||||
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
struct FFX_CACAO_Constants
|
||||
{
|
||||
FfxFloat32x2 DepthUnpackConsts;
|
||||
FfxFloat32x2 CameraTanHalfFOV;
|
||||
|
||||
FfxFloat32x2 NDCToViewMul;
|
||||
FfxFloat32x2 NDCToViewAdd;
|
||||
|
||||
FfxFloat32x2 DepthBufferUVToViewMul;
|
||||
FfxFloat32x2 DepthBufferUVToViewAdd;
|
||||
|
||||
FfxFloat32 EffectRadius; // world (viewspace) maximum size of the shadow
|
||||
FfxFloat32 EffectShadowStrength; // global strength of the effect (0 - 5)
|
||||
FfxFloat32 EffectShadowPow;
|
||||
FfxFloat32 EffectShadowClamp;
|
||||
|
||||
FfxFloat32 EffectFadeOutMul; // effect fade out from distance (ex. 25)
|
||||
FfxFloat32 EffectFadeOutAdd; // effect fade out to distance (ex. 100)
|
||||
FfxFloat32 EffectHorizonAngleThreshold; // limit errors on slopes and caused by insufficient geometry tessellation (0.05 to 0.5)
|
||||
FfxFloat32 EffectSamplingRadiusNearLimitRec; // if viewspace pixel closer than this, don't enlarge shadow sampling radius anymore (makes no sense to grow beyond some distance, not enough samples to cover everything, so just limit the shadow growth; could be SSAOSettingsFadeOutFrom * 0.1 or less)
|
||||
|
||||
FfxFloat32 DepthPrecisionOffsetMod;
|
||||
FfxFloat32 NegRecEffectRadius; // -1.0 / EffectRadius
|
||||
FfxFloat32 LoadCounterAvgDiv; // 1.0 / ( halfDepthMip[SSAO_DEPTH_MIP_LEVELS-1].sizeX * halfDepthMip[SSAO_DEPTH_MIP_LEVELS-1].sizeY )
|
||||
FfxFloat32 AdaptiveSampleCountLimit;
|
||||
|
||||
FfxFloat32 InvSharpness;
|
||||
FfxInt32 BlurNumPasses;
|
||||
FfxFloat32 BilateralSigmaSquared;
|
||||
FfxFloat32 BilateralSimilarityDistanceSigma;
|
||||
|
||||
FfxFloat32x4 PatternRotScaleMatrices[4][5];
|
||||
|
||||
FfxFloat32 NormalsUnpackMul;
|
||||
FfxFloat32 NormalsUnpackAdd;
|
||||
FfxFloat32 DetailAOStrength;
|
||||
FfxFloat32 Dummy0;
|
||||
|
||||
FfxFloat32x2 SSAOBufferDimensions;
|
||||
FfxFloat32x2 SSAOBufferInverseDimensions;
|
||||
|
||||
FfxFloat32x2 DepthBufferDimensions;
|
||||
FfxFloat32x2 DepthBufferInverseDimensions;
|
||||
|
||||
FfxInt32x2 DepthBufferOffset;
|
||||
FfxFloat32x4 PerPassFullResUVOffset[4];
|
||||
|
||||
FfxFloat32x2 OutputBufferDimensions;
|
||||
FfxFloat32x2 OutputBufferInverseDimensions;
|
||||
|
||||
FfxFloat32x2 ImportanceMapDimensions;
|
||||
FfxFloat32x2 ImportanceMapInverseDimensions;
|
||||
|
||||
FfxFloat32x2 DeinterleavedDepthBufferDimensions;
|
||||
FfxFloat32x2 DeinterleavedDepthBufferInverseDimensions;
|
||||
|
||||
FfxFloat32x2 DeinterleavedDepthBufferOffset;
|
||||
FfxFloat32x2 DeinterleavedDepthBufferNormalisedOffset;
|
||||
|
||||
mat4 NormalsWorldToViewspaceMatrix;
|
||||
};
|
||||
|
||||
layout (set=0, binding = CACAO_BIND_CB_CACAO) uniform SSAOConstantsBuffer_t
|
||||
{
|
||||
FFX_CACAO_Constants g_FFX_CACAO_Consts;
|
||||
};
|
||||
|
||||
#define FFX_CACAO_CONSTANT_BUFFER_1_SIZE 172 // Number of 32-bit values. This must be kept in sync with max( cbRCAS , cbSPD) size.
|
||||
#endif
|
||||
|
||||
FfxFloat32x2 DepthUnpackConsts(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.DepthUnpackConsts;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32x2 CameraTanHalfFOV(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.CameraTanHalfFOV;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32x2 NDCToViewMul(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.NDCToViewMul;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32x2 NDCToViewAdd(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.NDCToViewAdd;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32x2 DepthBufferUVToViewMul(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.DepthBufferUVToViewMul;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32x2 DepthBufferUVToViewAdd(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.DepthBufferUVToViewAdd;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32 EffectRadius(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.EffectRadius;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 EffectShadowStrength(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.EffectShadowStrength;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 EffectShadowPow(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.EffectShadowPow;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 EffectShadowClamp(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.EffectShadowClamp;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32 EffectFadeOutMul(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.EffectFadeOutMul;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 EffectFadeOutAdd(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.EffectFadeOutAdd;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 EffectHorizonAngleThreshold(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.EffectHorizonAngleThreshold;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 EffectSamplingRadiusNearLimitRec(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.EffectSamplingRadiusNearLimitRec;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32 DepthPrecisionOffsetMod(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.DepthPrecisionOffsetMod;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 NegRecEffectRadius(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.NegRecEffectRadius;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 LoadCounterAvgDiv(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.LoadCounterAvgDiv;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 AdaptiveSampleCountLimit(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.AdaptiveSampleCountLimit;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32 InvSharpness(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.InvSharpness;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxInt32 BlurNumPasses(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.BlurNumPasses;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 BilateralSigmaSquared(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.BilateralSigmaSquared;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 BilateralSimilarityDistanceSigma(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.BilateralSimilarityDistanceSigma;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32x4 PatternRotScaleMatrices(uint i, uint j){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.PatternRotScaleMatrices[i][j];
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32 NormalsUnpackMul(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.NormalsUnpackMul;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 NormalsUnpackAdd(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.NormalsUnpackAdd;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 DetailAOStrength(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.DetailAOStrength;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 Dummy0(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.Dummy0;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32x2 SSAOBufferDimensions(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.SSAOBufferDimensions;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32x2 SSAOBufferInverseDimensions(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.SSAOBufferInverseDimensions;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32x2 DepthBufferDimensions(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.DepthBufferDimensions;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32x2 DepthBufferInverseDimensions(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.DepthBufferInverseDimensions;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxInt32x2 DepthBufferOffset(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.DepthBufferOffset;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32x4 PerPassFullResUVOffset(uint i){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.PerPassFullResUVOffset[i];
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32x2 OutputBufferDimensions(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.OutputBufferDimensions;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32x2 OutputBufferInverseDimensions(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.OutputBufferInverseDimensions;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32x2 ImportanceMapDimensions(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.ImportanceMapDimensions;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32x2 ImportanceMapInverseDimensions(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.ImportanceMapInverseDimensions;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32x2 DeinterleavedDepthBufferDimensions(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.DeinterleavedDepthBufferDimensions;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32x2 DeinterleavedDepthBufferInverseDimensions(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.DeinterleavedDepthBufferInverseDimensions;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32x2 DeinterleavedDepthBufferOffset(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.DeinterleavedDepthBufferOffset;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32x2 DeinterleavedDepthBufferNormalisedOffset(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.DeinterleavedDepthBufferNormalisedOffset;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
mat4 NormalsWorldToViewspaceMatrix(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.NormalsWorldToViewspaceMatrix;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
layout (set=0, binding = 1000) uniform sampler g_PointClampSampler;
|
||||
layout (set=0, binding = 1001) uniform sampler g_PointMirrorSampler;
|
||||
layout (set=0, binding = 1002) uniform sampler g_LinearClampSampler;
|
||||
layout (set=0, binding = 1003) uniform sampler g_ViewspaceDepthTapSampler;
|
||||
layout (set=0, binding = 1004) uniform sampler g_RealPointClampSampler;
|
||||
|
||||
|
||||
#if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
layout (set=0, binding = CACAO_BIND_SRV_DEPTH_IN) uniform texture2D g_DepthIn;
|
||||
#endif
|
||||
#if defined CACAO_BIND_SRV_NORMAL_IN
|
||||
layout (set=0, binding = CACAO_BIND_SRV_NORMAL_IN) uniform texture2D g_NormalIn;
|
||||
#endif
|
||||
#if defined CACAO_BIND_SRV_LOAD_COUNTER
|
||||
layout (set=0, binding = CACAO_BIND_SRV_LOAD_COUNTER) uniform utexture1D g_LoadCounter;
|
||||
#endif
|
||||
#if defined CACAO_BIND_SRV_DEINTERLEAVED_DEPTHS
|
||||
layout (set=0, binding = CACAO_BIND_SRV_DEINTERLEAVED_DEPTHS) uniform texture2DArray g_DeinterleavedDepth;
|
||||
#endif
|
||||
#if defined CACAO_BIND_SRV_DEINTERLEAVED_NORMALS
|
||||
layout (set=0, binding = CACAO_BIND_SRV_DEINTERLEAVED_NORMALS) uniform texture2DArray g_DeinterleavedNormals;
|
||||
#endif
|
||||
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
layout (set=0, binding = CACAO_BIND_SRV_SSAO_BUFFER_PING) uniform texture2DArray g_SsaoBufferPing;
|
||||
#endif
|
||||
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PONG
|
||||
layout (set=0, binding = CACAO_BIND_SRV_SSAO_BUFFER_PONG) uniform texture2DArray g_SsaoBufferPong;
|
||||
#endif
|
||||
#if defined CACAO_BIND_SRV_IMPORTANCE_MAP
|
||||
layout (set=0, binding = CACAO_BIND_SRV_IMPORTANCE_MAP) uniform texture2D g_ImportanceMap;
|
||||
#endif
|
||||
#if defined CACAO_BIND_SRV_IMPORTANCE_MAP_PONG
|
||||
layout (set=0, binding = CACAO_BIND_SRV_IMPORTANCE_MAP_PONG) uniform texture2D g_ImportanceMapPong;
|
||||
#endif
|
||||
|
||||
#if defined CACAO_BIND_UAV_LOAD_COUNTER
|
||||
layout (set=0, binding = CACAO_BIND_UAV_LOAD_COUNTER, r32ui) uniform uimage1D g_RwLoadCounter;
|
||||
#endif
|
||||
#if defined CACAO_BIND_UAV_DEINTERLEAVED_DEPTHS
|
||||
layout (set=0, binding = CACAO_BIND_UAV_DEINTERLEAVED_DEPTHS, r32f) uniform image2DArray g_RwDeinterleavedDepth;
|
||||
#endif
|
||||
#if defined CACAO_BIND_UAV_DEINTERLEAVED_NORMALS
|
||||
layout (set=0, binding = CACAO_BIND_UAV_DEINTERLEAVED_NORMALS, rgba32f) uniform image2DArray g_RwDeinterleavedNormals;
|
||||
#endif
|
||||
#if defined CACAO_BIND_UAV_SSAO_BUFFER_PING
|
||||
layout (set=0, binding = CACAO_BIND_UAV_SSAO_BUFFER_PING, rg32f) uniform image2DArray g_RwSsaoBufferPing;
|
||||
#endif
|
||||
#if defined CACAO_BIND_UAV_SSAO_BUFFER_PONG
|
||||
layout (set=0, binding = CACAO_BIND_UAV_SSAO_BUFFER_PONG, rg32f) uniform image2DArray g_RwSsaoBufferPong;
|
||||
#endif
|
||||
#if defined CACAO_BIND_UAV_IMPORTANCE_MAP
|
||||
layout (set = 0, binding = CACAO_BIND_UAV_IMPORTANCE_MAP, r32f) uniform image2D g_RwImportanceMap;
|
||||
#endif
|
||||
#if defined CACAO_BIND_UAV_IMPORTANCE_MAP_PONG
|
||||
layout (set = 0, binding = CACAO_BIND_UAV_IMPORTANCE_MAP_PONG, r32f) uniform image2D g_RwImportanceMapPong;
|
||||
#endif
|
||||
#if defined CACAO_BIND_UAV_OUTPUT
|
||||
layout (set = 0, binding = CACAO_BIND_UAV_OUTPUT, rgba16f) uniform image2D g_RwOutput;
|
||||
#endif
|
||||
#if defined CACAO_BIND_UAV_DEPTH_DOWNSAMPLED_MIPS
|
||||
layout (set = 0, binding = CACAO_BIND_UAV_DEPTH_DOWNSAMPLED_MIPS, r32f) uniform image2DArray g_RwDepthMips[4];
|
||||
#endif
|
||||
|
||||
// =============================================================================
|
||||
// Clear Load Counter
|
||||
#if defined CACAO_BIND_UAV_LOAD_COUNTER
|
||||
void FFX_CACAO_ClearLoadCounter_SetLoadCounter(FfxUInt32 val)
|
||||
{
|
||||
imageStore(g_RwLoadCounter, 0, FfxUInt32x4(val, val, val, val));
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_LOAD_COUNTER
|
||||
|
||||
// =============================================================================
|
||||
// Edge Sensitive Blur
|
||||
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
FfxFloat32x2 FFX_CACAO_EdgeSensitiveBlur_SampleInput(FfxFloat32x2 uv, FfxUInt32 layerId)
|
||||
{
|
||||
return textureLod(sampler2DArray(g_SsaoBufferPing, g_PointMirrorSampler), FfxFloat32x3(uv, FfxFloat32(layerId)), 0.0f).xy;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
|
||||
#if defined CACAO_BIND_UAV_SSAO_BUFFER_PONG
|
||||
void FFX_CACAO_EdgeSensitiveBlur_StoreOutput(FfxUInt32x2 coord, FfxFloat32x2 value, FfxUInt32 layerId)
|
||||
{
|
||||
imageStore(g_RwSsaoBufferPong, FfxInt32x3(coord, layerId), FfxFloat32x4(value, 0, 0));
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_SSAO_BUFFER_PONG
|
||||
|
||||
// =============================================================================
|
||||
// SSAO Generation
|
||||
#if defined CACAO_BIND_SRV_DEINTERLEAVED_DEPTHS
|
||||
FfxFloat32 FFX_CACAO_SSAOGeneration_SampleViewspaceDepthMip(FfxFloat32x2 uv, FfxFloat32 mip, FfxUInt32 layerId)
|
||||
{
|
||||
return textureLod(sampler2DArray(g_DeinterleavedDepth, g_ViewspaceDepthTapSampler), FfxFloat32x3(uv, FfxFloat32(layerId)), mip).x;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_DEINTERLEAVED_DEPTHS
|
||||
|
||||
#if defined CACAO_BIND_SRV_DEINTERLEAVED_DEPTHS
|
||||
FfxFloat32x4 FFX_CACAO_SSAOGeneration_GatherViewspaceDepthOffset(FfxFloat32x2 uv, FfxInt32x2 offset, FfxUInt32 layerId)
|
||||
{
|
||||
return textureGatherOffset(sampler2DArray(g_DeinterleavedDepth, g_PointMirrorSampler), FfxFloat32x3(uv, FfxFloat32(layerId)), offset, 0);
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_DEINTERLEAVED_DEPTHS
|
||||
|
||||
#if defined CACAO_BIND_SRV_LOAD_COUNTER
|
||||
FfxUInt32 FFX_CACAO_SSAOGeneration_GetLoadCounter()
|
||||
{
|
||||
return FfxUInt32(texelFetch(g_LoadCounter, 0, 0).x);
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_LOAD_COUNTER
|
||||
|
||||
#if defined CACAO_BIND_SRV_IMPORTANCE_MAP
|
||||
FfxFloat32 FFX_CACAO_SSAOGeneration_SampleImportance(FfxFloat32x2 uv)
|
||||
{
|
||||
return textureLod(sampler2D(g_ImportanceMap, g_LinearClampSampler), uv, 0.0f).x;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_IMPORTANCE_MAP
|
||||
|
||||
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PONG
|
||||
FfxFloat32x2 FFX_CACAO_SSAOGeneration_LoadBasePassSSAOPass(FfxUInt32x2 coord, FfxUInt32 pass)
|
||||
{
|
||||
return texelFetch(g_SsaoBufferPong, FfxInt32x3(coord, pass), 0).xy;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_SSAO_BUFFER_PONG
|
||||
|
||||
#if defined CACAO_BIND_SRV_DEINTERLEAVED_NORMALS
|
||||
FfxFloat32x3 FFX_CACAO_SSAOGeneration_GetNormalPass(FfxUInt32x2 coord, FfxUInt32 pass)
|
||||
{
|
||||
return texelFetch(g_DeinterleavedNormals, FfxInt32x3(coord, pass), 0).xyz;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_DEINTERLEAVED_NORMALS
|
||||
|
||||
#if defined CACAO_BIND_UAV_SSAO_BUFFER_PING
|
||||
void FFX_CACAO_SSAOGeneration_StoreOutput(FfxUInt32x2 coord, FfxFloat32x2 val, FfxUInt32 layerId)
|
||||
{
|
||||
imageStore(g_RwSsaoBufferPing, FfxInt32x3(coord, layerId), FfxFloat32x4(val, 0, 0));
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_SSAO_BUFFER_PING
|
||||
|
||||
// ============================================================================
|
||||
// Apply
|
||||
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
FfxFloat32 FFX_CACAO_Apply_SampleSSAOUVPass(FfxFloat32x2 uv, FfxUInt32 pass)
|
||||
{
|
||||
return textureLod(sampler2DArray(g_SsaoBufferPing, g_LinearClampSampler), FfxFloat32x3(uv, pass), 0.0f).x;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
|
||||
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
FfxFloat32x2 FFX_CACAO_Apply_LoadSSAOPass(FfxUInt32x2 coord, FfxUInt32 pass)
|
||||
{
|
||||
return texelFetch(g_SsaoBufferPing, FfxInt32x3(coord, pass), 0).xy;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
|
||||
#if defined CACAO_BIND_UAV_OUTPUT
|
||||
void FFX_CACAO_Apply_StoreOutput(FfxUInt32x2 coord, FfxFloat32 val)
|
||||
{
|
||||
FfxFloat32x4 prev = imageLoad(g_RwOutput, FfxInt32x2(coord));
|
||||
imageStore(g_RwOutput, FfxInt32x2(coord), FfxFloat32x4(val, prev.g, prev.b, prev.a));
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_OUTPUT
|
||||
|
||||
// =============================================================================
|
||||
// Prepare
|
||||
#if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
FfxFloat32x4 FFX_CACAO_Prepare_SampleDepthOffsets(FfxFloat32x2 uv)
|
||||
{
|
||||
FfxFloat32x4 samples;
|
||||
samples.x = textureLodOffset(sampler2D(g_DepthIn, g_PointClampSampler), uv, 0.0f, FfxInt32x2(0, 2)).x;
|
||||
samples.y = textureLodOffset(sampler2D(g_DepthIn, g_PointClampSampler), uv, 0.0f, FfxInt32x2(2, 2)).x;
|
||||
samples.z = textureLodOffset(sampler2D(g_DepthIn, g_PointClampSampler), uv, 0.0f, FfxInt32x2(2, 0)).x;
|
||||
samples.w = textureLodOffset(sampler2D(g_DepthIn, g_PointClampSampler), uv, 0.0f, FfxInt32x2(0, 0)).x;
|
||||
return samples;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
|
||||
#if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
FfxFloat32x4 FFX_CACAO_Prepare_GatherDepth(FfxFloat32x2 uv)
|
||||
{
|
||||
return textureGather(sampler2D(g_DepthIn, g_PointClampSampler), uv, 0);
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
|
||||
#if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
FfxFloat32 FFX_CACAO_Prepare_LoadDepth(FfxUInt32x2 coord)
|
||||
{
|
||||
return texelFetch(g_DepthIn, FfxInt32x2(coord), 0).x;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
|
||||
#if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
FfxFloat32 FFX_CACAO_Prepare_LoadDepthOffset(FfxUInt32x2 coord, FfxInt32x2 offset)
|
||||
{
|
||||
return texelFetch(g_DepthIn, FfxInt32x2(coord) + offset, 0).x; //CACAO_TODO
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
|
||||
#if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
FfxFloat32x4 FFX_CACAO_Prepare_GatherDepthOffset(FfxFloat32x2 uv, FfxInt32x2 offset)
|
||||
{
|
||||
return textureGatherOffset(sampler2D(g_DepthIn, g_PointClampSampler), uv, offset, 0);
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
|
||||
#if defined CACAO_BIND_SRV_NORMAL_IN
|
||||
FfxFloat32x3 FFX_CACAO_Prepare_LoadNormal(FfxUInt32x2 coord)
|
||||
{
|
||||
FfxFloat32x3 normal = texelFetch(g_NormalIn, FfxInt32x2(coord), 0).xyz;
|
||||
normal = normal * NormalsUnpackMul().xxx + NormalsUnpackAdd().xxx;
|
||||
normal = FFX_TRANSFORM_VECTOR(normal, FfxFloat32x3x3(NormalsWorldToViewspaceMatrix())).xyz;
|
||||
return normal;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_NORMAL_IN
|
||||
|
||||
#if defined CACAO_BIND_UAV_DEPTH_DOWNSAMPLED_MIPS
|
||||
void FFX_CACAO_Prepare_StoreDepthMip0(FfxUInt32x2 coord, FfxUInt32 index, FfxFloat32 val)
|
||||
{
|
||||
imageStore(g_RwDepthMips[0], FfxInt32x3(coord, index), FfxFloat32x4(val, val, val, val));
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_DEPTH_DOWNSAMPLED_MIPS
|
||||
|
||||
#if defined CACAO_BIND_UAV_DEPTH_DOWNSAMPLED_MIPS
|
||||
void FFX_CACAO_Prepare_StoreDepthMip1(FfxUInt32x2 coord, FfxUInt32 index, FfxFloat32 val)
|
||||
{
|
||||
imageStore(g_RwDepthMips[1], FfxInt32x3(coord, index), FfxFloat32x4(val, val, val, val));
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_DEPTH_DOWNSAMPLED_MIPS
|
||||
|
||||
#if defined CACAO_BIND_UAV_DEPTH_DOWNSAMPLED_MIPS
|
||||
void FFX_CACAO_Prepare_StoreDepthMip2(FfxUInt32x2 coord, FfxUInt32 index, FfxFloat32 val)
|
||||
{
|
||||
imageStore(g_RwDepthMips[2], FfxInt32x3(coord, index), FfxFloat32x4(val, val, val, val));
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_DEPTH_DOWNSAMPLED_MIPS
|
||||
|
||||
#if defined CACAO_BIND_UAV_DEPTH_DOWNSAMPLED_MIPS
|
||||
void FFX_CACAO_Prepare_StoreDepthMip3(FfxUInt32x2 coord, FfxUInt32 index, FfxFloat32 val)
|
||||
{
|
||||
imageStore(g_RwDepthMips[3], FfxInt32x3(coord, index), FfxFloat32x4(val, val, val, val));
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_DEPTH_DOWNSAMPLED_MIPS
|
||||
|
||||
#if defined CACAO_BIND_UAV_DEINTERLEAVED_DEPTHS
|
||||
void FFX_CACAO_Prepare_StoreDepth(FfxUInt32x2 coord, FfxUInt32 index, FfxFloat32 val)
|
||||
{
|
||||
imageStore(g_RwDeinterleavedDepth, FfxInt32x3(coord, index), FfxFloat32x4(val, val, val, val));
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_DEINTERLEAVED_DEPTHS
|
||||
|
||||
#if defined CACAO_BIND_UAV_DEINTERLEAVED_DEPTHS
|
||||
void FFX_CACAO_Prepare_StoreNormal(FfxUInt32x2 coord, FfxUInt32 index, FfxFloat32x3 normal)
|
||||
{
|
||||
imageStore(g_RwDeinterleavedNormals, FfxInt32x3(coord, index), FfxFloat32x4(normal, 1.0f));
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_DEINTERLEAVED_DEPTHS
|
||||
|
||||
// =============================================================================
|
||||
// Importance Map
|
||||
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PONG
|
||||
FfxFloat32x4 FFX_CACAO_Importance_GatherSSAO(FfxFloat32x2 uv, FfxUInt32 index)
|
||||
{
|
||||
return textureGather(sampler2DArray(g_SsaoBufferPong, g_PointClampSampler), FfxFloat32x3(uv, index), 0);
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_SSAO_BUFFER_PONG
|
||||
|
||||
#if defined CACAO_BIND_UAV_IMPORTANCE_MAP
|
||||
void FFX_CACAO_Importance_StoreImportance(FfxUInt32x2 coord, FfxFloat32 val)
|
||||
{
|
||||
imageStore(g_RwImportanceMap, FfxInt32x2(coord), FfxFloat32x4(val, val, val, val));
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_IMPORTANCE_MAP
|
||||
|
||||
#if defined CACAO_BIND_SRV_IMPORTANCE_MAP
|
||||
FfxFloat32 FFX_CACAO_Importance_SampleImportanceA(FfxFloat32x2 uv)
|
||||
{
|
||||
return textureLod(sampler2D(g_ImportanceMap, g_LinearClampSampler), uv, 0.0f).x;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_IMPORTANCE_MAP
|
||||
|
||||
#if defined CACAO_BIND_UAV_IMPORTANCE_MAP_PONG
|
||||
void FFX_CACAO_Importance_StoreImportanceA(FfxUInt32x2 coord, FfxFloat32 val)
|
||||
{
|
||||
imageStore(g_RwImportanceMapPong, FfxInt32x2(coord), FfxFloat32x4(val, val, val, val));
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_IMPORTANCE_MAP_PONG
|
||||
|
||||
#if defined CACAO_BIND_SRV_IMPORTANCE_MAP_PONG
|
||||
FfxFloat32 FFX_CACAO_Importance_SampleImportanceB(FfxFloat32x2 uv)
|
||||
{
|
||||
return textureLod(sampler2D(g_ImportanceMapPong, g_LinearClampSampler), uv, 0.0f).x;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_IMPORTANCE_MAP_PONG
|
||||
|
||||
#if defined CACAO_BIND_UAV_IMPORTANCE_MAP
|
||||
void FFX_CACAO_Importance_StoreImportanceB(FfxUInt32x2 coord, FfxFloat32 val)
|
||||
{
|
||||
imageStore(g_RwImportanceMap, FfxInt32x2(coord), FfxFloat32x4(val, val, val, val));
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_IMPORTANCE_MAP
|
||||
|
||||
#if defined CACAO_BIND_UAV_LOAD_COUNTER
|
||||
void FFX_CACAO_Importance_LoadCounterInterlockedAdd(FfxUInt32 val)
|
||||
{
|
||||
imageAtomicAdd(g_RwLoadCounter, 0, val);
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_LOAD_COUNTER
|
||||
|
||||
// =============================================================================
|
||||
// Bilateral Upscale
|
||||
|
||||
// These resources ping/pong which is handled by schedule dispatch
|
||||
#if defined CACAO_BIND_UAV_OUTPUT
|
||||
void FFX_CACAO_BilateralUpscale_StoreOutput(FfxUInt32x2 coord, FfxInt32x2 offset, FfxFloat32 val)
|
||||
{
|
||||
FfxFloat32x4 prev = imageLoad(g_RwOutput, FfxInt32x2(coord) + offset);
|
||||
imageStore(g_RwOutput, FfxInt32x2(coord) + offset, FfxFloat32x4(val, prev.g, prev.b, prev.a));
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_OUTPUT
|
||||
|
||||
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
FfxFloat32 FFX_CACAO_BilateralUpscale_SampleSSAOLinear(FfxFloat32x2 uv, FfxUInt32 index)
|
||||
{
|
||||
return textureLod(sampler2DArray(g_SsaoBufferPing, g_LinearClampSampler), FfxFloat32x3(uv, index), 0).r;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
|
||||
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
FfxFloat32 FFX_CACAO_BilateralUpscale_SampleSSAOPoint(FfxFloat32x2 uv, FfxUInt32 index)
|
||||
{
|
||||
return textureLod(sampler2DArray(g_SsaoBufferPing, g_PointClampSampler), FfxFloat32x3(uv, index), 0).r;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
|
||||
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
FfxFloat32x2 FFX_CACAO_BilateralUpscale_LoadSSAO(FfxUInt32x2 coord, FfxUInt32 index)
|
||||
{
|
||||
return texelFetch(g_SsaoBufferPing, FfxInt32x3(coord, index), 0).rg;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
|
||||
#if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
FfxFloat32x4 FFX_CACAO_BilateralUpscale_LoadDepths(FfxUInt32x2 coord)
|
||||
{
|
||||
FfxFloat32x4 depths;
|
||||
depths.x = texelFetchOffset(g_DepthIn, FfxInt32x2(coord), 0, FfxInt32x2(0, 0)).x;
|
||||
depths.y = texelFetchOffset(g_DepthIn, FfxInt32x2(coord), 0, FfxInt32x2(1, 0)).x;
|
||||
depths.z = texelFetchOffset(g_DepthIn, FfxInt32x2(coord), 0, FfxInt32x2(0, 1)).x;
|
||||
depths.w = texelFetchOffset(g_DepthIn, FfxInt32x2(coord), 0, FfxInt32x2(1, 1)).x;
|
||||
return depths;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
|
||||
#if defined CACAO_BIND_SRV_DEINTERLEAVED_DEPTHS
|
||||
FfxFloat32 FFX_CACAO_BilateralUpscale_LoadDownscaledDepth(FfxUInt32x2 coord, FfxUInt32 index)
|
||||
{
|
||||
return texelFetch(g_DeinterleavedDepth, FfxInt32x3(coord, index), 0).x;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_DEINTERLEAVED_DEPTHS
|
||||
|
||||
#endif // #if defined(FFX_GPU)
|
||||
852
betterRenderer/thirdparty/fsr2/include/FidelityFX/gpu/cacao/ffx_cacao_callbacks_hlsl.h
vendored
Normal file
852
betterRenderer/thirdparty/fsr2/include/FidelityFX/gpu/cacao/ffx_cacao_callbacks_hlsl.h
vendored
Normal file
@@ -0,0 +1,852 @@
|
||||
// This file is part of the FidelityFX SDK.
|
||||
//
|
||||
// Copyright (C) 2024 Advanced Micro Devices, Inc.
|
||||
//
|
||||
// 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.
|
||||
|
||||
#include "ffx_cacao_resources.h"
|
||||
|
||||
#if defined(FFX_GPU)
|
||||
#ifdef __hlsl_dx_compiler
|
||||
#pragma dxc diagnostic push
|
||||
#pragma dxc diagnostic ignored "-Wambig-lit-shift"
|
||||
#endif //__hlsl_dx_compiler
|
||||
#include "ffx_core.h"
|
||||
#ifdef __hlsl_dx_compiler
|
||||
#pragma dxc diagnostic pop
|
||||
#endif //__hlsl_dx_compiler
|
||||
|
||||
#ifndef FFX_PREFER_WAVE64
|
||||
#define FFX_PREFER_WAVE64
|
||||
#endif // #ifndef FFX_PREFER_WAVE64
|
||||
|
||||
#if defined(FFX_GPU)
|
||||
#pragma warning(disable: 3205) // conversion from larger type to smaller
|
||||
#endif // #if defined(FFX_GPU)
|
||||
|
||||
#define DECLARE_SRV_REGISTER(regIndex) t##regIndex
|
||||
#define DECLARE_UAV_REGISTER(regIndex) u##regIndex
|
||||
#define DECLARE_CB_REGISTER(regIndex) b##regIndex
|
||||
#define FFX_CACAO_DECLARE_SRV(regIndex) register(DECLARE_SRV_REGISTER(regIndex))
|
||||
#define FFX_CACAO_DECLARE_UAV(regIndex) register(DECLARE_UAV_REGISTER(regIndex))
|
||||
#define FFX_CACAO_DECLARE_CB(regIndex) register(DECLARE_CB_REGISTER(regIndex))
|
||||
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
struct FFX_CACAO_Constants
|
||||
{
|
||||
FfxFloat32x2 DepthUnpackConsts;
|
||||
FfxFloat32x2 CameraTanHalfFOV;
|
||||
|
||||
FfxFloat32x2 NDCToViewMul;
|
||||
FfxFloat32x2 NDCToViewAdd;
|
||||
|
||||
FfxFloat32x2 DepthBufferUVToViewMul;
|
||||
FfxFloat32x2 DepthBufferUVToViewAdd;
|
||||
|
||||
FfxFloat32 EffectRadius; // world (viewspace) maximum size of the shadow
|
||||
FfxFloat32 EffectShadowStrength; // global strength of the effect (0 - 5)
|
||||
FfxFloat32 EffectShadowPow;
|
||||
FfxFloat32 EffectShadowClamp;
|
||||
|
||||
FfxFloat32 EffectFadeOutMul; // effect fade out from distance (ex. 25)
|
||||
FfxFloat32 EffectFadeOutAdd; // effect fade out to distance (ex. 100)
|
||||
FfxFloat32 EffectHorizonAngleThreshold; // limit errors on slopes and caused by insufficient geometry tessellation (0.05 to 0.5)
|
||||
FfxFloat32 EffectSamplingRadiusNearLimitRec; // if viewspace pixel closer than this, don't enlarge shadow sampling radius anymore (makes no sense to grow beyond some distance, not enough samples to cover everything, so just limit the shadow growth; could be SSAOSettingsFadeOutFrom * 0.1 or less)
|
||||
|
||||
FfxFloat32 DepthPrecisionOffsetMod;
|
||||
FfxFloat32 NegRecEffectRadius; // -1.0 / EffectRadius
|
||||
FfxFloat32 LoadCounterAvgDiv; // 1.0 / ( halfDepthMip[SSAO_DEPTH_MIP_LEVELS-1].sizeX * halfDepthMip[SSAO_DEPTH_MIP_LEVELS-1].sizeY )
|
||||
FfxFloat32 AdaptiveSampleCountLimit;
|
||||
|
||||
FfxFloat32 InvSharpness;
|
||||
FfxInt32 BlurNumPasses;
|
||||
FfxFloat32 BilateralSigmaSquared;
|
||||
FfxFloat32 BilateralSimilarityDistanceSigma;
|
||||
|
||||
FfxFloat32x4 PatternRotScaleMatrices[4][5];
|
||||
|
||||
FfxFloat32 NormalsUnpackMul;
|
||||
FfxFloat32 NormalsUnpackAdd;
|
||||
FfxFloat32 DetailAOStrength;
|
||||
FfxFloat32 Dummy0;
|
||||
|
||||
FfxFloat32x2 SSAOBufferDimensions;
|
||||
FfxFloat32x2 SSAOBufferInverseDimensions;
|
||||
|
||||
FfxFloat32x2 DepthBufferDimensions;
|
||||
FfxFloat32x2 DepthBufferInverseDimensions;
|
||||
|
||||
FfxInt32x2 DepthBufferOffset;
|
||||
FfxFloat32x4 PerPassFullResUVOffset[4];
|
||||
|
||||
FfxFloat32x2 OutputBufferDimensions;
|
||||
FfxFloat32x2 OutputBufferInverseDimensions;
|
||||
|
||||
FfxFloat32x2 ImportanceMapDimensions;
|
||||
FfxFloat32x2 ImportanceMapInverseDimensions;
|
||||
|
||||
FfxFloat32x2 DeinterleavedDepthBufferDimensions;
|
||||
FfxFloat32x2 DeinterleavedDepthBufferInverseDimensions;
|
||||
|
||||
FfxFloat32x2 DeinterleavedDepthBufferOffset;
|
||||
FfxFloat32x2 DeinterleavedDepthBufferNormalisedOffset;
|
||||
|
||||
float4x4 NormalsWorldToViewspaceMatrix;
|
||||
};
|
||||
|
||||
cbuffer SSAOConstantsBuffer_t : register(b0)
|
||||
{
|
||||
FFX_CACAO_Constants g_FFX_CACAO_Consts;
|
||||
}
|
||||
|
||||
#define FFX_CACAO_CONSTANT_BUFFER_1_SIZE 172 // Number of 32-bit values. This must be kept in sync with max( cbRCAS , cbSPD) size.
|
||||
#endif
|
||||
|
||||
FfxFloat32x2 DepthUnpackConsts(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.DepthUnpackConsts;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32x2 CameraTanHalfFOV(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.CameraTanHalfFOV;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32x2 NDCToViewMul(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.NDCToViewMul;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32x2 NDCToViewAdd(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.NDCToViewAdd;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32x2 DepthBufferUVToViewMul(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.DepthBufferUVToViewMul;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32x2 DepthBufferUVToViewAdd(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.DepthBufferUVToViewAdd;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32 EffectRadius(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.EffectRadius;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 EffectShadowStrength(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.EffectShadowStrength;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 EffectShadowPow(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.EffectShadowPow;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 EffectShadowClamp(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.EffectShadowClamp;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32 EffectFadeOutMul(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.EffectFadeOutMul;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 EffectFadeOutAdd(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.EffectFadeOutAdd;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 EffectHorizonAngleThreshold(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.EffectHorizonAngleThreshold;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 EffectSamplingRadiusNearLimitRec(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.EffectSamplingRadiusNearLimitRec;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32 DepthPrecisionOffsetMod(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.DepthPrecisionOffsetMod;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 NegRecEffectRadius(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.NegRecEffectRadius;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 LoadCounterAvgDiv(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.LoadCounterAvgDiv;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 AdaptiveSampleCountLimit(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.AdaptiveSampleCountLimit;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32 InvSharpness(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.InvSharpness;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxInt32 BlurNumPasses(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.BlurNumPasses;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 BilateralSigmaSquared(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.BilateralSigmaSquared;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 BilateralSimilarityDistanceSigma(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.BilateralSimilarityDistanceSigma;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32x4 PatternRotScaleMatrices(uint i, uint j){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.PatternRotScaleMatrices[i][j];
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32 NormalsUnpackMul(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.NormalsUnpackMul;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 NormalsUnpackAdd(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.NormalsUnpackAdd;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 DetailAOStrength(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.DetailAOStrength;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32 Dummy0(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.Dummy0;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32x2 SSAOBufferDimensions(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.SSAOBufferDimensions;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32x2 SSAOBufferInverseDimensions(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.SSAOBufferInverseDimensions;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32x2 DepthBufferDimensions(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.DepthBufferDimensions;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32x2 DepthBufferInverseDimensions(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.DepthBufferInverseDimensions;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxInt32x2 DepthBufferOffset(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.DepthBufferOffset;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32x4 PerPassFullResUVOffset(uint i){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.PerPassFullResUVOffset[i];
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32x2 OutputBufferDimensions(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.OutputBufferDimensions;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32x2 OutputBufferInverseDimensions(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.OutputBufferInverseDimensions;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32x2 ImportanceMapDimensions(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.ImportanceMapDimensions;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32x2 ImportanceMapInverseDimensions(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.ImportanceMapInverseDimensions;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32x2 DeinterleavedDepthBufferDimensions(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.DeinterleavedDepthBufferDimensions;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32x2 DeinterleavedDepthBufferInverseDimensions(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.DeinterleavedDepthBufferInverseDimensions;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
FfxFloat32x2 DeinterleavedDepthBufferOffset(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.DeinterleavedDepthBufferOffset;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
FfxFloat32x2 DeinterleavedDepthBufferNormalisedOffset(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.DeinterleavedDepthBufferNormalisedOffset;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
float4x4 NormalsWorldToViewspaceMatrix(){
|
||||
#if defined(CACAO_BIND_CB_CACAO)
|
||||
return g_FFX_CACAO_Consts.NormalsWorldToViewspaceMatrix;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(FFX_GPU)
|
||||
#define FFX_CACAO_ROOTSIG_STRINGIFY(p) FFX_CACAO_ROOTSIG_STR(p)
|
||||
#define FFX_CACAO_ROOTSIG_STR(p) #p
|
||||
#define FFX_CACAO_ROOTSIG [RootSignature( "DescriptorTable(UAV(u0, numDescriptors = " FFX_CACAO_ROOTSIG_STRINGIFY(FFX_CACAO_RESOURCE_IDENTIFIER_COUNT) ")), " \
|
||||
"DescriptorTable(SRV(t0, numDescriptors = " FFX_CACAO_ROOTSIG_STRINGIFY(FFX_CACAO_RESOURCE_IDENTIFIER_COUNT) ")), " \
|
||||
"CBV(b0), " \
|
||||
"StaticSampler(s0, filter = FILTER_MIN_MAG_MIP_POINT, " \
|
||||
"addressU = TEXTURE_ADDRESS_CLAMP, " \
|
||||
"addressV = TEXTURE_ADDRESS_CLAMP, " \
|
||||
"addressW = TEXTURE_ADDRESS_CLAMP, " \
|
||||
"comparisonFunc = COMPARISON_NEVER, " \
|
||||
"borderColor = STATIC_BORDER_COLOR_TRANSPARENT_BLACK), " \
|
||||
"StaticSampler(s1, filter = FILTER_MIN_MAG_MIP_POINT, " \
|
||||
"addressU = TEXTURE_ADDRESS_MIRROR, " \
|
||||
"addressV = TEXTURE_ADDRESS_MIRROR, " \
|
||||
"addressW = TEXTURE_ADDRESS_MIRROR, " \
|
||||
"comparisonFunc = COMPARISON_NEVER, " \
|
||||
"borderColor = STATIC_BORDER_COLOR_TRANSPARENT_BLACK), " \
|
||||
"StaticSampler(s2, filter = FILTER_MIN_MAG_MIP_LINEAR, " \
|
||||
"addressU = TEXTURE_ADDRESS_CLAMP, " \
|
||||
"addressV = TEXTURE_ADDRESS_CLAMP, " \
|
||||
"addressW = TEXTURE_ADDRESS_CLAMP, " \
|
||||
"comparisonFunc = COMPARISON_NEVER, " \
|
||||
"borderColor = STATIC_BORDER_COLOR_TRANSPARENT_BLACK), " \
|
||||
"StaticSampler(s3, filter = FILTER_MIN_MAG_MIP_POINT, " \
|
||||
"addressU = TEXTURE_ADDRESS_CLAMP, " \
|
||||
"addressV = TEXTURE_ADDRESS_CLAMP, " \
|
||||
"addressW = TEXTURE_ADDRESS_CLAMP, " \
|
||||
"comparisonFunc = COMPARISON_NEVER, " \
|
||||
"borderColor = STATIC_BORDER_COLOR_TRANSPARENT_BLACK)" )]
|
||||
|
||||
#define FFX_CACAO_CB2_ROOTSIG [RootSignature( "DescriptorTable(UAV(u0, numDescriptors = " FFX_CACAO_ROOTSIG_STRINGIFY(FFX_CACAO_RESOURCE_IDENTIFIER_COUNT) ")), " \
|
||||
"DescriptorTable(SRV(t0, numDescriptors = " FFX_CACAO_ROOTSIG_STRINGIFY(FFX_CACAO_RESOURCE_IDENTIFIER_COUNT) ")), " \
|
||||
"CBV(b0)" )]
|
||||
|
||||
#define FFX_CACAO_CB_GENERATE_REACTIVE_ROOTSIG [RootSignature( "DescriptorTable(UAV(u0, numDescriptors = " FFX_CACAO_ROOTSIG_STRINGIFY(FFX_CACAO_RESOURCE_IDENTIFIER_COUNT) ")), " \
|
||||
"DescriptorTable(SRV(t0, numDescriptors = " FFX_CACAO_ROOTSIG_STRINGIFY(FFX_CACAO_RESOURCE_IDENTIFIER_COUNT) ")), " \
|
||||
"CBV(b0), " \
|
||||
"CBV(b1)")]
|
||||
|
||||
#if defined(FFX_CACAO_EMBED_ROOTSIG)
|
||||
#define FFX_CACAO_EMBED_ROOTSIG_CONTENT FFX_CACAO_ROOTSIG
|
||||
#define FFX_CACAO_EMBED_CB2_ROOTSIG_CONTENT FFX_CACAO_CB2_ROOTSIG
|
||||
#define FFX_CACAO_EMBED_CB_GENERATE_REACTIVE_ROOTSIG_CONTENT FFX_CACAO_CB_GENERATE_REACTIVE_ROOTSIG
|
||||
#else
|
||||
#define FFX_CACAO_EMBED_ROOTSIG_CONTENT
|
||||
#define FFX_CACAO_EMBED_CB2_ROOTSIG_CONTENT
|
||||
#define FFX_CACAO_EMBED_CB_GENERATE_REACTIVE_ROOTSIG_CONTENT
|
||||
#endif // #if FFX_CACAO_EMBED_ROOTSIG
|
||||
#endif // #if defined(FFX_GPU)
|
||||
|
||||
SamplerState g_PointClampSampler : register(s0);
|
||||
SamplerState g_PointMirrorSampler : register(s1);
|
||||
SamplerState g_LinearClampSampler : register(s2);
|
||||
SamplerState g_ViewspaceDepthTapSampler : register(s3);
|
||||
SamplerState g_RealPointClampSampler : register(s4);
|
||||
|
||||
#if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
Texture2D<FfxFloat32> g_DepthIn : FFX_CACAO_DECLARE_SRV(FFX_CACAO_RESOURCE_IDENTIFIER_DEPTH_IN);
|
||||
#endif
|
||||
#if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
Texture2D<FfxFloat32x4> g_NormalIn : FFX_CACAO_DECLARE_SRV(FFX_CACAO_RESOURCE_IDENTIFIER_NORMAL_IN);
|
||||
#endif
|
||||
#if defined CACAO_BIND_SRV_LOAD_COUNTER
|
||||
Texture1D<FfxUInt32> g_LoadCounter : FFX_CACAO_DECLARE_SRV(FFX_CACAO_RESOURCE_IDENTIFIER_LOAD_COUNTER_BUFFER);
|
||||
#endif
|
||||
#if defined CACAO_BIND_SRV_DEINTERLEAVED_DEPTHS
|
||||
Texture2DArray<FfxFloat32> g_DeinterleavedDepth : FFX_CACAO_DECLARE_SRV(FFX_CACAO_RESOURCE_IDENTIFIER_DEINTERLEAVED_DEPTHS);
|
||||
#endif
|
||||
#if defined CACAO_BIND_SRV_DEINTERLEAVED_NORMALS
|
||||
Texture2DArray<FfxFloat32x4> g_DeinterleavedNormals : FFX_CACAO_DECLARE_SRV(FFX_CACAO_RESOURCE_IDENTIFIER_DEINTERLEAVED_NORMALS);
|
||||
#endif
|
||||
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
Texture2DArray<FfxFloat32x2> g_SsaoBufferPing : FFX_CACAO_DECLARE_SRV(FFX_CACAO_RESOURCE_IDENTIFIER_SSAO_BUFFER_PONG);
|
||||
#endif
|
||||
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PONG
|
||||
Texture2DArray<FfxFloat32x2> g_SsaoBufferPong : FFX_CACAO_DECLARE_SRV(FFX_CACAO_RESOURCE_IDENTIFIER_SSAO_BUFFER_PONG);
|
||||
#endif
|
||||
#if defined CACAO_BIND_SRV_IMPORTANCE_MAP
|
||||
Texture2D<FfxFloat32> g_ImportanceMap : FFX_CACAO_DECLARE_SRV(FFX_CACAO_RESOURCE_IDENTIFIER_IMPORTANCE_MAP);
|
||||
#endif
|
||||
#if defined CACAO_BIND_SRV_IMPORTANCE_MAP_PONG
|
||||
Texture2D<FfxFloat32> g_ImportanceMapPong : FFX_CACAO_DECLARE_SRV(FFX_CACAO_RESOURCE_IDENTIFIER_IMPORTANCE_MAP_PONG);
|
||||
#endif
|
||||
|
||||
#if defined CACAO_BIND_UAV_LOAD_COUNTER
|
||||
RWTexture1D<FfxUInt32> g_RwLoadCounter : FFX_CACAO_DECLARE_UAV(FFX_CACAO_RESOURCE_IDENTIFIER_LOAD_COUNTER_BUFFER);
|
||||
#endif
|
||||
#if defined CACAO_BIND_UAV_DEINTERLEAVED_DEPTHS
|
||||
RWTexture2DArray<FfxFloat32> g_RwDeinterleavedDepth : FFX_CACAO_DECLARE_UAV(FFX_CACAO_RESOURCE_IDENTIFIER_DEINTERLEAVED_DEPTHS);
|
||||
#endif
|
||||
#if defined CACAO_BIND_UAV_DEINTERLEAVED_NORMALS
|
||||
RWTexture2DArray<FfxFloat32x4> g_RwDeinterleavedNormals : FFX_CACAO_DECLARE_UAV(FFX_CACAO_RESOURCE_IDENTIFIER_DEINTERLEAVED_NORMALS);
|
||||
#endif
|
||||
#if defined CACAO_BIND_UAV_SSAO_BUFFER_PING
|
||||
RWTexture2DArray<FfxFloat32x2> g_RwSsaoBufferPing : FFX_CACAO_DECLARE_UAV(FFX_CACAO_RESOURCE_IDENTIFIER_SSAO_BUFFER_PONG);
|
||||
#endif
|
||||
#if defined CACAO_BIND_UAV_SSAO_BUFFER_PONG
|
||||
RWTexture2DArray<FfxFloat32x2> g_RwSsaoBufferPong : FFX_CACAO_DECLARE_UAV(FFX_CACAO_RESOURCE_IDENTIFIER_SSAO_BUFFER_PONG);
|
||||
#endif
|
||||
#if defined CACAO_BIND_UAV_IMPORTANCE_MAP
|
||||
RWTexture2D<FfxFloat32> g_RwImportanceMap : FFX_CACAO_DECLARE_UAV(FFX_CACAO_RESOURCE_IDENTIFIER_IMPORTANCE_MAP);
|
||||
#endif
|
||||
#if defined CACAO_BIND_UAV_IMPORTANCE_MAP_PONG
|
||||
RWTexture2D<FfxFloat32> g_RwImportanceMapPong : FFX_CACAO_DECLARE_UAV(FFX_CACAO_RESOURCE_IDENTIFIER_IMPORTANCE_MAP_PONG);
|
||||
#endif
|
||||
#if defined CACAO_BIND_UAV_OUTPUT
|
||||
RWTexture2D<FfxFloat32x4> g_RwOutput : FFX_CACAO_DECLARE_UAV(FFX_CACAO_RESOURCE_IDENTIFIER_OUTPUT);
|
||||
#endif
|
||||
#if defined CACAO_BIND_UAV_DEPTH_DOWNSAMPLED_MIPS
|
||||
RWTexture2DArray<FfxFloat32> g_RwDepthMips[4] : FFX_CACAO_DECLARE_UAV(FFX_CACAO_RESOURCE_IDENTIFIER_DOWNSAMPLED_DEPTH_MIPMAP_0);
|
||||
#endif
|
||||
|
||||
// =============================================================================
|
||||
// Clear Load Counter
|
||||
|
||||
#if defined CACAO_BIND_UAV_LOAD_COUNTER
|
||||
void FFX_CACAO_ClearLoadCounter_SetLoadCounter(FfxUInt32 val)
|
||||
{
|
||||
g_RwLoadCounter[0] = val;
|
||||
}
|
||||
#endif
|
||||
|
||||
// =============================================================================
|
||||
// Edge Sensitive Blur
|
||||
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
FfxFloat32x2 FFX_CACAO_EdgeSensitiveBlur_SampleInputOffset(FfxFloat32x2 uv, FfxInt32x2 offset, FfxUInt32 layerId)
|
||||
{
|
||||
return g_SsaoBufferPing.SampleLevel(g_PointMirrorSampler, FfxFloat32x3(uv, FfxFloat32(layerId)), 0.0f, offset);
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
|
||||
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
FfxFloat32x2 FFX_CACAO_EdgeSensitiveBlur_SampleInput(FfxFloat32x2 uv, FfxUInt32 layerId)
|
||||
{
|
||||
return g_SsaoBufferPing.SampleLevel(g_PointMirrorSampler, FfxFloat32x3(uv, FfxFloat32(layerId)), 0.0f);
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
|
||||
#if defined CACAO_BIND_UAV_SSAO_BUFFER_PONG
|
||||
void FFX_CACAO_EdgeSensitiveBlur_StoreOutput(FfxUInt32x2 coord, FfxFloat32x2 value, FfxUInt32 layerId)
|
||||
{
|
||||
g_RwSsaoBufferPong[FfxInt32x3(coord, layerId)] = value;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_SSAO_BUFFER_PONG
|
||||
|
||||
// =============================================================================
|
||||
// SSAO Generation
|
||||
|
||||
#if defined CACAO_BIND_SRV_DEINTERLEAVED_DEPTHS
|
||||
FfxFloat32 FFX_CACAO_SSAOGeneration_SampleViewspaceDepthMip(FfxFloat32x2 uv, FfxFloat32 mip, FfxUInt32 layerId)
|
||||
{
|
||||
return g_DeinterleavedDepth.SampleLevel(g_ViewspaceDepthTapSampler, FfxFloat32x3(uv, FfxFloat32(layerId)), mip);
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_DEINTERLEAVED_DEPTHS
|
||||
|
||||
#if defined CACAO_BIND_SRV_DEINTERLEAVED_DEPTHS
|
||||
FfxFloat32x4 FFX_CACAO_SSAOGeneration_GatherViewspaceDepthOffset(FfxFloat32x2 uv, FfxInt32x2 offset, FfxUInt32 layerId)
|
||||
{
|
||||
return g_DeinterleavedDepth.GatherRed(g_PointMirrorSampler, FfxFloat32x3(uv, FfxFloat32(layerId)), offset);
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_DEINTERLEAVED_DEPTHS
|
||||
|
||||
#if defined CACAO_BIND_SRV_LOAD_COUNTER
|
||||
FfxUInt32 FFX_CACAO_SSAOGeneration_GetLoadCounter()
|
||||
{
|
||||
return g_LoadCounter[0];
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_LOAD_COUNTER
|
||||
|
||||
#if defined CACAO_BIND_SRV_IMPORTANCE_MAP
|
||||
FfxFloat32 FFX_CACAO_SSAOGeneration_SampleImportance(FfxFloat32x2 uv)
|
||||
{
|
||||
return g_ImportanceMap.SampleLevel(g_LinearClampSampler, uv, 0.0f);
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_IMPORTANCE_MAP
|
||||
|
||||
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PONG
|
||||
FfxFloat32x2 FFX_CACAO_SSAOGeneration_LoadBasePassSSAOPass(FfxUInt32x2 coord, FfxUInt32 pass)
|
||||
{
|
||||
return g_SsaoBufferPong.Load(FfxInt32x4(coord, pass, 0)).xy;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_SSAO_BUFFER_PONG
|
||||
|
||||
#if defined CACAO_BIND_SRV_DEINTERLEAVED_NORMALS
|
||||
FfxFloat32x3 FFX_CACAO_SSAOGeneration_GetNormalPass(FfxUInt32x2 coord, FfxUInt32 pass)
|
||||
{
|
||||
return g_DeinterleavedNormals[FfxInt32x3(coord, pass)].xyz;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_DEINTERLEAVED_NORMALS
|
||||
|
||||
#if defined CACAO_BIND_UAV_SSAO_BUFFER_PING
|
||||
void FFX_CACAO_SSAOGeneration_StoreOutput(FfxUInt32x2 coord, FfxFloat32x2 val, FfxUInt32 layerId)
|
||||
{
|
||||
g_RwSsaoBufferPing[FfxInt32x3(coord, layerId)] = val;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_SSAO_BUFFER_PING
|
||||
|
||||
// ============================================================================
|
||||
// Apply
|
||||
|
||||
// This resource can be ssao ping or pong, handled by schedule Dispatch
|
||||
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
FfxFloat32 FFX_CACAO_Apply_SampleSSAOUVPass(FfxFloat32x2 uv, FfxUInt32 pass)
|
||||
{
|
||||
return g_SsaoBufferPing.SampleLevel(g_LinearClampSampler, FfxFloat32x3(uv, pass), 0.0f).x;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
|
||||
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
FfxFloat32x2 FFX_CACAO_Apply_LoadSSAOPass(FfxUInt32x2 coord, FfxUInt32 pass)
|
||||
{
|
||||
return g_SsaoBufferPing.Load(FfxInt32x4(coord, pass, 0));
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
|
||||
#if defined CACAO_BIND_UAV_OUTPUT
|
||||
void FFX_CACAO_Apply_StoreOutput(FfxUInt32x2 coord, FfxFloat32 val)
|
||||
{
|
||||
g_RwOutput[coord].r = val;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_OUTPUT
|
||||
|
||||
// =============================================================================
|
||||
// Prepare
|
||||
#if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
FfxFloat32x4 FFX_CACAO_Prepare_SampleDepthOffsets(FfxFloat32x2 uv)
|
||||
{
|
||||
FfxFloat32x4 samples;
|
||||
samples.x = g_DepthIn.SampleLevel(g_PointClampSampler, uv, 0.0f, FfxInt32x2(0, 2));
|
||||
samples.y = g_DepthIn.SampleLevel(g_PointClampSampler, uv, 0.0f, FfxInt32x2(2, 2));
|
||||
samples.z = g_DepthIn.SampleLevel(g_PointClampSampler, uv, 0.0f, FfxInt32x2(2, 0));
|
||||
samples.w = g_DepthIn.SampleLevel(g_PointClampSampler, uv, 0.0f, FfxInt32x2(0, 0));
|
||||
return samples;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
|
||||
#if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
FfxFloat32x4 FFX_CACAO_Prepare_GatherDepth(FfxFloat32x2 uv)
|
||||
{
|
||||
return g_DepthIn.GatherRed(g_PointClampSampler, uv);
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
|
||||
#if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
FfxFloat32 FFX_CACAO_Prepare_LoadDepth(FfxUInt32x2 coord)
|
||||
{
|
||||
return g_DepthIn.Load(FfxInt32x3(coord, 0));
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
|
||||
#if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
FfxFloat32 FFX_CACAO_Prepare_LoadDepthOffset(FfxUInt32x2 coord, FfxInt32x2 offset)
|
||||
{
|
||||
return g_DepthIn.Load(FfxInt32x3(coord, 0), offset);
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
|
||||
#if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
FfxFloat32x4 FFX_CACAO_Prepare_GatherDepthOffset(FfxFloat32x2 uv, FfxInt32x2 offset)
|
||||
{
|
||||
return g_DepthIn.GatherRed(g_PointClampSampler, uv, offset);
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
|
||||
#if defined CACAO_BIND_SRV_NORMAL_IN
|
||||
FfxFloat32x3 FFX_CACAO_Prepare_LoadNormal(FfxUInt32x2 coord)
|
||||
{
|
||||
FfxFloat32x3 normal = g_NormalIn.Load(FfxInt32x3(coord, 0)).xyz;
|
||||
normal = normal * NormalsUnpackMul().xxx + NormalsUnpackAdd().xxx;
|
||||
normal = mul(normal, (float3x3)NormalsWorldToViewspaceMatrix()).xyz;
|
||||
// normal = normalize(normal);
|
||||
return normal;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_NORMAL_IN
|
||||
|
||||
#if defined CACAO_BIND_UAV_DEPTH_DOWNSAMPLED_MIPS
|
||||
void FFX_CACAO_Prepare_StoreDepthMip0(FfxUInt32x2 coord, FfxUInt32 index, FfxFloat32 val)
|
||||
{
|
||||
g_RwDepthMips[0][FfxInt32x3(coord, index)] = val;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_DEPTH_DOWNSAMPLED_MIPS
|
||||
|
||||
#if defined CACAO_BIND_UAV_DEPTH_DOWNSAMPLED_MIPS
|
||||
void FFX_CACAO_Prepare_StoreDepthMip1(FfxUInt32x2 coord, FfxUInt32 index, FfxFloat32 val)
|
||||
{
|
||||
g_RwDepthMips[1][FfxInt32x3(coord, index)] = val;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_DEPTH_DOWNSAMPLED_MIPS
|
||||
|
||||
#if defined CACAO_BIND_UAV_DEPTH_DOWNSAMPLED_MIPS
|
||||
void FFX_CACAO_Prepare_StoreDepthMip2(FfxUInt32x2 coord, FfxUInt32 index, FfxFloat32 val)
|
||||
{
|
||||
g_RwDepthMips[2][FfxInt32x3(coord, index)] = val;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_DEPTH_DOWNSAMPLED_MIPS
|
||||
|
||||
#if defined CACAO_BIND_UAV_DEPTH_DOWNSAMPLED_MIPS
|
||||
void FFX_CACAO_Prepare_StoreDepthMip3(FfxUInt32x2 coord, FfxUInt32 index, FfxFloat32 val)
|
||||
{
|
||||
g_RwDepthMips[3][FfxInt32x3(coord, index)] = val;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_DEPTH_DOWNSAMPLED_MIPS
|
||||
|
||||
#if defined CACAO_BIND_UAV_DEINTERLEAVED_DEPTHS
|
||||
void FFX_CACAO_Prepare_StoreDepth(FfxUInt32x2 coord, FfxUInt32 index, FfxFloat32 val)
|
||||
{
|
||||
g_RwDeinterleavedDepth[FfxInt32x3(coord, index)] = val;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_DEINTERLEAVED_DEPTHS
|
||||
|
||||
#if defined CACAO_BIND_UAV_DEINTERLEAVED_DEPTHS
|
||||
void FFX_CACAO_Prepare_StoreNormal(FfxUInt32x2 coord, FfxUInt32 index, FfxFloat32x3 normal)
|
||||
{
|
||||
g_RwDeinterleavedNormals[FfxInt32x3(coord, index)] = FfxFloat32x4(normal, 1.0f);
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_DEINTERLEAVED_DEPTHS
|
||||
|
||||
// =============================================================================
|
||||
// Importance Map
|
||||
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PONG
|
||||
FfxFloat32x4 FFX_CACAO_Importance_GatherSSAO(FfxFloat32x2 uv, FfxUInt32 index)
|
||||
{
|
||||
return g_SsaoBufferPong.GatherRed(g_PointClampSampler, FfxFloat32x3(uv, index));
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_SSAO_BUFFER_PONG
|
||||
|
||||
#if defined CACAO_BIND_UAV_IMPORTANCE_MAP
|
||||
void FFX_CACAO_Importance_StoreImportance(FfxUInt32x2 coord, FfxFloat32 val)
|
||||
{
|
||||
g_RwImportanceMap[coord] = val;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_IMPORTANCE_MAP
|
||||
|
||||
#if defined CACAO_BIND_SRV_IMPORTANCE_MAP
|
||||
FfxFloat32 FFX_CACAO_Importance_SampleImportanceA(FfxFloat32x2 uv)
|
||||
{
|
||||
return g_ImportanceMap.SampleLevel(g_LinearClampSampler, uv, 0.0f);
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_IMPORTANCE_MAP
|
||||
|
||||
#if defined CACAO_BIND_UAV_IMPORTANCE_MAP_PONG
|
||||
void FFX_CACAO_Importance_StoreImportanceA(FfxUInt32x2 coord, FfxFloat32 val)
|
||||
{
|
||||
g_RwImportanceMapPong[coord] = val;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_IMPORTANCE_MAP_PONG
|
||||
|
||||
#if defined CACAO_BIND_SRV_IMPORTANCE_MAP_PONG
|
||||
FfxFloat32 FFX_CACAO_Importance_SampleImportanceB(FfxFloat32x2 uv)
|
||||
{
|
||||
return g_ImportanceMapPong.SampleLevel(g_LinearClampSampler, uv, 0.0f);
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_IMPORTANCE_MAP_PONG
|
||||
|
||||
#if defined CACAO_BIND_UAV_IMPORTANCE_MAP
|
||||
void FFX_CACAO_Importance_StoreImportanceB(FfxUInt32x2 coord, FfxFloat32 val)
|
||||
{
|
||||
g_RwImportanceMap[coord] = val;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_IMPORTANCE_MAP
|
||||
|
||||
#if defined CACAO_BIND_UAV_LOAD_COUNTER
|
||||
void FFX_CACAO_Importance_LoadCounterInterlockedAdd(FfxUInt32 val)
|
||||
{
|
||||
InterlockedAdd(g_RwLoadCounter[0], val);
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_LOAD_COUNTER
|
||||
|
||||
// =============================================================================
|
||||
// Bilateral Upscale
|
||||
|
||||
// These resources ping/pong which is handled by schedule dispatch
|
||||
#if defined CACAO_BIND_UAV_OUTPUT
|
||||
void FFX_CACAO_BilateralUpscale_StoreOutput(FfxUInt32x2 coord, FfxInt32x2 offset, FfxFloat32 val)
|
||||
{
|
||||
g_RwOutput[coord + offset].r = val;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_UAV_OUTPUT
|
||||
|
||||
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
FfxFloat32 FFX_CACAO_BilateralUpscale_SampleSSAOLinear(FfxFloat32x2 uv, FfxUInt32 index)
|
||||
{
|
||||
return g_SsaoBufferPing.SampleLevel(g_LinearClampSampler, FfxFloat32x3(uv, index), 0).x;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
|
||||
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
FfxFloat32 FFX_CACAO_BilateralUpscale_SampleSSAOPoint(FfxFloat32x2 uv, FfxUInt32 index)
|
||||
{
|
||||
return g_SsaoBufferPing.SampleLevel(g_PointClampSampler, FfxFloat32x3(uv, index), 0).x;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
|
||||
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
FfxFloat32x2 FFX_CACAO_BilateralUpscale_LoadSSAO(FfxUInt32x2 coord, FfxUInt32 index)
|
||||
{
|
||||
return g_SsaoBufferPing.Load(FfxInt32x4(coord, index, 0));
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
|
||||
|
||||
#if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
FfxFloat32x4 FFX_CACAO_BilateralUpscale_LoadDepths(FfxUInt32x2 coord)
|
||||
{
|
||||
FfxFloat32x4 depths;
|
||||
depths.x = g_DepthIn.Load(FfxInt32x3(coord, 0), FfxInt32x2(0, 0));
|
||||
depths.y = g_DepthIn.Load(FfxInt32x3(coord, 0), FfxInt32x2(1, 0));
|
||||
depths.z = g_DepthIn.Load(FfxInt32x3(coord, 0), FfxInt32x2(0, 1));
|
||||
depths.w = g_DepthIn.Load(FfxInt32x3(coord, 0), FfxInt32x2(1, 1));
|
||||
return depths;
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_DEPTH_IN
|
||||
|
||||
#if defined CACAO_BIND_SRV_DEINTERLEAVED_DEPTHS
|
||||
FfxFloat32 FFX_CACAO_BilateralUpscale_LoadDownscaledDepth(FfxUInt32x2 coord, FfxUInt32 index)
|
||||
{
|
||||
return g_DeinterleavedDepth.Load(FfxInt32x4(coord, index, 0));
|
||||
}
|
||||
#endif // #if defined CACAO_BIND_SRV_DEINTERLEAVED_DEPTHS
|
||||
|
||||
#endif // #if defined(FFX_GPU)
|
||||
85
betterRenderer/thirdparty/fsr2/include/FidelityFX/gpu/cacao/ffx_cacao_defines.h
vendored
Normal file
85
betterRenderer/thirdparty/fsr2/include/FidelityFX/gpu/cacao/ffx_cacao_defines.h
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
// This file is part of the FidelityFX SDK.
|
||||
//
|
||||
// Copyright (C) 2024 Advanced Micro Devices, Inc.
|
||||
//
|
||||
// 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.
|
||||
|
||||
// Defines for constants common to both CACAO.cpp and CACAO.hlsl
|
||||
|
||||
#ifndef FFX_CACAO_DEFINES_H
|
||||
#define FFX_CACAO_DEFINES_H
|
||||
|
||||
// ============================================================================
|
||||
// Prepare
|
||||
|
||||
#define FFX_CACAO_PREPARE_DEPTHS_AND_MIPS_WIDTH 8
|
||||
#define FFX_CACAO_PREPARE_DEPTHS_AND_MIPS_HEIGHT 8
|
||||
|
||||
#define FFX_CACAO_PREPARE_DEPTHS_WIDTH 8
|
||||
#define FFX_CACAO_PREPARE_DEPTHS_HEIGHT 8
|
||||
|
||||
#define FFX_CACAO_PREPARE_DEPTHS_HALF_WIDTH 8
|
||||
#define FFX_CACAO_PREPARE_DEPTHS_HALF_HEIGHT 8
|
||||
|
||||
#define FFX_CACAO_PREPARE_NORMALS_WIDTH 8
|
||||
#define FFX_CACAO_PREPARE_NORMALS_HEIGHT 8
|
||||
|
||||
#define PREPARE_NORMALS_FROM_INPUT_NORMALS_WIDTH 8
|
||||
#define PREPARE_NORMALS_FROM_INPUT_NORMALS_HEIGHT 8
|
||||
|
||||
// ============================================================================
|
||||
// SSAO Generation
|
||||
|
||||
#define FFX_CACAO_GENERATE_SPARSE_WIDTH 4
|
||||
#define FFX_CACAO_GENERATE_SPARSE_HEIGHT 16
|
||||
|
||||
#define FFX_CACAO_GENERATE_WIDTH 8
|
||||
#define FFX_CACAO_GENERATE_HEIGHT 8
|
||||
|
||||
// ============================================================================
|
||||
// Importance Map
|
||||
|
||||
#define IMPORTANCE_MAP_WIDTH 8
|
||||
#define IMPORTANCE_MAP_HEIGHT 8
|
||||
|
||||
#define IMPORTANCE_MAP_A_WIDTH 8
|
||||
#define IMPORTANCE_MAP_A_HEIGHT 8
|
||||
|
||||
#define IMPORTANCE_MAP_B_WIDTH 8
|
||||
#define IMPORTANCE_MAP_B_HEIGHT 8
|
||||
|
||||
// ============================================================================
|
||||
// Edge Sensitive Blur
|
||||
|
||||
#define FFX_CACAO_BLUR_WIDTH 16
|
||||
#define FFX_CACAO_BLUR_HEIGHT 16
|
||||
|
||||
// ============================================================================
|
||||
// Apply
|
||||
|
||||
#define FFX_CACAO_APPLY_WIDTH 8
|
||||
#define FFX_CACAO_APPLY_HEIGHT 8
|
||||
|
||||
// ============================================================================
|
||||
// Bilateral Upscale
|
||||
|
||||
#define FFX_CACAO_BILATERAL_UPSCALE_WIDTH 8
|
||||
#define FFX_CACAO_BILATERAL_UPSCALE_HEIGHT 8
|
||||
|
||||
#endif
|
||||
449
betterRenderer/thirdparty/fsr2/include/FidelityFX/gpu/cacao/ffx_cacao_edge_sensitive_blur.h
vendored
Normal file
449
betterRenderer/thirdparty/fsr2/include/FidelityFX/gpu/cacao/ffx_cacao_edge_sensitive_blur.h
vendored
Normal file
@@ -0,0 +1,449 @@
|
||||
// This file is part of the FidelityFX SDK.
|
||||
//
|
||||
// Copyright (C) 2024 Advanced Micro Devices, Inc.
|
||||
//
|
||||
// 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.
|
||||
|
||||
#include "ffx_core.h"
|
||||
#include "ffx_cacao_defines.h"
|
||||
#include "ffx_cacao_utils.h"
|
||||
|
||||
// all in one, SIMD in yo SIMD dawg, shader
|
||||
#define FFX_CACAO_TILE_WIDTH 4
|
||||
#define FFX_CACAO_TILE_HEIGHT 3
|
||||
#define FFX_CACAO_HALF_TILE_WIDTH (FFX_CACAO_TILE_WIDTH / 2)
|
||||
#define FFX_CACAO_QUARTER_TILE_WIDTH (FFX_CACAO_TILE_WIDTH / 4)
|
||||
|
||||
#define FFX_CACAO_ARRAY_WIDTH (FFX_CACAO_HALF_TILE_WIDTH * FFX_CACAO_BLUR_WIDTH + 2)
|
||||
#define FFX_CACAO_ARRAY_HEIGHT (FFX_CACAO_TILE_HEIGHT * FFX_CACAO_BLUR_HEIGHT + 2)
|
||||
|
||||
#define FFX_CACAO_ITERS 4
|
||||
|
||||
FFX_GROUPSHARED FfxUInt32 s_FFX_CACAO_BlurF16Front_4[FFX_CACAO_ARRAY_WIDTH][FFX_CACAO_ARRAY_HEIGHT];
|
||||
FFX_GROUPSHARED FfxUInt32 s_FFX_CACAO_BlurF16Back_4[FFX_CACAO_ARRAY_WIDTH][FFX_CACAO_ARRAY_HEIGHT];
|
||||
|
||||
#if FFX_HALF
|
||||
struct FFX_CACAO_Edges_4
|
||||
{
|
||||
FfxFloat16x4 left;
|
||||
FfxFloat16x4 right;
|
||||
FfxFloat16x4 top;
|
||||
FfxFloat16x4 bottom;
|
||||
};
|
||||
|
||||
FFX_CACAO_Edges_4 FFX_CACAO_UnpackEdgesFloat16_4(FfxFloat16x4 _packedVal)
|
||||
{
|
||||
FfxUInt32x4 packedVal = FfxUInt32x4(_packedVal * 255.5);
|
||||
FFX_CACAO_Edges_4 result;
|
||||
result.left = FfxFloat16x4(ffxSaturate(FfxFloat16x4((packedVal >> 6) & 0x03) / 3.0 + InvSharpness()));
|
||||
result.right = FfxFloat16x4(ffxSaturate(FfxFloat16x4((packedVal >> 4) & 0x03) / 3.0 + InvSharpness()));
|
||||
result.top = FfxFloat16x4(ffxSaturate(FfxFloat16x4((packedVal >> 2) & 0x03) / 3.0 + InvSharpness()));
|
||||
result.bottom = FfxFloat16x4(ffxSaturate(FfxFloat16x4((packedVal >> 0) & 0x03) / 3.0 + InvSharpness()));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
FfxFloat16x4 FFX_CACAO_CalcBlurredSampleF16_4(FfxFloat16x4 packedEdges, FfxFloat16x4 centre, FfxFloat16x4 left, FfxFloat16x4 right, FfxFloat16x4 top, FfxFloat16x4 bottom)
|
||||
{
|
||||
FfxFloat16x4 sum = centre * FfxFloat16(0.5f);
|
||||
FfxFloat16x4 weight = FfxFloat16x4(0.5f, 0.5f, 0.5f, 0.5f);
|
||||
FFX_CACAO_Edges_4 edges = FFX_CACAO_UnpackEdgesFloat16_4(packedEdges);
|
||||
|
||||
sum += left * edges.left;
|
||||
weight += edges.left;
|
||||
sum += right * edges.right;
|
||||
weight += edges.right;
|
||||
sum += top * edges.top;
|
||||
weight += edges.top;
|
||||
sum += bottom * edges.bottom;
|
||||
weight += edges.bottom;
|
||||
|
||||
return sum / weight;
|
||||
}
|
||||
|
||||
void FFX_CACAO_LDSEdgeSensitiveBlur(const FfxUInt32 blurPasses, const FfxUInt32x2 tid, const FfxUInt32x2 gid, const FfxUInt32 layerId)
|
||||
{
|
||||
FfxInt32x2 imageCoord = FfxInt32x2(gid) * (FfxInt32x2(FFX_CACAO_TILE_WIDTH * FFX_CACAO_BLUR_WIDTH, FFX_CACAO_TILE_HEIGHT * FFX_CACAO_BLUR_HEIGHT) - FfxInt32(2*blurPasses)) + FfxInt32x2(FFX_CACAO_TILE_WIDTH, FFX_CACAO_TILE_HEIGHT) * FfxInt32x2(tid) - FfxInt32(blurPasses);
|
||||
FfxInt32x2 bufferCoord = FfxInt32x2(FFX_CACAO_HALF_TILE_WIDTH, FFX_CACAO_TILE_HEIGHT) * FfxInt32x2(tid) + 1;
|
||||
|
||||
FfxFloat16x4 packedEdges[FFX_CACAO_QUARTER_TILE_WIDTH][FFX_CACAO_TILE_HEIGHT];
|
||||
{
|
||||
FfxFloat32x2 inputVal[FFX_CACAO_TILE_WIDTH][FFX_CACAO_TILE_HEIGHT];
|
||||
FfxInt32 y;
|
||||
FFX_UNROLL
|
||||
for (y = 0; y < FFX_CACAO_TILE_HEIGHT; ++y)
|
||||
{
|
||||
FFX_UNROLL
|
||||
for (FfxInt32 x = 0; x < FFX_CACAO_TILE_WIDTH; ++x)
|
||||
{
|
||||
FfxFloat32x2 sampleUV = (FfxFloat32x2(imageCoord + FfxInt32x2(x, y)) + 0.5f) * SSAOBufferInverseDimensions();
|
||||
inputVal[x][y] = FFX_CACAO_EdgeSensitiveBlur_SampleInput(sampleUV, layerId);
|
||||
}
|
||||
}
|
||||
FFX_UNROLL
|
||||
for (y = 0; y < FFX_CACAO_TILE_HEIGHT; ++y)
|
||||
{
|
||||
FFX_UNROLL
|
||||
for (FfxInt32 x = 0; x < FFX_CACAO_QUARTER_TILE_WIDTH; ++x)
|
||||
{
|
||||
FfxFloat16x2 ssaoVals = FfxFloat16x2(inputVal[4 * x + 0][y].x, inputVal[4 * x + 1][y].x);
|
||||
s_FFX_CACAO_BlurF16Front_4[bufferCoord.x + 2*x + 0][bufferCoord.y + y] = ffxPackF16(ssaoVals);
|
||||
ssaoVals = FfxFloat16x2(inputVal[4 * x + 2][y].x, inputVal[4 * x + 3][y].x);
|
||||
s_FFX_CACAO_BlurF16Front_4[bufferCoord.x + 2*x + 1][bufferCoord.y + y] = ffxPackF16(ssaoVals);
|
||||
packedEdges[x][y] = FfxFloat16x4(inputVal[4 * x + 0][y].y, inputVal[4 * x + 1][y].y, inputVal[4 * x + 2][y].y, inputVal[4 * x + 3][y].y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FFX_GROUP_MEMORY_BARRIER;
|
||||
|
||||
FFX_UNROLL
|
||||
for (FfxUInt32 i = 0; i < (blurPasses + 1) / 2; ++i)
|
||||
{
|
||||
FFX_UNROLL
|
||||
for (FfxInt32 y = 0; y < FFX_CACAO_TILE_HEIGHT; ++y)
|
||||
{
|
||||
FFX_UNROLL
|
||||
for (FfxInt32 x = 0; x < FFX_CACAO_QUARTER_TILE_WIDTH; ++x)
|
||||
{
|
||||
FfxInt32x2 c = bufferCoord + FfxInt32x2(2*x, y);
|
||||
FfxFloat16x4 centre = FfxFloat16x4(ffxUnpackF16(s_FFX_CACAO_BlurF16Front_4[c.x + 0][c.y + 0]), ffxUnpackF16(s_FFX_CACAO_BlurF16Front_4[c.x + 1][c.y + 0]));
|
||||
FfxFloat16x4 top = FfxFloat16x4(ffxUnpackF16(s_FFX_CACAO_BlurF16Front_4[c.x + 0][c.y - 1]), ffxUnpackF16(s_FFX_CACAO_BlurF16Front_4[c.x + 1][c.y - 1]));
|
||||
FfxFloat16x4 bottom = FfxFloat16x4(ffxUnpackF16(s_FFX_CACAO_BlurF16Front_4[c.x + 0][c.y + 1]), ffxUnpackF16(s_FFX_CACAO_BlurF16Front_4[c.x + 1][c.y + 1]));
|
||||
|
||||
FfxFloat16x2 tmp = ffxUnpackF16(s_FFX_CACAO_BlurF16Front_4[c.x - 1][c.y + 0]);
|
||||
FfxFloat16x4 left = FfxFloat16x4(tmp.y, centre.xyz);
|
||||
tmp = ffxUnpackF16(s_FFX_CACAO_BlurF16Front_4[c.x + 2][c.y + 0]);
|
||||
FfxFloat16x4 right = FfxFloat16x4(centre.yzw, tmp.x);
|
||||
|
||||
FfxFloat16x4 tmp_4 = FFX_CACAO_CalcBlurredSampleF16_4(packedEdges[x][y], centre, left, right, top, bottom);
|
||||
s_FFX_CACAO_BlurF16Back_4[c.x + 0][c.y] = ffxPackF16(tmp_4.xy);
|
||||
s_FFX_CACAO_BlurF16Back_4[c.x + 1][c.y] = ffxPackF16(tmp_4.zw);
|
||||
}
|
||||
}
|
||||
FFX_GROUP_MEMORY_BARRIER;
|
||||
|
||||
if (2 * i + 1 < blurPasses)
|
||||
{
|
||||
FFX_UNROLL
|
||||
for (FfxInt32 y = 0; y < FFX_CACAO_TILE_HEIGHT; ++y)
|
||||
{
|
||||
FFX_UNROLL
|
||||
for (FfxInt32 x = 0; x < FFX_CACAO_QUARTER_TILE_WIDTH; ++x)
|
||||
{
|
||||
FfxInt32x2 c = bufferCoord + FfxInt32x2(2 * x, y);
|
||||
FfxFloat16x4 centre = FfxFloat16x4(ffxUnpackF16(s_FFX_CACAO_BlurF16Back_4[c.x + 0][c.y + 0]), ffxUnpackF16(s_FFX_CACAO_BlurF16Back_4[c.x + 1][c.y + 0]));
|
||||
FfxFloat16x4 top = FfxFloat16x4(ffxUnpackF16(s_FFX_CACAO_BlurF16Back_4[c.x + 0][c.y - 1]), ffxUnpackF16(s_FFX_CACAO_BlurF16Back_4[c.x + 1][c.y - 1]));
|
||||
FfxFloat16x4 bottom = FfxFloat16x4(ffxUnpackF16(s_FFX_CACAO_BlurF16Back_4[c.x + 0][c.y + 1]), ffxUnpackF16(s_FFX_CACAO_BlurF16Back_4[c.x + 1][c.y + 1]));
|
||||
|
||||
FfxFloat16x2 tmp = ffxUnpackF16(s_FFX_CACAO_BlurF16Back_4[c.x - 1][c.y + 0]);
|
||||
FfxFloat16x4 left = FfxFloat16x4(tmp.y, centre.xyz);
|
||||
tmp = ffxUnpackF16(s_FFX_CACAO_BlurF16Back_4[c.x + 2][c.y + 0]);
|
||||
FfxFloat16x4 right = FfxFloat16x4(centre.yzw, tmp.x);
|
||||
|
||||
FfxFloat16x4 tmp_4 = FFX_CACAO_CalcBlurredSampleF16_4(packedEdges[x][y], centre, left, right, top, bottom);
|
||||
s_FFX_CACAO_BlurF16Front_4[c.x + 0][c.y] = ffxPackF16(tmp_4.xy);
|
||||
s_FFX_CACAO_BlurF16Front_4[c.x + 1][c.y] = ffxPackF16(tmp_4.zw);
|
||||
}
|
||||
}
|
||||
FFX_GROUP_MEMORY_BARRIER;
|
||||
}
|
||||
}
|
||||
|
||||
FFX_UNROLL
|
||||
for (FfxUInt32 y = 0; y < FFX_CACAO_TILE_HEIGHT; ++y)
|
||||
{
|
||||
FfxUInt32 outputY = FFX_CACAO_TILE_HEIGHT * tid.y + y;
|
||||
if (blurPasses <= outputY && outputY < FFX_CACAO_TILE_HEIGHT * FFX_CACAO_BLUR_HEIGHT - blurPasses)
|
||||
{
|
||||
FFX_UNROLL
|
||||
for (FfxInt32 x = 0; x < FFX_CACAO_QUARTER_TILE_WIDTH; ++x)
|
||||
{
|
||||
FfxUInt32 outputX = FFX_CACAO_TILE_WIDTH * tid.x + 4 * x;
|
||||
|
||||
FfxFloat16x4 ssaoVal;
|
||||
if (blurPasses % 2 == 0)
|
||||
{
|
||||
ssaoVal = FfxFloat16x4(ffxUnpackF16(s_FFX_CACAO_BlurF16Front_4[bufferCoord.x + x][bufferCoord.y + y]), ffxUnpackF16(s_FFX_CACAO_BlurF16Front_4[bufferCoord.x + x + 1][bufferCoord.y + y]));
|
||||
}
|
||||
else
|
||||
{
|
||||
ssaoVal = FfxFloat16x4(ffxUnpackF16(s_FFX_CACAO_BlurF16Back_4[bufferCoord.x + x][bufferCoord.y + y]), ffxUnpackF16(s_FFX_CACAO_BlurF16Back_4[bufferCoord.x + x + 1][bufferCoord.y + y]));
|
||||
}
|
||||
|
||||
if (blurPasses <= outputX && outputX < FFX_CACAO_TILE_WIDTH * FFX_CACAO_BLUR_WIDTH - blurPasses)
|
||||
{
|
||||
FFX_CACAO_EdgeSensitiveBlur_StoreOutput(imageCoord + FfxInt32x2(4 * x, y), FfxFloat32x2(ssaoVal.x, packedEdges[x][y].x), layerId);
|
||||
}
|
||||
outputX += 1;
|
||||
if (blurPasses <= outputX && outputX < FFX_CACAO_TILE_WIDTH * FFX_CACAO_BLUR_WIDTH - blurPasses)
|
||||
{
|
||||
FFX_CACAO_EdgeSensitiveBlur_StoreOutput(imageCoord + FfxInt32x2(4 * x + 1, y), FfxFloat32x2(ssaoVal.y, packedEdges[x][y].y), layerId);
|
||||
}
|
||||
outputX += 1;
|
||||
if (blurPasses <= outputX && outputX < FFX_CACAO_TILE_WIDTH * FFX_CACAO_BLUR_WIDTH - blurPasses)
|
||||
{
|
||||
FFX_CACAO_EdgeSensitiveBlur_StoreOutput(imageCoord + FfxInt32x2(4 * x + 2, y), FfxFloat32x2(ssaoVal.z, packedEdges[x][y].z), layerId);
|
||||
}
|
||||
outputX += 1;
|
||||
if (blurPasses <= outputX && outputX < FFX_CACAO_TILE_WIDTH * FFX_CACAO_BLUR_WIDTH - blurPasses)
|
||||
{
|
||||
FFX_CACAO_EdgeSensitiveBlur_StoreOutput(imageCoord + FfxInt32x2(4 * x + 3, y), FfxFloat32x2(ssaoVal.w, packedEdges[x][y].w), layerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
struct FFX_CACAO_Edges_4
|
||||
{
|
||||
FfxFloat32x4 left;
|
||||
FfxFloat32x4 right;
|
||||
FfxFloat32x4 top;
|
||||
FfxFloat32x4 bottom;
|
||||
};
|
||||
|
||||
FFX_CACAO_Edges_4 FFX_CACAO_UnpackEdgesFloat32_4(FfxFloat32x4 _packedVal)
|
||||
{
|
||||
FfxUInt32x4 packedVal = FfxUInt32x4(_packedVal * 255.5);
|
||||
FFX_CACAO_Edges_4 result;
|
||||
result.left = ffxSaturate(((packedVal >> 6) & 0x03) / 3.0 + InvSharpness());
|
||||
result.right = ffxSaturate(((packedVal >> 4) & 0x03) / 3.0 + InvSharpness());
|
||||
result.top = ffxSaturate(((packedVal >> 2) & 0x03) / 3.0 + InvSharpness());
|
||||
result.bottom = ffxSaturate(((packedVal >> 0) & 0x03) / 3.0 + InvSharpness());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
FfxFloat32x4 FFX_CACAO_CalcBlurredSampleF32_4(FfxFloat32x4 packedEdges, FfxFloat32x4 centre, FfxFloat32x4 left, FfxFloat32x4 right, FfxFloat32x4 top, FfxFloat32x4 bottom)
|
||||
{
|
||||
FfxFloat32x4 sum = centre * FfxFloat32(0.5f);
|
||||
FfxFloat32x4 weight = FfxFloat32x4(0.5f, 0.5f, 0.5f, 0.5f);
|
||||
FFX_CACAO_Edges_4 edges = FFX_CACAO_UnpackEdgesFloat32_4(packedEdges);
|
||||
|
||||
sum += left * edges.left;
|
||||
weight += edges.left;
|
||||
sum += right * edges.right;
|
||||
weight += edges.right;
|
||||
sum += top * edges.top;
|
||||
weight += edges.top;
|
||||
sum += bottom * edges.bottom;
|
||||
weight += edges.bottom;
|
||||
|
||||
return sum / weight;
|
||||
}
|
||||
|
||||
void FFX_CACAO_LDSEdgeSensitiveBlur(const FfxUInt32 blurPasses, const FfxUInt32x2 tid, const FfxUInt32x2 gid, const FfxUInt32 layerId)
|
||||
{
|
||||
FfxInt32x2 imageCoord = FfxInt32x2(gid) * (FfxInt32x2(FFX_CACAO_TILE_WIDTH * FFX_CACAO_BLUR_WIDTH, FFX_CACAO_TILE_HEIGHT * FFX_CACAO_BLUR_HEIGHT) - FfxInt32(2*blurPasses)) + FfxInt32x2(FFX_CACAO_TILE_WIDTH, FFX_CACAO_TILE_HEIGHT) * FfxInt32x2(tid) - FfxInt32(blurPasses);
|
||||
FfxInt32x2 bufferCoord = FfxInt32x2(FFX_CACAO_HALF_TILE_WIDTH, FFX_CACAO_TILE_HEIGHT) * FfxInt32x2(tid) + 1;
|
||||
|
||||
FfxFloat32x4 packedEdges[FFX_CACAO_QUARTER_TILE_WIDTH][FFX_CACAO_TILE_HEIGHT];
|
||||
{
|
||||
FfxFloat32x2 inputVal[FFX_CACAO_TILE_WIDTH][FFX_CACAO_TILE_HEIGHT];
|
||||
FfxInt32 y;
|
||||
FFX_UNROLL
|
||||
for (y = 0; y < FFX_CACAO_TILE_HEIGHT; ++y)
|
||||
{
|
||||
FFX_UNROLL
|
||||
for (FfxInt32 x = 0; x < FFX_CACAO_TILE_WIDTH; ++x)
|
||||
{
|
||||
FfxFloat32x2 sampleUV = (FfxFloat32x2(imageCoord + FfxInt32x2(x, y)) + 0.5f) * SSAOBufferInverseDimensions();
|
||||
inputVal[x][y] = FFX_CACAO_EdgeSensitiveBlur_SampleInput(sampleUV, layerId);
|
||||
}
|
||||
}
|
||||
FFX_UNROLL
|
||||
for (y = 0; y < FFX_CACAO_TILE_HEIGHT; ++y)
|
||||
{
|
||||
FFX_UNROLL
|
||||
for (FfxInt32 x = 0; x < FFX_CACAO_QUARTER_TILE_WIDTH; ++x)
|
||||
{
|
||||
FfxFloat32x2 ssaoVals = FfxFloat32x2(inputVal[4 * x + 0][y].x, inputVal[4 * x + 1][y].x);
|
||||
s_FFX_CACAO_BlurF16Front_4[bufferCoord.x + 2*x + 0][bufferCoord.y + y] = ffxPackF32(ssaoVals);
|
||||
ssaoVals = FfxFloat32x2(inputVal[4 * x + 2][y].x, inputVal[4 * x + 3][y].x);
|
||||
s_FFX_CACAO_BlurF16Front_4[bufferCoord.x + 2*x + 1][bufferCoord.y + y] = ffxPackF32(ssaoVals);
|
||||
packedEdges[x][y] = FfxFloat32x4(inputVal[4 * x + 0][y].y, inputVal[4 * x + 1][y].y, inputVal[4 * x + 2][y].y, inputVal[4 * x + 3][y].y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FFX_GROUP_MEMORY_BARRIER;
|
||||
|
||||
FFX_UNROLL
|
||||
for (FfxUInt32 i = 0; i < (blurPasses + 1) / 2; ++i)
|
||||
{
|
||||
FFX_UNROLL
|
||||
for (FfxInt32 y = 0; y < FFX_CACAO_TILE_HEIGHT; ++y)
|
||||
{
|
||||
FFX_UNROLL
|
||||
for (FfxInt32 x = 0; x < FFX_CACAO_QUARTER_TILE_WIDTH; ++x)
|
||||
{
|
||||
FfxInt32x2 c = bufferCoord + FfxInt32x2(2*x, y);
|
||||
FfxFloat32x4 centre = FfxFloat32x4(ffxUnpackF32(s_FFX_CACAO_BlurF16Front_4[c.x + 0][c.y + 0]), ffxUnpackF32(s_FFX_CACAO_BlurF16Front_4[c.x + 1][c.y + 0]));
|
||||
FfxFloat32x4 top = FfxFloat32x4(ffxUnpackF32(s_FFX_CACAO_BlurF16Front_4[c.x + 0][c.y - 1]), ffxUnpackF32(s_FFX_CACAO_BlurF16Front_4[c.x + 1][c.y - 1]));
|
||||
FfxFloat32x4 bottom = FfxFloat32x4(ffxUnpackF32(s_FFX_CACAO_BlurF16Front_4[c.x + 0][c.y + 1]), ffxUnpackF32(s_FFX_CACAO_BlurF16Front_4[c.x + 1][c.y + 1]));
|
||||
|
||||
FfxFloat32x2 tmp = ffxUnpackF32(s_FFX_CACAO_BlurF16Front_4[c.x - 1][c.y + 0]);
|
||||
FfxFloat32x4 left = FfxFloat32x4(tmp.y, centre.xyz);
|
||||
tmp = ffxUnpackF32(s_FFX_CACAO_BlurF16Front_4[c.x + 2][c.y + 0]);
|
||||
FfxFloat32x4 right = FfxFloat32x4(centre.yzw, tmp.x);
|
||||
|
||||
FfxFloat32x4 tmp_4 = FFX_CACAO_CalcBlurredSampleF32_4(packedEdges[x][y], centre, left, right, top, bottom);
|
||||
s_FFX_CACAO_BlurF16Back_4[c.x + 0][c.y] = ffxPackF32(tmp_4.xy);
|
||||
s_FFX_CACAO_BlurF16Back_4[c.x + 1][c.y] = ffxPackF32(tmp_4.zw);
|
||||
}
|
||||
}
|
||||
FFX_GROUP_MEMORY_BARRIER;
|
||||
|
||||
if (2 * i + 1 < blurPasses)
|
||||
{
|
||||
FFX_UNROLL
|
||||
for (FfxInt32 y = 0; y < FFX_CACAO_TILE_HEIGHT; ++y)
|
||||
{
|
||||
FFX_UNROLL
|
||||
for (FfxInt32 x = 0; x < FFX_CACAO_QUARTER_TILE_WIDTH; ++x)
|
||||
{
|
||||
FfxInt32x2 c = bufferCoord + FfxInt32x2(2 * x, y);
|
||||
FfxFloat32x4 centre = FfxFloat32x4(ffxUnpackF32(s_FFX_CACAO_BlurF16Back_4[c.x + 0][c.y + 0]), ffxUnpackF32(s_FFX_CACAO_BlurF16Back_4[c.x + 1][c.y + 0]));
|
||||
FfxFloat32x4 top = FfxFloat32x4(ffxUnpackF32(s_FFX_CACAO_BlurF16Back_4[c.x + 0][c.y - 1]), ffxUnpackF32(s_FFX_CACAO_BlurF16Back_4[c.x + 1][c.y - 1]));
|
||||
FfxFloat32x4 bottom = FfxFloat32x4(ffxUnpackF32(s_FFX_CACAO_BlurF16Back_4[c.x + 0][c.y + 1]), ffxUnpackF32(s_FFX_CACAO_BlurF16Back_4[c.x + 1][c.y + 1]));
|
||||
|
||||
FfxFloat32x2 tmp = ffxUnpackF32(s_FFX_CACAO_BlurF16Back_4[c.x - 1][c.y + 0]);
|
||||
FfxFloat32x4 left = FfxFloat32x4(tmp.y, centre.xyz);
|
||||
tmp = ffxUnpackF32(s_FFX_CACAO_BlurF16Back_4[c.x + 2][c.y + 0]);
|
||||
FfxFloat32x4 right = FfxFloat32x4(centre.yzw, tmp.x);
|
||||
|
||||
FfxFloat32x4 tmp_4 = FFX_CACAO_CalcBlurredSampleF32_4(packedEdges[x][y], centre, left, right, top, bottom);
|
||||
s_FFX_CACAO_BlurF16Front_4[c.x + 0][c.y] = ffxPackF32(tmp_4.xy);
|
||||
s_FFX_CACAO_BlurF16Front_4[c.x + 1][c.y] = ffxPackF32(tmp_4.zw);
|
||||
}
|
||||
}
|
||||
FFX_GROUP_MEMORY_BARRIER;
|
||||
}
|
||||
}
|
||||
|
||||
FFX_UNROLL
|
||||
for (FfxUInt32 y = 0; y < FFX_CACAO_TILE_HEIGHT; ++y)
|
||||
{
|
||||
FfxUInt32 outputY = FFX_CACAO_TILE_HEIGHT * tid.y + y;
|
||||
if (blurPasses <= outputY && outputY < FFX_CACAO_TILE_HEIGHT * FFX_CACAO_BLUR_HEIGHT - blurPasses)
|
||||
{
|
||||
FFX_UNROLL
|
||||
for (FfxInt32 x = 0; x < FFX_CACAO_QUARTER_TILE_WIDTH; ++x)
|
||||
{
|
||||
FfxUInt32 outputX = FFX_CACAO_TILE_WIDTH * tid.x + 4 * x;
|
||||
|
||||
FfxFloat32x4 ssaoVal;
|
||||
if (blurPasses % 2 == 0)
|
||||
{
|
||||
ssaoVal = FfxFloat32x4(ffxUnpackF32(s_FFX_CACAO_BlurF16Front_4[bufferCoord.x + x][bufferCoord.y + y]), ffxUnpackF32(s_FFX_CACAO_BlurF16Front_4[bufferCoord.x + x + 1][bufferCoord.y + y]));
|
||||
}
|
||||
else
|
||||
{
|
||||
ssaoVal = FfxFloat32x4(ffxUnpackF32(s_FFX_CACAO_BlurF16Back_4[bufferCoord.x + x][bufferCoord.y + y]), ffxUnpackF32(s_FFX_CACAO_BlurF16Back_4[bufferCoord.x + x + 1][bufferCoord.y + y]));
|
||||
}
|
||||
|
||||
if (blurPasses <= outputX && outputX < FFX_CACAO_TILE_WIDTH * FFX_CACAO_BLUR_WIDTH - blurPasses)
|
||||
{
|
||||
FFX_CACAO_EdgeSensitiveBlur_StoreOutput(imageCoord + FfxInt32x2(4 * x, y), FfxFloat32x2(ssaoVal.x, packedEdges[x][y].x), layerId);
|
||||
}
|
||||
outputX += 1;
|
||||
if (blurPasses <= outputX && outputX < FFX_CACAO_TILE_WIDTH * FFX_CACAO_BLUR_WIDTH - blurPasses)
|
||||
{
|
||||
FFX_CACAO_EdgeSensitiveBlur_StoreOutput(imageCoord + FfxInt32x2(4 * x + 1, y), FfxFloat32x2(ssaoVal.y, packedEdges[x][y].y), layerId);
|
||||
}
|
||||
outputX += 1;
|
||||
if (blurPasses <= outputX && outputX < FFX_CACAO_TILE_WIDTH * FFX_CACAO_BLUR_WIDTH - blurPasses)
|
||||
{
|
||||
FFX_CACAO_EdgeSensitiveBlur_StoreOutput(imageCoord + FfxInt32x2(4 * x + 2, y), FfxFloat32x2(ssaoVal.z, packedEdges[x][y].z), layerId);
|
||||
}
|
||||
outputX += 1;
|
||||
if (blurPasses <= outputX && outputX < FFX_CACAO_TILE_WIDTH * FFX_CACAO_BLUR_WIDTH - blurPasses)
|
||||
{
|
||||
FFX_CACAO_EdgeSensitiveBlur_StoreOutput(imageCoord + FfxInt32x2(4 * x + 3, y), FfxFloat32x2(ssaoVal.w, packedEdges[x][y].w), layerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif //FFX_HALF
|
||||
|
||||
void FFX_CACAO_EdgeSensitiveBlur1(FfxUInt32x2 tid, FfxUInt32x3 gid)
|
||||
{
|
||||
FfxUInt32 layerId = gid.z;
|
||||
layerId = (layerId == 1 && BlurNumPasses() == 2) ? 3 : layerId;
|
||||
FFX_CACAO_LDSEdgeSensitiveBlur(1, tid, gid.xy, layerId);
|
||||
}
|
||||
|
||||
void FFX_CACAO_EdgeSensitiveBlur2(FfxUInt32x2 tid, FfxUInt32x3 gid)
|
||||
{
|
||||
FfxUInt32 layerId = gid.z;
|
||||
layerId = (layerId == 1 && BlurNumPasses() == 2) ? 3 : layerId;
|
||||
FFX_CACAO_LDSEdgeSensitiveBlur(2, tid, gid.xy, layerId);
|
||||
}
|
||||
|
||||
void FFX_CACAO_EdgeSensitiveBlur3(FfxUInt32x2 tid, FfxUInt32x3 gid)
|
||||
{
|
||||
FfxUInt32 layerId = gid.z;
|
||||
layerId = (layerId == 1 && BlurNumPasses() == 2) ? 3 : layerId;
|
||||
FFX_CACAO_LDSEdgeSensitiveBlur(3, tid, gid.xy, layerId);
|
||||
}
|
||||
|
||||
void FFX_CACAO_EdgeSensitiveBlur4(FfxUInt32x2 tid, FfxUInt32x3 gid)
|
||||
{
|
||||
FfxUInt32 layerId = gid.z;
|
||||
layerId = (layerId == 1 && BlurNumPasses() == 2) ? 3 : layerId;
|
||||
FFX_CACAO_LDSEdgeSensitiveBlur(4, tid, gid.xy, layerId);
|
||||
}
|
||||
|
||||
void FFX_CACAO_EdgeSensitiveBlur5(FfxUInt32x2 tid, FfxUInt32x3 gid)
|
||||
{
|
||||
FfxUInt32 layerId = gid.z;
|
||||
layerId = (layerId == 1 && BlurNumPasses() == 2) ? 3 : layerId;
|
||||
FFX_CACAO_LDSEdgeSensitiveBlur(5, tid, gid.xy, layerId);
|
||||
}
|
||||
|
||||
void FFX_CACAO_EdgeSensitiveBlur6(FfxUInt32x2 tid, FfxUInt32x3 gid)
|
||||
{
|
||||
FfxUInt32 layerId = gid.z;
|
||||
layerId = (layerId == 1 && BlurNumPasses() == 2) ? 3 : layerId;
|
||||
FFX_CACAO_LDSEdgeSensitiveBlur(6, tid, gid.xy, layerId);
|
||||
}
|
||||
|
||||
void FFX_CACAO_EdgeSensitiveBlur7(FfxUInt32x2 tid, FfxUInt32x3 gid)
|
||||
{
|
||||
FfxUInt32 layerId = gid.z;
|
||||
layerId = (layerId == 1 && BlurNumPasses() == 2) ? 3 : layerId;
|
||||
FFX_CACAO_LDSEdgeSensitiveBlur(7, tid, gid.xy, layerId);
|
||||
}
|
||||
|
||||
void FFX_CACAO_EdgeSensitiveBlur8(FfxUInt32x2 tid, FfxUInt32x3 gid)
|
||||
{
|
||||
FfxUInt32 layerId = gid.z;
|
||||
layerId = (layerId == 1 && BlurNumPasses() == 2) ? 3 : layerId;
|
||||
FFX_CACAO_LDSEdgeSensitiveBlur(8, tid, gid.xy, layerId);
|
||||
}
|
||||
|
||||
#undef FFX_CACAO_TILE_WIDTH
|
||||
#undef FFX_CACAO_TILE_HEIGHT
|
||||
#undef FFX_CACAO_HALF_TILE_WIDTH
|
||||
#undef FFX_CACAO_QUARTER_TILE_WIDTH
|
||||
#undef FFX_CACAO_ARRAY_WIDTH
|
||||
#undef FFX_CACAO_ARRAY_HEIGHT
|
||||
#undef FFX_CACAO_ITERS
|
||||
111
betterRenderer/thirdparty/fsr2/include/FidelityFX/gpu/cacao/ffx_cacao_importance_map.h
vendored
Normal file
111
betterRenderer/thirdparty/fsr2/include/FidelityFX/gpu/cacao/ffx_cacao_importance_map.h
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
// This file is part of the FidelityFX SDK.
|
||||
//
|
||||
// Copyright (C) 2024 Advanced Micro Devices, Inc.
|
||||
//
|
||||
// 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.
|
||||
|
||||
#include "ffx_core.h"
|
||||
#include "ffx_cacao_defines.h"
|
||||
#include "ffx_cacao_utils.h"
|
||||
|
||||
void FFX_CACAO_GenerateImportanceMap(FfxUInt32x2 tid)
|
||||
{
|
||||
FfxUInt32x2 basePos = tid * 2;
|
||||
|
||||
FfxFloat32x2 baseUV = (FfxFloat32x2(basePos) + 1.0f) * SSAOBufferInverseDimensions();
|
||||
|
||||
FfxFloat32 avg = 0.0;
|
||||
FfxFloat32 minV = 1.0;
|
||||
FfxFloat32 maxV = 0.0;
|
||||
FFX_UNROLL
|
||||
for (FfxInt32 i = 0; i < 4; i++)
|
||||
{
|
||||
FfxFloat32x4 vals = FFX_CACAO_Importance_GatherSSAO(baseUV, i);
|
||||
|
||||
// apply the same modifications that would have been applied in the main shader
|
||||
vals = EffectShadowStrength() * vals;
|
||||
|
||||
vals = 1 - vals;
|
||||
|
||||
vals = pow(ffxSaturate(vals), FfxFloat32x4(EffectShadowPow(), EffectShadowPow(), EffectShadowPow(), EffectShadowPow()));
|
||||
|
||||
avg += dot(FfxFloat32x4(vals.x, vals.y, vals.z, vals.w), FfxFloat32x4(1.0 / 16.0, 1.0 / 16.0, 1.0 / 16.0, 1.0 / 16.0));
|
||||
|
||||
maxV = max(maxV, max(max(vals.x, vals.y), max(vals.z, vals.w)));
|
||||
minV = min(minV, min(min(vals.x, vals.y), min(vals.z, vals.w)));
|
||||
}
|
||||
|
||||
FfxFloat32 minMaxDiff = maxV - minV;
|
||||
|
||||
FFX_CACAO_Importance_StoreImportance(tid, pow(ffxSaturate(minMaxDiff * 2.0), 0.8f));
|
||||
}
|
||||
|
||||
FFX_STATIC const FfxFloat32 c_FFX_CACAO_SmoothenImportance = 1.0f;
|
||||
|
||||
void FFX_CACAO_PostprocessImportanceMapA(FfxUInt32x2 tid)
|
||||
{
|
||||
FfxFloat32x2 uv = (FfxFloat32x2(tid)+0.5f) * ImportanceMapInverseDimensions();
|
||||
|
||||
FfxFloat32 centre = FFX_CACAO_Importance_SampleImportanceA(uv);
|
||||
|
||||
FfxFloat32x2 halfPixel = 0.5f * ImportanceMapInverseDimensions();
|
||||
|
||||
FfxFloat32x4 vals;
|
||||
vals.x = FFX_CACAO_Importance_SampleImportanceA(uv + FfxFloat32x2(-halfPixel.x * 3, -halfPixel.y));
|
||||
vals.y = FFX_CACAO_Importance_SampleImportanceA(uv + FfxFloat32x2(+halfPixel.x, -halfPixel.y * 3));
|
||||
vals.z = FFX_CACAO_Importance_SampleImportanceA(uv + FfxFloat32x2(+halfPixel.x * 3, +halfPixel.y));
|
||||
vals.w = FFX_CACAO_Importance_SampleImportanceA(uv + FfxFloat32x2(-halfPixel.x, +halfPixel.y * 3));
|
||||
|
||||
FfxFloat32 avgVal = dot(vals, FfxFloat32x4(0.25, 0.25, 0.25, 0.25));
|
||||
vals.xy = max(vals.xy, vals.zw);
|
||||
FfxFloat32 maxVal = max(centre, max(vals.x, vals.y));
|
||||
|
||||
FFX_CACAO_Importance_StoreImportanceA(tid, ffxLerp(maxVal, avgVal, c_FFX_CACAO_SmoothenImportance));
|
||||
}
|
||||
|
||||
void FFX_CACAO_PostprocessImportanceMapB(FfxUInt32x2 tid)
|
||||
{
|
||||
FfxFloat32x2 uv = (FfxFloat32x2(tid)+0.5f) * ImportanceMapInverseDimensions();
|
||||
|
||||
FfxFloat32 centre = FFX_CACAO_Importance_SampleImportanceB(uv);
|
||||
|
||||
FfxFloat32x2 halfPixel = 0.5f * ImportanceMapInverseDimensions();
|
||||
|
||||
FfxFloat32x4 vals;
|
||||
vals.x = FFX_CACAO_Importance_SampleImportanceB(uv + FfxFloat32x2(-halfPixel.x, -halfPixel.y * 3));
|
||||
vals.y = FFX_CACAO_Importance_SampleImportanceB(uv + FfxFloat32x2(+halfPixel.x * 3, -halfPixel.y));
|
||||
vals.z = FFX_CACAO_Importance_SampleImportanceB(uv + FfxFloat32x2(+halfPixel.x, +halfPixel.y * 3));
|
||||
vals.w = FFX_CACAO_Importance_SampleImportanceB(uv + FfxFloat32x2(-halfPixel.x * 3, +halfPixel.y));
|
||||
|
||||
FfxFloat32 avgVal = dot(vals, FfxFloat32x4(0.25, 0.25, 0.25, 0.25));
|
||||
vals.xy = max(vals.xy, vals.zw);
|
||||
FfxFloat32 maxVal = max(centre, max(vals.x, vals.y));
|
||||
|
||||
FfxFloat32 retVal = ffxLerp(maxVal, avgVal, c_FFX_CACAO_SmoothenImportance);
|
||||
FFX_CACAO_Importance_StoreImportanceB(tid, retVal);
|
||||
|
||||
// sum the average; to avoid overflowing we assume max AO resolution is not bigger than 16384x16384; so quarter res (used here) will be 4096x4096, which leaves us with 8 bits per pixel
|
||||
FfxUInt32 sum = FfxUInt32(ffxSaturate(retVal) * 255.0 + 0.5);
|
||||
|
||||
// save every 9th to avoid InterlockedAdd congestion - since we're blurring, this is good enough; compensated by multiplying LoadCounterAvgDiv by 9
|
||||
if (((tid.x % 3) + (tid.y % 3)) == 0)
|
||||
{
|
||||
FFX_CACAO_Importance_LoadCounterInterlockedAdd(sum);
|
||||
}
|
||||
}
|
||||
310
betterRenderer/thirdparty/fsr2/include/FidelityFX/gpu/cacao/ffx_cacao_prepare.h
vendored
Normal file
310
betterRenderer/thirdparty/fsr2/include/FidelityFX/gpu/cacao/ffx_cacao_prepare.h
vendored
Normal file
@@ -0,0 +1,310 @@
|
||||
// This file is part of the FidelityFX SDK.
|
||||
//
|
||||
// Copyright (C) 2024 Advanced Micro Devices, Inc.
|
||||
//
|
||||
// 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.
|
||||
|
||||
#include "ffx_core.h"
|
||||
#include "ffx_cacao_defines.h"
|
||||
#include "ffx_cacao_utils.h"
|
||||
|
||||
FFX_GROUPSHARED FfxFloat32 s_FFX_CACAO_PrepareDepthsAndMipsBuffer[4][8][8];
|
||||
|
||||
FfxFloat32 FFX_CACAO_MipSmartAverage(FfxFloat32x4 depths)
|
||||
{
|
||||
FfxFloat32 closest = min(min(depths.x, depths.y), min(depths.z, depths.w));
|
||||
FfxFloat32 falloffCalcMulSq = -1.0f / EffectRadius() * EffectRadius();
|
||||
FfxFloat32x4 dists = depths - closest.xxxx;
|
||||
FfxFloat32x4 weights = ffxSaturate(dists * dists * falloffCalcMulSq + 1.0);
|
||||
return dot(weights, depths) / dot(weights, FfxFloat32x4(1.0, 1.0, 1.0, 1.0));
|
||||
}
|
||||
|
||||
void FFX_CACAO_PrepareDepthsAndMips(FfxFloat32x4 samples, FfxUInt32x2 outputCoord, FfxUInt32x2 gtid)
|
||||
{
|
||||
samples = FFX_CACAO_ScreenSpaceToViewSpaceDepth(samples);
|
||||
|
||||
s_FFX_CACAO_PrepareDepthsAndMipsBuffer[0][gtid.x][gtid.y] = samples.w;
|
||||
s_FFX_CACAO_PrepareDepthsAndMipsBuffer[1][gtid.x][gtid.y] = samples.z;
|
||||
s_FFX_CACAO_PrepareDepthsAndMipsBuffer[2][gtid.x][gtid.y] = samples.x;
|
||||
s_FFX_CACAO_PrepareDepthsAndMipsBuffer[3][gtid.x][gtid.y] = samples.y;
|
||||
|
||||
FFX_CACAO_Prepare_StoreDepthMip0(outputCoord, 0, samples.w);
|
||||
FFX_CACAO_Prepare_StoreDepthMip0(outputCoord, 1, samples.z);
|
||||
FFX_CACAO_Prepare_StoreDepthMip0(outputCoord, 2, samples.x);
|
||||
FFX_CACAO_Prepare_StoreDepthMip0(outputCoord, 3, samples.y);
|
||||
|
||||
FfxUInt32 depthArrayIndex = 2 * (gtid.y % 2) + (gtid.x % 2);
|
||||
FfxUInt32x2 depthArrayOffset = FfxInt32x2(gtid.x % 2, gtid.y % 2);
|
||||
FfxInt32x2 bufferCoord = FfxInt32x2(gtid) - FfxInt32x2(depthArrayOffset);
|
||||
|
||||
outputCoord /= 2;
|
||||
FFX_GROUP_MEMORY_BARRIER;
|
||||
|
||||
// if (stillAlive) <-- all threads alive here
|
||||
{
|
||||
FfxFloat32 sample_00 = s_FFX_CACAO_PrepareDepthsAndMipsBuffer[depthArrayIndex][bufferCoord.x + 0][bufferCoord.y + 0];
|
||||
FfxFloat32 sample_01 = s_FFX_CACAO_PrepareDepthsAndMipsBuffer[depthArrayIndex][bufferCoord.x + 0][bufferCoord.y + 1];
|
||||
FfxFloat32 sample_10 = s_FFX_CACAO_PrepareDepthsAndMipsBuffer[depthArrayIndex][bufferCoord.x + 1][bufferCoord.y + 0];
|
||||
FfxFloat32 sample_11 = s_FFX_CACAO_PrepareDepthsAndMipsBuffer[depthArrayIndex][bufferCoord.x + 1][bufferCoord.y + 1];
|
||||
|
||||
FfxFloat32 avg = FFX_CACAO_MipSmartAverage(FfxFloat32x4(sample_00, sample_01, sample_10, sample_11));
|
||||
FFX_CACAO_Prepare_StoreDepthMip1(outputCoord, depthArrayIndex, avg);
|
||||
s_FFX_CACAO_PrepareDepthsAndMipsBuffer[depthArrayIndex][bufferCoord.x][bufferCoord.y] = avg;
|
||||
}
|
||||
|
||||
bool stillAlive = gtid.x % 4 == depthArrayOffset.x && gtid.y % 4 == depthArrayOffset.y;
|
||||
|
||||
outputCoord /= 2;
|
||||
FFX_GROUP_MEMORY_BARRIER;
|
||||
|
||||
if (stillAlive)
|
||||
{
|
||||
FfxFloat32 sample_00 = s_FFX_CACAO_PrepareDepthsAndMipsBuffer[depthArrayIndex][bufferCoord.x + 0][bufferCoord.y + 0];
|
||||
FfxFloat32 sample_01 = s_FFX_CACAO_PrepareDepthsAndMipsBuffer[depthArrayIndex][bufferCoord.x + 0][bufferCoord.y + 2];
|
||||
FfxFloat32 sample_10 = s_FFX_CACAO_PrepareDepthsAndMipsBuffer[depthArrayIndex][bufferCoord.x + 2][bufferCoord.y + 0];
|
||||
FfxFloat32 sample_11 = s_FFX_CACAO_PrepareDepthsAndMipsBuffer[depthArrayIndex][bufferCoord.x + 2][bufferCoord.y + 2];
|
||||
|
||||
FfxFloat32 avg = FFX_CACAO_MipSmartAverage(FfxFloat32x4(sample_00, sample_01, sample_10, sample_11));
|
||||
FFX_CACAO_Prepare_StoreDepthMip2(outputCoord, depthArrayIndex, avg);
|
||||
s_FFX_CACAO_PrepareDepthsAndMipsBuffer[depthArrayIndex][bufferCoord.x][bufferCoord.y] = avg;
|
||||
}
|
||||
|
||||
stillAlive = gtid.x % 8 == depthArrayOffset.x && gtid.y % 8 == depthArrayOffset.y;
|
||||
|
||||
outputCoord /= 2;
|
||||
FFX_GROUP_MEMORY_BARRIER;
|
||||
|
||||
if (stillAlive)
|
||||
{
|
||||
FfxFloat32 sample_00 = s_FFX_CACAO_PrepareDepthsAndMipsBuffer[depthArrayIndex][bufferCoord.x + 0][bufferCoord.y + 0];
|
||||
FfxFloat32 sample_01 = s_FFX_CACAO_PrepareDepthsAndMipsBuffer[depthArrayIndex][bufferCoord.x + 0][bufferCoord.y + 4];
|
||||
FfxFloat32 sample_10 = s_FFX_CACAO_PrepareDepthsAndMipsBuffer[depthArrayIndex][bufferCoord.x + 4][bufferCoord.y + 0];
|
||||
FfxFloat32 sample_11 = s_FFX_CACAO_PrepareDepthsAndMipsBuffer[depthArrayIndex][bufferCoord.x + 4][bufferCoord.y + 4];
|
||||
|
||||
FfxFloat32 avg = FFX_CACAO_MipSmartAverage(FfxFloat32x4(sample_00, sample_01, sample_10, sample_11));
|
||||
FFX_CACAO_Prepare_StoreDepthMip3(outputCoord, depthArrayIndex, avg);
|
||||
}
|
||||
}
|
||||
|
||||
void FFX_CACAO_PrepareDownsampledDepthsAndMips(FfxUInt32x2 tid, FfxUInt32x2 gtid)
|
||||
{
|
||||
FfxInt32x2 depthBufferCoord = 4 * FfxInt32x2(tid.xy);
|
||||
FfxInt32x2 outputCoord = FfxInt32x2(tid);
|
||||
|
||||
FfxFloat32x2 uv = (FfxFloat32x2(depthBufferCoord)+0.5f) * DepthBufferInverseDimensions();
|
||||
FfxFloat32x4 samples = FFX_CACAO_Prepare_SampleDepthOffsets(uv);
|
||||
|
||||
FFX_CACAO_PrepareDepthsAndMips(samples, outputCoord, gtid);
|
||||
}
|
||||
|
||||
void FFX_CACAO_PrepareNativeDepthsAndMips(FfxUInt32x2 tid, FfxUInt32x2 gtid)
|
||||
{
|
||||
FfxInt32x2 depthBufferCoord = 2 * FfxInt32x2(tid.xy);
|
||||
FfxInt32x2 outputCoord = FfxInt32x2(tid);
|
||||
|
||||
FfxFloat32x2 uv = (FfxFloat32x2(depthBufferCoord)+ 1.0f) * DepthBufferInverseDimensions();
|
||||
FfxFloat32x4 samples = FFX_CACAO_Prepare_GatherDepth(uv);
|
||||
|
||||
FFX_CACAO_PrepareDepthsAndMips(samples, outputCoord, gtid);
|
||||
}
|
||||
|
||||
void FFX_CACAO_PrepareDepths(FfxFloat32x4 samples, FfxUInt32x2 tid)
|
||||
{
|
||||
samples = FFX_CACAO_ScreenSpaceToViewSpaceDepth(samples);
|
||||
FFX_CACAO_Prepare_StoreDepth(tid, 0, samples.w);
|
||||
FFX_CACAO_Prepare_StoreDepth(tid, 1, samples.z);
|
||||
FFX_CACAO_Prepare_StoreDepth(tid, 2, samples.x);
|
||||
FFX_CACAO_Prepare_StoreDepth(tid, 3, samples.y);
|
||||
}
|
||||
|
||||
void FFX_CACAO_PrepareDownsampledDepths(FfxUInt32x2 tid)
|
||||
{
|
||||
FfxInt32x2 depthBufferCoord = 4 * FfxInt32x2(tid.xy);
|
||||
|
||||
FfxFloat32x2 uv = (FfxFloat32x2(depthBufferCoord)+0.5f) * DepthBufferInverseDimensions();
|
||||
FfxFloat32x4 samples = FFX_CACAO_Prepare_SampleDepthOffsets(uv);
|
||||
|
||||
FFX_CACAO_PrepareDepths(samples, tid);
|
||||
}
|
||||
|
||||
void FFX_CACAO_PrepareNativeDepths(FfxUInt32x2 tid)
|
||||
{
|
||||
FfxInt32x2 depthBufferCoord = 2 * FfxInt32x2(tid.xy);
|
||||
|
||||
FfxFloat32x2 uv = (FfxFloat32x2(depthBufferCoord) + 1.0f) * DepthBufferInverseDimensions();
|
||||
FfxFloat32x4 samples = FFX_CACAO_Prepare_GatherDepth(uv);
|
||||
|
||||
FFX_CACAO_PrepareDepths(samples, tid);
|
||||
}
|
||||
|
||||
void FFX_CACAO_PrepareDownsampledDepthsHalf(FfxUInt32x2 tid)
|
||||
{
|
||||
FfxFloat32 sample_00 = FFX_CACAO_Prepare_LoadDepth(FfxInt32x2(4 * tid.x + 0, 4 * tid.y + 0));
|
||||
FfxFloat32 sample_11 = FFX_CACAO_Prepare_LoadDepth(FfxInt32x2(4 * tid.x + 2, 4 * tid.y + 2));
|
||||
sample_00 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(sample_00);
|
||||
sample_11 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(sample_11);
|
||||
FFX_CACAO_Prepare_StoreDepth(tid, 0, sample_00);
|
||||
FFX_CACAO_Prepare_StoreDepth(tid, 3, sample_11);
|
||||
}
|
||||
|
||||
void FFX_CACAO_PrepareNativeDepthsHalf(FfxUInt32x2 tid)
|
||||
{
|
||||
FfxFloat32 sample_00 = FFX_CACAO_Prepare_LoadDepth(FfxInt32x2(2 * tid.x + 0, 2 * tid.y + 0));
|
||||
FfxFloat32 sample_11 = FFX_CACAO_Prepare_LoadDepth(FfxInt32x2(2 * tid.x + 1, 2 * tid.y + 1));
|
||||
sample_00 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(sample_00);
|
||||
sample_11 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(sample_11);
|
||||
FFX_CACAO_Prepare_StoreDepth(tid, 0, sample_00);
|
||||
FFX_CACAO_Prepare_StoreDepth(tid, 3, sample_11);
|
||||
}
|
||||
|
||||
struct FFX_CACAO_PrepareNormalsInputDepths
|
||||
{
|
||||
FfxFloat32 depth_10;
|
||||
FfxFloat32 depth_20;
|
||||
|
||||
FfxFloat32 depth_01;
|
||||
FfxFloat32 depth_11;
|
||||
FfxFloat32 depth_21;
|
||||
FfxFloat32 depth_31;
|
||||
|
||||
FfxFloat32 depth_02;
|
||||
FfxFloat32 depth_12;
|
||||
FfxFloat32 depth_22;
|
||||
FfxFloat32 depth_32;
|
||||
|
||||
FfxFloat32 depth_13;
|
||||
FfxFloat32 depth_23;
|
||||
};
|
||||
|
||||
void FFX_CACAO_PrepareNormals(FFX_CACAO_PrepareNormalsInputDepths depths, FfxFloat32x2 uv, FfxFloat32x2 pixelSize, FfxUInt32x2 normalCoord)
|
||||
{
|
||||
FfxFloat32x3 p_10 = FFX_CACAO_NDCToViewSpace(uv + FfxFloat32x2(+0.0f, -1.0f) * pixelSize, depths.depth_10);
|
||||
FfxFloat32x3 p_20 = FFX_CACAO_NDCToViewSpace(uv + FfxFloat32x2(+1.0f, -1.0f) * pixelSize, depths.depth_20);
|
||||
|
||||
FfxFloat32x3 p_01 = FFX_CACAO_NDCToViewSpace(uv + FfxFloat32x2(-1.0f, +0.0f) * pixelSize, depths.depth_01);
|
||||
FfxFloat32x3 p_11 = FFX_CACAO_NDCToViewSpace(uv + FfxFloat32x2(+0.0f, +0.0f) * pixelSize, depths.depth_11);
|
||||
FfxFloat32x3 p_21 = FFX_CACAO_NDCToViewSpace(uv + FfxFloat32x2(+1.0f, +0.0f) * pixelSize, depths.depth_21);
|
||||
FfxFloat32x3 p_31 = FFX_CACAO_NDCToViewSpace(uv + FfxFloat32x2(+2.0f, +0.0f) * pixelSize, depths.depth_31);
|
||||
|
||||
FfxFloat32x3 p_02 = FFX_CACAO_NDCToViewSpace(uv + FfxFloat32x2(-1.0f, +1.0f) * pixelSize, depths.depth_02);
|
||||
FfxFloat32x3 p_12 = FFX_CACAO_NDCToViewSpace(uv + FfxFloat32x2(+0.0f, +1.0f) * pixelSize, depths.depth_12);
|
||||
FfxFloat32x3 p_22 = FFX_CACAO_NDCToViewSpace(uv + FfxFloat32x2(+1.0f, +1.0f) * pixelSize, depths.depth_22);
|
||||
FfxFloat32x3 p_32 = FFX_CACAO_NDCToViewSpace(uv + FfxFloat32x2(+2.0f, +1.0f) * pixelSize, depths.depth_32);
|
||||
|
||||
FfxFloat32x3 p_13 = FFX_CACAO_NDCToViewSpace(uv + FfxFloat32x2(+0.0f, +2.0f) * pixelSize, depths.depth_13);
|
||||
FfxFloat32x3 p_23 = FFX_CACAO_NDCToViewSpace(uv + FfxFloat32x2(+1.0f, +2.0f) * pixelSize, depths.depth_23);
|
||||
|
||||
FfxFloat32x4 edges_11 = FFX_CACAO_CalculateEdges(p_11.z, p_01.z, p_21.z, p_10.z, p_12.z);
|
||||
FfxFloat32x4 edges_21 = FFX_CACAO_CalculateEdges(p_21.z, p_11.z, p_31.z, p_20.z, p_22.z);
|
||||
FfxFloat32x4 edges_12 = FFX_CACAO_CalculateEdges(p_12.z, p_02.z, p_22.z, p_11.z, p_13.z);
|
||||
FfxFloat32x4 edges_22 = FFX_CACAO_CalculateEdges(p_22.z, p_12.z, p_32.z, p_21.z, p_23.z);
|
||||
|
||||
FfxFloat32x3 norm_11 = FFX_CACAO_CalculateNormal(edges_11, p_11, p_01, p_21, p_10, p_12);
|
||||
FfxFloat32x3 norm_21 = FFX_CACAO_CalculateNormal(edges_21, p_21, p_11, p_31, p_20, p_22);
|
||||
FfxFloat32x3 norm_12 = FFX_CACAO_CalculateNormal(edges_12, p_12, p_02, p_22, p_11, p_13);
|
||||
FfxFloat32x3 norm_22 = FFX_CACAO_CalculateNormal(edges_22, p_22, p_12, p_32, p_21, p_23);
|
||||
|
||||
FFX_CACAO_Prepare_StoreNormal(normalCoord, 0, norm_11);
|
||||
FFX_CACAO_Prepare_StoreNormal(normalCoord, 1, norm_21);
|
||||
FFX_CACAO_Prepare_StoreNormal(normalCoord, 2, norm_12);
|
||||
FFX_CACAO_Prepare_StoreNormal(normalCoord, 3, norm_22);
|
||||
}
|
||||
|
||||
void FFX_CACAO_PrepareDownsampledNormals(FfxUInt32x2 tid)
|
||||
{
|
||||
FfxInt32x2 depthCoord = 4 * FfxInt32x2(tid) + DepthBufferOffset();
|
||||
|
||||
FFX_CACAO_PrepareNormalsInputDepths depths;
|
||||
|
||||
depths.depth_10 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(FFX_CACAO_Prepare_LoadDepthOffset(depthCoord, FfxInt32x2(+0, -2)));
|
||||
depths.depth_20 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(FFX_CACAO_Prepare_LoadDepthOffset(depthCoord, FfxInt32x2(+2, -2)));
|
||||
|
||||
depths.depth_01 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(FFX_CACAO_Prepare_LoadDepthOffset(depthCoord, FfxInt32x2(-2, +0)));
|
||||
depths.depth_11 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(FFX_CACAO_Prepare_LoadDepthOffset(depthCoord, FfxInt32x2(+0, +0)));
|
||||
depths.depth_21 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(FFX_CACAO_Prepare_LoadDepthOffset(depthCoord, FfxInt32x2(+2, +0)));
|
||||
depths.depth_31 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(FFX_CACAO_Prepare_LoadDepthOffset(depthCoord, FfxInt32x2(+4, +0)));
|
||||
|
||||
depths.depth_02 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(FFX_CACAO_Prepare_LoadDepthOffset(depthCoord, FfxInt32x2(-2, +2)));
|
||||
depths.depth_12 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(FFX_CACAO_Prepare_LoadDepthOffset(depthCoord, FfxInt32x2(+0, +2)));
|
||||
depths.depth_22 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(FFX_CACAO_Prepare_LoadDepthOffset(depthCoord, FfxInt32x2(+2, +2)));
|
||||
depths.depth_32 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(FFX_CACAO_Prepare_LoadDepthOffset(depthCoord, FfxInt32x2(+4, +2)));
|
||||
|
||||
depths.depth_13 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(FFX_CACAO_Prepare_LoadDepthOffset(depthCoord, FfxInt32x2(+0, +4)));
|
||||
depths.depth_23 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(FFX_CACAO_Prepare_LoadDepthOffset(depthCoord, FfxInt32x2(+2, +4)));
|
||||
|
||||
FfxFloat32x2 pixelSize = 2.0f * OutputBufferInverseDimensions();
|
||||
FfxFloat32x2 uv = (FfxFloat32x2(4 * tid) + 0.5f) * OutputBufferInverseDimensions();
|
||||
|
||||
FFX_CACAO_PrepareNormals(depths, uv, pixelSize, tid);
|
||||
}
|
||||
|
||||
void FFX_CACAO_PrepareNativeNormals(FfxUInt32x2 tid)
|
||||
{
|
||||
FfxInt32x2 depthCoord = 2 * FfxInt32x2(tid) + DepthBufferOffset();
|
||||
FfxFloat32x2 depthBufferUV = FfxFloat32x2(depthCoord) * DepthBufferInverseDimensions();
|
||||
FfxFloat32x4 samples_00 = FFX_CACAO_Prepare_GatherDepthOffset(depthBufferUV, FfxInt32x2(0, 0)); //CACAO_TODO fix gather
|
||||
FfxFloat32x4 samples_10 = FFX_CACAO_Prepare_GatherDepthOffset(depthBufferUV, FfxInt32x2(2, 0));
|
||||
FfxFloat32x4 samples_01 = FFX_CACAO_Prepare_GatherDepthOffset(depthBufferUV, FfxInt32x2(0, 2));
|
||||
FfxFloat32x4 samples_11 = FFX_CACAO_Prepare_GatherDepthOffset(depthBufferUV, FfxInt32x2(2, 2));
|
||||
|
||||
FFX_CACAO_PrepareNormalsInputDepths depths;
|
||||
|
||||
depths.depth_10 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(samples_00.z);
|
||||
depths.depth_20 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(samples_10.w);
|
||||
|
||||
depths.depth_01 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(samples_00.x);
|
||||
depths.depth_11 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(samples_00.y);
|
||||
depths.depth_21 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(samples_10.x);
|
||||
depths.depth_31 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(samples_10.y);
|
||||
|
||||
depths.depth_02 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(samples_01.w);
|
||||
depths.depth_12 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(samples_01.z);
|
||||
depths.depth_22 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(samples_11.w);
|
||||
depths.depth_32 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(samples_11.z);
|
||||
|
||||
depths.depth_13 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(samples_01.y);
|
||||
depths.depth_23 = FFX_CACAO_ScreenSpaceToViewSpaceDepth(samples_11.x);
|
||||
|
||||
// use unused samples to make sure compiler doesn't overlap memory and put a sync
|
||||
// between loads
|
||||
FfxFloat32 epsilon = (samples_00.w + samples_10.z + samples_01.x + samples_11.y) * 1e-20f;
|
||||
|
||||
FfxFloat32x2 pixelSize = OutputBufferInverseDimensions();
|
||||
FfxFloat32x2 uv = (FfxFloat32x2(2 * tid) + 0.5f + epsilon) * OutputBufferInverseDimensions();
|
||||
|
||||
FFX_CACAO_PrepareNormals(depths, uv, pixelSize, tid);
|
||||
}
|
||||
|
||||
void FFX_CACAO_PrepareDownsampledNormalsFromInputNormals(FfxUInt32x2 tid)
|
||||
{
|
||||
FfxUInt32x2 baseCoord = 4 * tid;
|
||||
FFX_CACAO_Prepare_StoreNormal(tid, 0, FFX_CACAO_Prepare_LoadNormal(baseCoord + FfxUInt32x2(0, 0)));
|
||||
FFX_CACAO_Prepare_StoreNormal(tid, 1, FFX_CACAO_Prepare_LoadNormal(baseCoord + FfxUInt32x2(2, 0)));
|
||||
FFX_CACAO_Prepare_StoreNormal(tid, 2, FFX_CACAO_Prepare_LoadNormal(baseCoord + FfxUInt32x2(0, 2)));
|
||||
FFX_CACAO_Prepare_StoreNormal(tid, 3, FFX_CACAO_Prepare_LoadNormal(baseCoord + FfxUInt32x2(2, 2)));
|
||||
}
|
||||
|
||||
void FFX_CACAO_PrepareNativeNormalsFromInputNormals(FfxUInt32x2 tid)
|
||||
{
|
||||
FfxUInt32x2 baseCoord = 2 * tid;
|
||||
FFX_CACAO_Prepare_StoreNormal(tid, 0, FFX_CACAO_Prepare_LoadNormal(baseCoord + FfxUInt32x2(0, 0)));
|
||||
FFX_CACAO_Prepare_StoreNormal(tid, 1, FFX_CACAO_Prepare_LoadNormal(baseCoord + FfxUInt32x2(1, 0)));
|
||||
FFX_CACAO_Prepare_StoreNormal(tid, 2, FFX_CACAO_Prepare_LoadNormal(baseCoord + FfxUInt32x2(0, 1)));
|
||||
FFX_CACAO_Prepare_StoreNormal(tid, 3, FFX_CACAO_Prepare_LoadNormal(baseCoord + FfxUInt32x2(1, 1)));
|
||||
}
|
||||
50
betterRenderer/thirdparty/fsr2/include/FidelityFX/gpu/cacao/ffx_cacao_resources.h
vendored
Normal file
50
betterRenderer/thirdparty/fsr2/include/FidelityFX/gpu/cacao/ffx_cacao_resources.h
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
// This file is part of the FidelityFX SDK.
|
||||
//
|
||||
// Copyright (C) 2024 Advanced Micro Devices, Inc.
|
||||
//
|
||||
// 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.
|
||||
|
||||
#ifndef FFX_CACAO_RESOURCES_H
|
||||
#define FFX_CACAO_RESOURCES_H
|
||||
|
||||
#if defined(FFX_CPU) || defined(FFX_GPU)
|
||||
#define FFX_FSR2_RESOURCE_IDENTIFIER_NULL 0
|
||||
#define FFX_CACAO_RESOURCE_IDENTIFIER_DEPTH_IN 1
|
||||
#define FFX_CACAO_RESOURCE_IDENTIFIER_NORMAL_IN 2
|
||||
#define FFX_CACAO_RESOURCE_IDENTIFIER_DEINTERLEAVED_DEPTHS 3
|
||||
#define FFX_CACAO_RESOURCE_IDENTIFIER_DEINTERLEAVED_NORMALS 4
|
||||
#define FFX_CACAO_RESOURCE_IDENTIFIER_SSAO_BUFFER_PING 5
|
||||
#define FFX_CACAO_RESOURCE_IDENTIFIER_SSAO_BUFFER_PONG 6
|
||||
#define FFX_CACAO_RESOURCE_IDENTIFIER_IMPORTANCE_MAP 7
|
||||
#define FFX_CACAO_RESOURCE_IDENTIFIER_IMPORTANCE_MAP_PONG 8
|
||||
#define FFX_CACAO_RESOURCE_IDENTIFIER_DOWNSAMPLED_SSAO_BUFFER 9
|
||||
#define FFX_CACAO_RESOURCE_IDENTIFIER_LOAD_COUNTER_BUFFER 10
|
||||
#define FFX_CACAO_RESOURCE_IDENTIFIER_OUTPUT 11
|
||||
#define FFX_CACAO_RESOURCE_IDENTIFIER_DOWNSAMPLED_DEPTH_MIPMAP_0 12
|
||||
#define FFX_CACAO_RESOURCE_IDENTIFIER_DOWNSAMPLED_DEPTH_MIPMAP_1 13
|
||||
#define FFX_CACAO_RESOURCE_IDENTIFIER_DOWNSAMPLED_DEPTH_MIPMAP_2 14
|
||||
#define FFX_CACAO_RESOURCE_IDENTIFIER_DOWNSAMPLED_DEPTH_MIPMAP_3 15
|
||||
#define FFX_CACAO_RESOURCE_IDENTIFIER_COUNT 16
|
||||
|
||||
#define FFX_CACAO_CONSTANTBUFFER_IDENTIFIER_CACAO 0
|
||||
#define FFX_CACAO_CONSTANTBUFFER_IDENTIFIER_COUNT 1
|
||||
|
||||
#endif // #if defined(FFX_CPU) || defined(FFX_GPU)
|
||||
|
||||
#endif //!defined( FFX_FSR2_RESOURCES_H )
|
||||
616
betterRenderer/thirdparty/fsr2/include/FidelityFX/gpu/cacao/ffx_cacao_ssao_generation.h
vendored
Normal file
616
betterRenderer/thirdparty/fsr2/include/FidelityFX/gpu/cacao/ffx_cacao_ssao_generation.h
vendored
Normal file
@@ -0,0 +1,616 @@
|
||||
// This file is part of the FidelityFX SDK.
|
||||
//
|
||||
// Copyright (C) 2024 Advanced Micro Devices, Inc.
|
||||
//
|
||||
// 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.
|
||||
|
||||
#include "ffx_core.h"
|
||||
#include "ffx_cacao_defines.h"
|
||||
#include "ffx_cacao_utils.h"
|
||||
|
||||
FFX_STATIC const FfxFloat32x4 g_FFX_CACAO_samplePatternMain[] =
|
||||
{
|
||||
{ 0.78488064, 0.56661671, 1.500000, -0.126083}, { 0.26022232, -0.29575172, 1.500000, -1.064030}, { 0.10459357, 0.08372527, 1.110000, -2.730563}, {-0.68286800, 0.04963045, 1.090000, -0.498827},
|
||||
{-0.13570161, -0.64190155, 1.250000, -0.532765}, {-0.26193795, -0.08205118, 0.670000, -1.783245}, {-0.61177456, 0.66664219, 0.710000, -0.044234}, { 0.43675563, 0.25119025, 0.610000, -1.167283},
|
||||
{ 0.07884444, 0.86618668, 0.640000, -0.459002}, {-0.12790935, -0.29869005, 0.600000, -1.729424}, {-0.04031125, 0.02413622, 0.600000, -4.792042}, { 0.16201244, -0.52851415, 0.790000, -1.067055},
|
||||
{-0.70991218, 0.47301072, 0.640000, -0.335236}, { 0.03277707, -0.22349690, 0.600000, -1.982384}, { 0.68921727, 0.36800742, 0.630000, -0.266718}, { 0.29251814, 0.37775412, 0.610000, -1.422520},
|
||||
{-0.12224089, 0.96582592, 0.600000, -0.426142}, { 0.11071457, -0.16131058, 0.600000, -2.165947}, { 0.46562141, -0.59747696, 0.600000, -0.189760}, {-0.51548797, 0.11804193, 0.600000, -1.246800},
|
||||
{ 0.89141309, -0.42090443, 0.600000, 0.028192}, {-0.32402530, -0.01591529, 0.600000, -1.543018}, { 0.60771245, 0.41635221, 0.600000, -0.605411}, { 0.02379565, -0.08239821, 0.600000, -3.809046},
|
||||
{ 0.48951152, -0.23657045, 0.600000, -1.189011}, {-0.17611565, -0.81696892, 0.600000, -0.513724}, {-0.33930185, -0.20732205, 0.600000, -1.698047}, {-0.91974425, 0.05403209, 0.600000, 0.062246},
|
||||
{-0.15064627, -0.14949332, 0.600000, -1.896062}, { 0.53180975, -0.35210401, 0.600000, -0.758838}, { 0.41487166, 0.81442589, 0.600000, -0.505648}, {-0.24106961, -0.32721516, 0.600000, -1.665244}
|
||||
};
|
||||
|
||||
#define FFX_CACAO_MAX_TAPS (32)
|
||||
#define FFX_CACAO_ADAPTIVE_TAP_BASE_COUNT (5)
|
||||
#define FFX_CACAO_ADAPTIVE_TAP_FLEXIBLE_COUNT (FFX_CACAO_MAX_TAPS - FFX_CACAO_ADAPTIVE_TAP_BASE_COUNT)
|
||||
|
||||
// these values can be changed (up to FFX_CACAO_MAX_TAPS) with no changes required elsewhere; values for 4th and 5th preset are ignored but array needed to avoid compilation errors
|
||||
// the actual number of texture samples is two times this value (each "tap" has two symmetrical depth texture samples)
|
||||
FFX_STATIC const FfxUInt32 g_FFX_CACAO_numTaps[5] = {3, 5, 12, 0, 0};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Optional parts that can be enabled for a required quality preset level and above (0 == Low, 1 == Medium, 2 == High, 3 == Highest/Adaptive, 4 == reference/unused )
|
||||
// Each has its own cost. To disable just set to 5 or above.
|
||||
//
|
||||
// (experimental) tilts the disk (although only half of the samples!) towards surface normal; this helps with effect uniformity between objects but reduces effect distance and has other side-effects
|
||||
#define FFX_CACAO_TILT_SAMPLES_ENABLE_AT_QUALITY_PRESET (99) // to disable simply set to 99 or similar
|
||||
#define FFX_CACAO_TILT_SAMPLES_AMOUNT (0.4)
|
||||
//
|
||||
#define FFX_CACAO_HALOING_REDUCTION_ENABLE_AT_QUALITY_PRESET (1) // to disable simply set to 99 or similar
|
||||
#define FFX_CACAO_HALOING_REDUCTION_AMOUNT (0.6) // values from 0.0 - 1.0, 1.0 means max weighting (will cause artifacts, 0.8 is more reasonable)
|
||||
//
|
||||
#define FFX_CACAO_NORMAL_BASED_EDGES_ENABLE_AT_QUALITY_PRESET (2) //2 // to disable simply set to 99 or similar
|
||||
#define FFX_CACAO_NORMAL_BASED_EDGES_DOT_THRESHOLD (0.5) // use 0-0.1 for super-sharp normal-based edges
|
||||
//
|
||||
#define FFX_CACAO_DETAIL_AO_ENABLE_AT_QUALITY_PRESET (1) //1 // whether to use DetailAOStrength; to disable simply set to 99 or similar
|
||||
//
|
||||
#define FFX_CACAO_DEPTH_MIPS_ENABLE_AT_QUALITY_PRESET (2) // !!warning!! the MIP generation on the C++ side will be enabled on quality preset 2 regardless of this value, so if changing here, change the C++ side too
|
||||
#define FFX_CACAO_DEPTH_MIPS_GLOBAL_OFFSET (-4.3) // best noise/quality/performance tradeoff, found empirically
|
||||
//
|
||||
// !!warning!! the edge handling is hard-coded to 'disabled' on quality level 0, and enabled above, on the C++ side; while toggling it here will work for
|
||||
// testing purposes, it will not yield performance gains (or correct results)
|
||||
#define FFX_CACAO_DEPTH_BASED_EDGES_ENABLE_AT_QUALITY_PRESET (1)
|
||||
//
|
||||
#define FFX_CACAO_REDUCE_RADIUS_NEAR_SCREEN_BORDER_ENABLE_AT_QUALITY_PRESET (99) // 99 means disabled; only helpful if artifacts at the edges caused by lack of out of screen depth data are not acceptable with the depth sampler in either clamp or mirror modes
|
||||
|
||||
// =======================================================================================================
|
||||
// SSAO Generation
|
||||
|
||||
// calculate effect radius and fit our screen sampling pattern inside it
|
||||
void FFX_CACAO_CalculateRadiusParameters(const FfxFloat32 pixCenterLength, const FfxFloat32x2 pixelDirRBViewspaceSizeAtCenterZ, out FfxFloat32 pixLookupRadiusMod, out FfxFloat32 effectRadius, out FfxFloat32 falloffCalcMulSq)
|
||||
{
|
||||
effectRadius = EffectRadius();
|
||||
|
||||
// leaving this out for performance reasons: use something similar if radius needs to scale based on distance
|
||||
//effectRadius *= pow( pixCenterLength, RadiusDistanceScalingFunctionPow());
|
||||
|
||||
// when too close, on-screen sampling disk will grow beyond screen size; limit this to avoid closeup temporal artifacts
|
||||
const FfxFloat32 tooCloseLimitMod = ffxSaturate(pixCenterLength * EffectSamplingRadiusNearLimitRec()) * 0.8 + 0.2;
|
||||
|
||||
effectRadius *= tooCloseLimitMod;
|
||||
|
||||
// 0.85 is to reduce the radius to allow for more samples on a slope to still stay within influence
|
||||
pixLookupRadiusMod = (0.85 * effectRadius) / pixelDirRBViewspaceSizeAtCenterZ.x;
|
||||
|
||||
// used to calculate falloff (both for AO samples and per-sample weights)
|
||||
falloffCalcMulSq = -1.0f / (effectRadius*effectRadius);
|
||||
}
|
||||
|
||||
// all vectors in viewspace
|
||||
FfxFloat32 FFX_CACAO_CalculatePixelObscurance(FfxFloat32x3 pixelNormal, FfxFloat32x3 hitDelta, FfxFloat32 falloffCalcMulSq)
|
||||
{
|
||||
FfxFloat32 lengthSq = dot(hitDelta, hitDelta);
|
||||
FfxFloat32 NdotD = dot(pixelNormal, hitDelta) / sqrt(lengthSq);
|
||||
|
||||
FfxFloat32 falloffMult = max(0.0, lengthSq * falloffCalcMulSq + 1.0);
|
||||
|
||||
return max(0, NdotD - EffectHorizonAngleThreshold()) * falloffMult;
|
||||
}
|
||||
|
||||
void FFX_CACAO_SSAOTapInner(const FfxInt32 qualityLevel,
|
||||
inout FfxFloat32 obscuranceSum,
|
||||
inout FfxFloat32 weightSum,
|
||||
const FfxFloat32x2 samplingUV,
|
||||
const FfxFloat32 mipLevel,
|
||||
const FfxFloat32x3 pixCenterPos,
|
||||
const FfxFloat32x3 negViewspaceDir,
|
||||
FfxFloat32x3 pixelNormal,
|
||||
const FfxFloat32 falloffCalcMulSq,
|
||||
const FfxFloat32 weightMod,
|
||||
const FfxInt32 dbgTapIndex,
|
||||
FfxUInt32 layerId)
|
||||
{
|
||||
// get depth at sample
|
||||
FfxFloat32 viewspaceSampleZ = FFX_CACAO_SSAOGeneration_SampleViewspaceDepthMip(samplingUV, mipLevel, layerId);
|
||||
|
||||
// convert to viewspace
|
||||
FfxFloat32x3 hitPos = FFX_CACAO_DepthBufferUVToViewSpace(samplingUV.xy, viewspaceSampleZ).xyz;
|
||||
FfxFloat32x3 hitDelta = hitPos - pixCenterPos;
|
||||
|
||||
FfxFloat32 obscurance = FFX_CACAO_CalculatePixelObscurance(pixelNormal, hitDelta, falloffCalcMulSq);
|
||||
FfxFloat32 weight = 1.0;
|
||||
|
||||
if (qualityLevel >= FFX_CACAO_HALOING_REDUCTION_ENABLE_AT_QUALITY_PRESET)
|
||||
{
|
||||
//FfxFloat32 reduct = max( 0, dot( hitDelta, negViewspaceDir ) );
|
||||
FfxFloat32 reduct = max(0, -hitDelta.z); // cheaper, less correct version
|
||||
reduct = ffxSaturate(reduct * NegRecEffectRadius() + 2.0); // ffxSaturate( 2.0 - reduct / EffectRadius() );
|
||||
weight = FFX_CACAO_HALOING_REDUCTION_AMOUNT * reduct + (1.0 - FFX_CACAO_HALOING_REDUCTION_AMOUNT);
|
||||
}
|
||||
weight *= weightMod;
|
||||
obscuranceSum += obscurance * weight;
|
||||
weightSum += weight;
|
||||
}
|
||||
|
||||
void FFX_CACAO_SSAOTap(const FfxInt32 qualityLevel,
|
||||
inout FfxFloat32 obscuranceSum,
|
||||
inout FfxFloat32 weightSum,
|
||||
const FfxInt32 tapIndex,
|
||||
const FfxFloat32x2x2 rotScale,
|
||||
const FfxFloat32x3 pixCenterPos,
|
||||
const FfxFloat32x3 negViewspaceDir,
|
||||
FfxFloat32x3 pixelNormal,
|
||||
const FfxFloat32x2 normalizedScreenPos,
|
||||
const FfxFloat32x2 depthBufferUV,
|
||||
const FfxFloat32 mipOffset,
|
||||
const FfxFloat32 falloffCalcMulSq,
|
||||
FfxFloat32 weightMod,
|
||||
FfxFloat32x2 normXY,
|
||||
FfxFloat32 normXYLength,
|
||||
const FfxUInt32 layerId)
|
||||
{
|
||||
FfxFloat32x2 sampleOffset;
|
||||
FfxFloat32 samplePow2Len;
|
||||
|
||||
// patterns
|
||||
{
|
||||
FfxFloat32x4 newSample = g_FFX_CACAO_samplePatternMain[tapIndex];
|
||||
sampleOffset = FFX_TRANSFORM_VECTOR(rotScale, newSample.xy);
|
||||
samplePow2Len = newSample.w; // precalculated, same as: samplePow2Len = log2( length( newSample.xy ) );
|
||||
weightMod *= newSample.z;
|
||||
}
|
||||
|
||||
// snap to pixel center (more correct obscurance math, avoids artifacts)
|
||||
sampleOffset = round(sampleOffset);
|
||||
|
||||
// calculate MIP based on the sample distance from the centre, similar to as described
|
||||
// in http://graphics.cs.williams.edu/papers/SAOHPG12/.
|
||||
FfxFloat32 mipLevel = (qualityLevel < FFX_CACAO_DEPTH_MIPS_ENABLE_AT_QUALITY_PRESET) ? (0) : (samplePow2Len + mipOffset);
|
||||
|
||||
FfxFloat32x2 samplingUV = sampleOffset * DeinterleavedDepthBufferInverseDimensions() + depthBufferUV;
|
||||
|
||||
FFX_CACAO_SSAOTapInner(qualityLevel, obscuranceSum, weightSum, samplingUV, mipLevel, pixCenterPos, negViewspaceDir, pixelNormal, falloffCalcMulSq, weightMod, tapIndex * 2, layerId);
|
||||
|
||||
// for the second tap, just use the mirrored offset
|
||||
FfxFloat32x2 sampleOffsetMirroredUV = -sampleOffset;
|
||||
|
||||
// tilt the second set of samples so that the disk is effectively rotated by the normal
|
||||
// effective at removing one set of artifacts, but too expensive for lower quality settings
|
||||
if (qualityLevel >= FFX_CACAO_TILT_SAMPLES_ENABLE_AT_QUALITY_PRESET)
|
||||
{
|
||||
FfxFloat32 dotNorm = dot(sampleOffsetMirroredUV, normXY);
|
||||
sampleOffsetMirroredUV -= dotNorm * normXYLength * normXY;
|
||||
sampleOffsetMirroredUV = round(sampleOffsetMirroredUV);
|
||||
}
|
||||
|
||||
// snap to pixel center (more correct obscurance math, avoids artifacts)
|
||||
FfxFloat32x2 samplingMirroredUV = sampleOffsetMirroredUV * DeinterleavedDepthBufferInverseDimensions() + depthBufferUV;
|
||||
|
||||
FFX_CACAO_SSAOTapInner(qualityLevel, obscuranceSum, weightSum, samplingMirroredUV, mipLevel, pixCenterPos, negViewspaceDir, pixelNormal, falloffCalcMulSq, weightMod, tapIndex * 2 + 1, layerId);
|
||||
}
|
||||
|
||||
struct FFX_CACAO_SSAOHits
|
||||
{
|
||||
FfxFloat32x3 hits[2];
|
||||
FfxFloat32 weightMod;
|
||||
};
|
||||
|
||||
struct FFX_CACAO_SSAOSampleData
|
||||
{
|
||||
FfxFloat32x2 uvOffset;
|
||||
FfxFloat32 mipLevel;
|
||||
FfxFloat32 weightMod;
|
||||
};
|
||||
|
||||
FFX_CACAO_SSAOSampleData FFX_CACAO_SSAOGetSampleData(const FfxInt32 qualityLevel,
|
||||
const FfxFloat32x2x2 rotScale,
|
||||
const FfxFloat32x4 newSample,
|
||||
const FfxFloat32 mipOffset)
|
||||
{
|
||||
FfxFloat32x2 sampleOffset = FFX_TRANSFORM_VECTOR(rotScale, newSample.xy);
|
||||
sampleOffset = round(sampleOffset) * DeinterleavedDepthBufferInverseDimensions();
|
||||
|
||||
FfxFloat32 samplePow2Len = newSample.w;
|
||||
FfxFloat32 mipLevel = (qualityLevel < FFX_CACAO_DEPTH_MIPS_ENABLE_AT_QUALITY_PRESET) ? (0) : (samplePow2Len + mipOffset);
|
||||
|
||||
FFX_CACAO_SSAOSampleData result;
|
||||
|
||||
result.uvOffset = sampleOffset;
|
||||
result.mipLevel = mipLevel;
|
||||
result.weightMod = newSample.z;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
FFX_CACAO_SSAOHits FFX_CACAO_SSAOGetHits2(FFX_CACAO_SSAOSampleData data, const FfxFloat32x2 depthBufferUV, const FfxUInt32 layerId)
|
||||
{
|
||||
FFX_CACAO_SSAOHits result;
|
||||
result.weightMod = data.weightMod;
|
||||
FfxFloat32x2 sampleUV = depthBufferUV + data.uvOffset;
|
||||
result.hits[0] = FfxFloat32x3(sampleUV, FFX_CACAO_SSAOGeneration_SampleViewspaceDepthMip(sampleUV, data.mipLevel, layerId));
|
||||
sampleUV = depthBufferUV - data.uvOffset;
|
||||
result.hits[1] = FfxFloat32x3(sampleUV, FFX_CACAO_SSAOGeneration_SampleViewspaceDepthMip(sampleUV, data.mipLevel, layerId));
|
||||
return result;
|
||||
}
|
||||
|
||||
void FFX_CACAO_SSAOAddHits(const FfxInt32 qualityLevel, const FfxFloat32x3 pixCenterPos, const FfxFloat32x3 pixelNormal, const FfxFloat32 falloffCalcMulSq, inout FfxFloat32 weightSum, inout FfxFloat32 obscuranceSum, FFX_CACAO_SSAOHits hits)
|
||||
{
|
||||
FfxFloat32 weight = hits.weightMod;
|
||||
FFX_UNROLL
|
||||
for (FfxInt32 hitIndex = 0; hitIndex < 2; ++hitIndex)
|
||||
{
|
||||
FfxFloat32x3 hit = hits.hits[hitIndex];
|
||||
FfxFloat32x3 hitPos = FFX_CACAO_DepthBufferUVToViewSpace(hit.xy, hit.z);
|
||||
FfxFloat32x3 hitDelta = hitPos - pixCenterPos;
|
||||
|
||||
FfxFloat32 obscurance = FFX_CACAO_CalculatePixelObscurance(pixelNormal, hitDelta, falloffCalcMulSq);
|
||||
|
||||
if (qualityLevel >= FFX_CACAO_HALOING_REDUCTION_ENABLE_AT_QUALITY_PRESET)
|
||||
{
|
||||
//FfxFloat32 reduct = max( 0, dot( hitDelta, negViewspaceDir ) );
|
||||
FfxFloat32 reduct = max(0, -hitDelta.z); // cheaper, less correct version
|
||||
reduct = ffxSaturate(reduct * NegRecEffectRadius() + 2.0); // ffxSaturate( 2.0 - reduct / EffectRadius() );
|
||||
weight = FFX_CACAO_HALOING_REDUCTION_AMOUNT * reduct + (1.0 - FFX_CACAO_HALOING_REDUCTION_AMOUNT);
|
||||
}
|
||||
obscuranceSum += obscurance * weight;
|
||||
weightSum += weight;
|
||||
}
|
||||
}
|
||||
|
||||
void FFX_CACAO_GenerateSSAOShadowsInternal(out FfxFloat32 outShadowTerm,
|
||||
out FfxFloat32x4 outEdges,
|
||||
out FfxFloat32 outWeight,
|
||||
const FfxFloat32x2 SVPos /*, const FfxFloat32x2 normalizedScreenPos*/,
|
||||
FFX_PARAMETER_UNIFORM FfxInt32 qualityLevel,
|
||||
bool adaptiveBase,
|
||||
const FfxUInt32 layerId)
|
||||
{
|
||||
FfxFloat32x2 SVPosRounded = trunc(SVPos);
|
||||
FfxUInt32x2 SVPosui = FfxUInt32x2(SVPosRounded); //same as FfxUInt32x2( SVPos )
|
||||
|
||||
const FfxInt32 numberOfTaps = (adaptiveBase) ? (FFX_CACAO_ADAPTIVE_TAP_BASE_COUNT) : FfxInt32(g_FFX_CACAO_numTaps[qualityLevel]);
|
||||
FfxFloat32 pixZ, pixLZ, pixTZ, pixRZ, pixBZ;
|
||||
|
||||
FfxFloat32x2 depthBufferUVCorner = (SVPos + 1.0f) * DeinterleavedDepthBufferInverseDimensions() + DeinterleavedDepthBufferNormalisedOffset(); //Need corner to avoid gather fixed point error.
|
||||
FfxFloat32x2 depthBufferUV = (SVPos + 0.5f) * DeinterleavedDepthBufferInverseDimensions() + DeinterleavedDepthBufferNormalisedOffset(); //Need center coord
|
||||
FfxFloat32x4 valuesUL = FFX_CACAO_SSAOGeneration_GatherViewspaceDepthOffset(depthBufferUVCorner, FfxInt32x2(-1, -1), layerId);
|
||||
FfxFloat32x4 valuesBR = FFX_CACAO_SSAOGeneration_GatherViewspaceDepthOffset(depthBufferUVCorner, FfxInt32x2(0, 0), layerId);
|
||||
|
||||
|
||||
// get this pixel's viewspace depth
|
||||
pixZ = valuesUL.y;
|
||||
|
||||
// get left right top bottom neighbouring pixels for edge detection (gets compiled out on qualityLevel == 0)
|
||||
pixLZ = valuesUL.x;
|
||||
pixTZ = valuesUL.z;
|
||||
pixRZ = valuesBR.z;
|
||||
pixBZ = valuesBR.x;
|
||||
|
||||
// FfxFloat32x2 normalizedScreenPos = SVPosRounded * Viewport2xPixelSize() + Viewport2xPixelSize_x_025();
|
||||
FfxFloat32x2 normalizedScreenPos = (SVPosRounded + 0.5f) * SSAOBufferInverseDimensions();
|
||||
FfxFloat32x3 pixCenterPos = FFX_CACAO_NDCToViewSpace(normalizedScreenPos, pixZ); // g
|
||||
|
||||
// Load this pixel's viewspace normal
|
||||
// FfxUInt32x2 fullResCoord = 2 * (SVPosui * 2 + PerPassFullResCoordOffset().xy);
|
||||
FfxFloat32x3 pixelNormal = FFX_CACAO_SSAOGeneration_GetNormalPass(SVPosui, layerId);
|
||||
|
||||
// optimized approximation of: FfxFloat32x2 pixelDirRBViewspaceSizeAtCenterZ = FFX_CACAO_NDCToViewSpace( normalizedScreenPos.xy + _ViewportPixelSize().xy, pixCenterPos.z ).xy - pixCenterPos.xy;
|
||||
// const FfxFloat32x2 pixelDirRBViewspaceSizeAtCenterZ = pixCenterPos.z * NDCToViewMul() * Viewport2xPixelSize();
|
||||
const FfxFloat32x2 pixelDirRBViewspaceSizeAtCenterZ = pixCenterPos.z * NDCToViewMul() * SSAOBufferInverseDimensions();
|
||||
|
||||
FfxFloat32 pixLookupRadiusMod;
|
||||
FfxFloat32 falloffCalcMulSq;
|
||||
|
||||
// calculate effect radius and fit our screen sampling pattern inside it
|
||||
FfxFloat32 effectViewspaceRadius;
|
||||
FFX_CACAO_CalculateRadiusParameters(length(pixCenterPos), pixelDirRBViewspaceSizeAtCenterZ, pixLookupRadiusMod, effectViewspaceRadius, falloffCalcMulSq);
|
||||
|
||||
// calculate samples rotation/scaling
|
||||
FfxFloat32x2x2 rotScale;
|
||||
{
|
||||
// reduce effect radius near the screen edges slightly; ideally, one would render a larger depth buffer (5% on each side) instead
|
||||
if (!adaptiveBase && (qualityLevel >= FFX_CACAO_REDUCE_RADIUS_NEAR_SCREEN_BORDER_ENABLE_AT_QUALITY_PRESET))
|
||||
{
|
||||
FfxFloat32 nearScreenBorder = min(min(depthBufferUV.x, 1.0 - depthBufferUV.x), min(depthBufferUV.y, 1.0 - depthBufferUV.y));
|
||||
nearScreenBorder = ffxSaturate(10.0 * nearScreenBorder + 0.6);
|
||||
pixLookupRadiusMod *= nearScreenBorder;
|
||||
}
|
||||
|
||||
// load & update pseudo-random rotation matrix
|
||||
FfxUInt32 pseudoRandomIndex = FfxUInt32(SVPosRounded.y * 2 + SVPosRounded.x) % 5;
|
||||
FfxFloat32x4 rs = PatternRotScaleMatrices(layerId, pseudoRandomIndex);
|
||||
rotScale = FfxFloat32x2x2(rs.x * pixLookupRadiusMod, rs.y * pixLookupRadiusMod, rs.z * pixLookupRadiusMod, rs.w * pixLookupRadiusMod);
|
||||
}
|
||||
|
||||
// the main obscurance & sample weight storage
|
||||
FfxFloat32 obscuranceSum = 0.0;
|
||||
FfxFloat32 weightSum = 0.0;
|
||||
|
||||
// edge mask for between this and left/right/top/bottom neighbour pixels - not used in quality level 0 so initialize to "no edge" (1 is no edge, 0 is edge)
|
||||
FfxFloat32x4 edgesLRTB = FfxFloat32x4(1.0, 1.0, 1.0, 1.0);
|
||||
|
||||
// Move center pixel slightly towards camera to avoid imprecision artifacts due to using of 16bit depth buffer; a lot smaller offsets needed when using 32bit floats
|
||||
pixCenterPos *= DepthPrecisionOffsetMod();
|
||||
|
||||
if (!adaptiveBase && (qualityLevel >= FFX_CACAO_DEPTH_BASED_EDGES_ENABLE_AT_QUALITY_PRESET))
|
||||
{
|
||||
edgesLRTB = FFX_CACAO_CalculateEdges(pixZ, pixLZ, pixRZ, pixTZ, pixBZ);
|
||||
}
|
||||
|
||||
// adds a more high definition sharp effect, which gets blurred out (reuses left/right/top/bottom samples that we used for edge detection)
|
||||
if (!adaptiveBase && (qualityLevel >= FFX_CACAO_DETAIL_AO_ENABLE_AT_QUALITY_PRESET))
|
||||
{
|
||||
// disable in case of quality level 4 (reference)
|
||||
if (qualityLevel != 4)
|
||||
{
|
||||
//approximate neighbouring pixels positions (actually just deltas or "positions - pixCenterPos" )
|
||||
FfxFloat32x3 viewspaceDirZNormalized = FfxFloat32x3(pixCenterPos.xy / pixCenterPos.zz, 1.0);
|
||||
|
||||
// very close approximation of: FfxFloat32x3 pixLPos = FFX_CACAO_NDCToViewSpace( normalizedScreenPos + FfxFloat32x2( -HalfViewportPixelSize().x, 0.0 ), pixLZ ).xyz - pixCenterPos.xyz;
|
||||
FfxFloat32x3 pixLDelta = FfxFloat32x3(-pixelDirRBViewspaceSizeAtCenterZ.x, 0.0, 0.0) + viewspaceDirZNormalized * (pixLZ - pixCenterPos.z);
|
||||
// very close approximation of: FfxFloat32x3 pixRPos = FFX_CACAO_NDCToViewSpace( normalizedScreenPos + FfxFloat32x2( +HalfViewportPixelSize().x, 0.0 ), pixRZ ).xyz - pixCenterPos.xyz;
|
||||
FfxFloat32x3 pixRDelta = FfxFloat32x3(+pixelDirRBViewspaceSizeAtCenterZ.x, 0.0, 0.0) + viewspaceDirZNormalized * (pixRZ - pixCenterPos.z);
|
||||
// very close approximation of: FfxFloat32x3 pixTPos = FFX_CACAO_NDCToViewSpace( normalizedScreenPos + FfxFloat32x2( 0.0, -HalfViewportPixelSize().y ), pixTZ ).xyz - pixCenterPos.xyz;
|
||||
FfxFloat32x3 pixTDelta = FfxFloat32x3(0.0, -pixelDirRBViewspaceSizeAtCenterZ.y, 0.0) + viewspaceDirZNormalized * (pixTZ - pixCenterPos.z);
|
||||
// very close approximation of: FfxFloat32x3 pixBPos = FFX_CACAO_NDCToViewSpace( normalizedScreenPos + FfxFloat32x2( 0.0, +HalfViewportPixelSize().y ), pixBZ ).xyz - pixCenterPos.xyz;
|
||||
FfxFloat32x3 pixBDelta = FfxFloat32x3(0.0, +pixelDirRBViewspaceSizeAtCenterZ.y, 0.0) + viewspaceDirZNormalized * (pixBZ - pixCenterPos.z);
|
||||
|
||||
const FfxFloat32 rangeReductionConst = 4.0f; // this is to avoid various artifacts
|
||||
const FfxFloat32 modifiedFalloffCalcMulSq = rangeReductionConst * falloffCalcMulSq;
|
||||
|
||||
FfxFloat32x4 additionalObscurance;
|
||||
additionalObscurance.x = FFX_CACAO_CalculatePixelObscurance(pixelNormal, pixLDelta, modifiedFalloffCalcMulSq);
|
||||
additionalObscurance.y = FFX_CACAO_CalculatePixelObscurance(pixelNormal, pixRDelta, modifiedFalloffCalcMulSq);
|
||||
additionalObscurance.z = FFX_CACAO_CalculatePixelObscurance(pixelNormal, pixTDelta, modifiedFalloffCalcMulSq);
|
||||
additionalObscurance.w = FFX_CACAO_CalculatePixelObscurance(pixelNormal, pixBDelta, modifiedFalloffCalcMulSq);
|
||||
|
||||
obscuranceSum += DetailAOStrength() * dot(additionalObscurance, edgesLRTB);
|
||||
}
|
||||
}
|
||||
|
||||
// Sharp normals also create edges - but this adds to the cost as well
|
||||
if (!adaptiveBase && (qualityLevel >= FFX_CACAO_NORMAL_BASED_EDGES_ENABLE_AT_QUALITY_PRESET))
|
||||
{
|
||||
FfxFloat32x3 neighbourNormalL = FFX_CACAO_SSAOGeneration_GetNormalPass(SVPosui + FfxInt32x2(-1, +0), layerId);
|
||||
FfxFloat32x3 neighbourNormalR = FFX_CACAO_SSAOGeneration_GetNormalPass(SVPosui + FfxInt32x2(+1, +0), layerId);
|
||||
FfxFloat32x3 neighbourNormalT = FFX_CACAO_SSAOGeneration_GetNormalPass(SVPosui + FfxInt32x2(+0, -1), layerId);
|
||||
FfxFloat32x3 neighbourNormalB = FFX_CACAO_SSAOGeneration_GetNormalPass(SVPosui + FfxInt32x2(+0, +1), layerId);
|
||||
|
||||
const FfxFloat32 dotThreshold = FFX_CACAO_NORMAL_BASED_EDGES_DOT_THRESHOLD;
|
||||
|
||||
FfxFloat32x4 normalEdgesLRTB;
|
||||
normalEdgesLRTB.x = ffxSaturate((dot(pixelNormal, neighbourNormalL) + dotThreshold));
|
||||
normalEdgesLRTB.y = ffxSaturate((dot(pixelNormal, neighbourNormalR) + dotThreshold));
|
||||
normalEdgesLRTB.z = ffxSaturate((dot(pixelNormal, neighbourNormalT) + dotThreshold));
|
||||
normalEdgesLRTB.w = ffxSaturate((dot(pixelNormal, neighbourNormalB) + dotThreshold));
|
||||
|
||||
//#define FFX_CACAO_SMOOTHEN_NORMALS // fixes some aliasing artifacts but kills a lot of high detail and adds to the cost - not worth it probably but feel free to play with it
|
||||
#ifdef FFX_CACAO_SMOOTHEN_NORMALS
|
||||
//neighbourNormalL = LoadNormal( fullResCoord, FfxInt32x2( -1, 0 ) );
|
||||
//neighbourNormalR = LoadNormal( fullResCoord, FfxInt32x2( 1, 0 ) );
|
||||
//neighbourNormalT = LoadNormal( fullResCoord, FfxInt32x2( 0, -1 ) );
|
||||
//neighbourNormalB = LoadNormal( fullResCoord, FfxInt32x2( 0, 1 ) );
|
||||
pixelNormal += neighbourNormalL * edgesLRTB.x + neighbourNormalR * edgesLRTB.y + neighbourNormalT * edgesLRTB.z + neighbourNormalB * edgesLRTB.w;
|
||||
pixelNormal = normalize(pixelNormal);
|
||||
#endif
|
||||
|
||||
edgesLRTB *= normalEdgesLRTB;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const FfxFloat32 globalMipOffset = FFX_CACAO_DEPTH_MIPS_GLOBAL_OFFSET;
|
||||
FfxFloat32 mipOffset = (qualityLevel < FFX_CACAO_DEPTH_MIPS_ENABLE_AT_QUALITY_PRESET) ? (0) : (log2(pixLookupRadiusMod) + globalMipOffset);
|
||||
|
||||
// Used to tilt the second set of samples so that the disk is effectively rotated by the normal
|
||||
// effective at removing one set of artifacts, but too expensive for lower quality settings
|
||||
FfxFloat32x2 normXY = FfxFloat32x2(pixelNormal.x, pixelNormal.y);
|
||||
FfxFloat32 normXYLength = length(normXY);
|
||||
normXY /= FfxFloat32x2(normXYLength, -normXYLength);
|
||||
normXYLength *= FFX_CACAO_TILT_SAMPLES_AMOUNT;
|
||||
|
||||
const FfxFloat32x3 negViewspaceDir = -normalize(pixCenterPos);
|
||||
|
||||
// standard, non-adaptive approach
|
||||
if ((qualityLevel != 3) || adaptiveBase)
|
||||
{
|
||||
FFX_UNROLL
|
||||
for (FfxInt32 i = 0; i < numberOfTaps; i++)
|
||||
{
|
||||
FFX_CACAO_SSAOTap(qualityLevel, obscuranceSum, weightSum, i, rotScale, pixCenterPos, negViewspaceDir, pixelNormal, normalizedScreenPos, depthBufferUV, mipOffset, falloffCalcMulSq, 1.0, normXY, normXYLength, layerId);
|
||||
}
|
||||
}
|
||||
else // if( qualityLevel == 3 ) adaptive approach
|
||||
{
|
||||
// add new ones if needed
|
||||
FfxFloat32x2 fullResUV = normalizedScreenPos + PerPassFullResUVOffset(layerId).xy;
|
||||
FfxFloat32 importance = FFX_CACAO_SSAOGeneration_SampleImportance(fullResUV);
|
||||
|
||||
// this is to normalize FFX_CACAO_DETAIL_AO_AMOUNT across all pixel regardless of importance
|
||||
obscuranceSum *= (FFX_CACAO_ADAPTIVE_TAP_BASE_COUNT / FfxFloat32(FFX_CACAO_MAX_TAPS)) + (importance * FFX_CACAO_ADAPTIVE_TAP_FLEXIBLE_COUNT / FfxFloat32(FFX_CACAO_MAX_TAPS));
|
||||
|
||||
// load existing base values
|
||||
FfxFloat32x2 baseValues = FFX_CACAO_SSAOGeneration_LoadBasePassSSAOPass(SVPosui, layerId); //PassIndex());
|
||||
weightSum += baseValues.y * FfxFloat32(FFX_CACAO_ADAPTIVE_TAP_BASE_COUNT * 4.0);
|
||||
obscuranceSum += (baseValues.x) * weightSum;
|
||||
|
||||
// increase importance around edges
|
||||
FfxFloat32 edgeCount = dot(1.0 - edgesLRTB, FfxFloat32x4(1.0, 1.0, 1.0, 1.0));
|
||||
|
||||
FfxFloat32 avgTotalImportance = FfxFloat32(FFX_CACAO_SSAOGeneration_GetLoadCounter()) * LoadCounterAvgDiv();
|
||||
|
||||
FfxFloat32 importanceLimiter = ffxSaturate(AdaptiveSampleCountLimit() / avgTotalImportance);
|
||||
importance *= importanceLimiter;
|
||||
|
||||
FfxFloat32 additionalSampleCountFlt = FFX_CACAO_ADAPTIVE_TAP_FLEXIBLE_COUNT * importance;
|
||||
|
||||
additionalSampleCountFlt += 1.5;
|
||||
FfxUInt32 additionalSamples = FfxUInt32(additionalSampleCountFlt);
|
||||
FfxUInt32 additionalSamplesTo = min(FFX_CACAO_MAX_TAPS - 1, additionalSamples + FFX_CACAO_ADAPTIVE_TAP_BASE_COUNT);
|
||||
|
||||
// sample loop
|
||||
{
|
||||
FfxFloat32x4 newSample = g_FFX_CACAO_samplePatternMain[FFX_CACAO_ADAPTIVE_TAP_BASE_COUNT];
|
||||
FFX_CACAO_SSAOSampleData data = FFX_CACAO_SSAOGetSampleData(qualityLevel, rotScale, newSample, mipOffset);
|
||||
FFX_CACAO_SSAOHits hits = FFX_CACAO_SSAOGetHits2(data, depthBufferUV, layerId);
|
||||
newSample = g_FFX_CACAO_samplePatternMain[FFX_CACAO_ADAPTIVE_TAP_BASE_COUNT + 1];
|
||||
|
||||
for (FfxUInt32 i = FFX_CACAO_ADAPTIVE_TAP_BASE_COUNT; i < additionalSamplesTo - 1; i++)
|
||||
{
|
||||
data = FFX_CACAO_SSAOGetSampleData(qualityLevel, rotScale, newSample, mipOffset);
|
||||
newSample = g_FFX_CACAO_samplePatternMain[i + 2];
|
||||
FFX_CACAO_SSAOHits nextHits = FFX_CACAO_SSAOGetHits2(data, depthBufferUV, layerId);
|
||||
|
||||
FFX_CACAO_SSAOAddHits(qualityLevel, pixCenterPos, pixelNormal, falloffCalcMulSq, weightSum, obscuranceSum, hits);
|
||||
hits = nextHits;
|
||||
}
|
||||
|
||||
// last loop iteration
|
||||
{
|
||||
FFX_CACAO_SSAOAddHits(qualityLevel, pixCenterPos, pixelNormal, falloffCalcMulSq, weightSum, obscuranceSum, hits);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// early out for adaptive base - just output weight (used for the next pass)
|
||||
if (adaptiveBase)
|
||||
{
|
||||
FfxFloat32 obscurance = obscuranceSum / weightSum;
|
||||
|
||||
outShadowTerm = obscurance;
|
||||
outEdges = FfxFloat32x4(0, 0, 0, 0);
|
||||
outWeight = weightSum;
|
||||
return;
|
||||
}
|
||||
|
||||
// calculate weighted average
|
||||
FfxFloat32 obscurance = obscuranceSum / weightSum;
|
||||
|
||||
// calculate fadeout (1 close, gradient, 0 far)
|
||||
FfxFloat32 fadeOut = ffxSaturate(pixCenterPos.z * EffectFadeOutMul() + EffectFadeOutAdd());
|
||||
|
||||
// Reduce the SSAO shadowing if we're on the edge to remove artifacts on edges (we don't care for the lower quality one)
|
||||
if (!adaptiveBase && (qualityLevel >= FFX_CACAO_DEPTH_BASED_EDGES_ENABLE_AT_QUALITY_PRESET))
|
||||
{
|
||||
// FfxFloat32 edgeCount = dot( 1.0-edgesLRTB, FfxFloat32x4( 1.0, 1.0, 1.0, 1.0 ) );
|
||||
|
||||
// when there's more than 2 opposite edges, start fading out the occlusion to reduce aliasing artifacts
|
||||
FfxFloat32 edgeFadeoutFactor = ffxSaturate((1.0 - edgesLRTB.x - edgesLRTB.y) * 0.35) + ffxSaturate((1.0 - edgesLRTB.z - edgesLRTB.w) * 0.35);
|
||||
|
||||
// (experimental) if you want to reduce the effect next to any edge
|
||||
// edgeFadeoutFactor += 0.1 * ffxSaturate( dot( 1 - edgesLRTB, FfxFloat32x4( 1, 1, 1, 1 ) ) );
|
||||
|
||||
fadeOut *= ffxSaturate(1.0 - edgeFadeoutFactor);
|
||||
}
|
||||
|
||||
// same as a bove, but a lot more conservative version
|
||||
// fadeOut *= ffxSaturate( dot( edgesLRTB, FfxFloat32x4( 0.9, 0.9, 0.9, 0.9 ) ) - 2.6 );
|
||||
|
||||
// strength
|
||||
obscurance = EffectShadowStrength() * obscurance;
|
||||
|
||||
// clamp
|
||||
obscurance = min(obscurance, EffectShadowClamp());
|
||||
|
||||
// fadeout
|
||||
obscurance *= fadeOut;
|
||||
|
||||
// conceptually switch to occlusion with the meaning being visibility (grows with visibility, occlusion == 1 implies full visibility),
|
||||
// to be in line with what is more commonly used.
|
||||
FfxFloat32 occlusion = 1.0 - obscurance;
|
||||
|
||||
// modify the gradient
|
||||
// note: this cannot be moved to a later pass because of loss of precision after storing in the render target
|
||||
occlusion = pow(ffxSaturate(occlusion), EffectShadowPow());
|
||||
|
||||
// outputs!
|
||||
outShadowTerm = occlusion; // Our final 'occlusion' term (0 means fully occluded, 1 means fully lit)
|
||||
outEdges = edgesLRTB; // These are used to prevent blurring across edges, 1 means no edge, 0 means edge, 0.5 means half way there, etc.
|
||||
outWeight = weightSum;
|
||||
}
|
||||
|
||||
void FFX_CACAO_GenerateQ0(FfxUInt32x3 tid)
|
||||
{
|
||||
FfxUInt32 tidCorrectedZ = tid.z % 5;
|
||||
FfxUInt32 layerId = tid.z / 5;
|
||||
layerId = (layerId == 1 && BlurNumPasses() == 2) ? 3 : layerId; // Choose correct layer in 2 layer case
|
||||
FfxUInt32 xOffset = (tid.y * 3 + tidCorrectedZ) % 5;
|
||||
FfxUInt32x2 coord = FfxUInt32x2(5 * tid.x + xOffset, tid.y);
|
||||
FfxFloat32x2 inPos = FfxFloat32x2(coord);
|
||||
FfxFloat32 outShadowTerm;
|
||||
FfxFloat32 outWeight;
|
||||
FfxFloat32x4 outEdges;
|
||||
FFX_CACAO_GenerateSSAOShadowsInternal(outShadowTerm, outEdges, outWeight, inPos.xy, 0, false, layerId);
|
||||
FfxFloat32x2 out0;
|
||||
out0.x = outShadowTerm;
|
||||
out0.y = FFX_CACAO_PackEdges(FfxFloat32x4(1, 1, 1, 1)); // no edges in low quality
|
||||
FFX_CACAO_SSAOGeneration_StoreOutput(coord, out0, layerId);
|
||||
}
|
||||
|
||||
void FFX_CACAO_GenerateQ1(FfxUInt32x3 tid)
|
||||
{
|
||||
FfxUInt32 tidCorrectedZ = tid.z % 5;
|
||||
FfxUInt32 layerId = tid.z / 5;
|
||||
layerId = (layerId == 1 && BlurNumPasses() == 2) ? 3 : layerId; // Choose correct layer in 2 layer case
|
||||
FfxUInt32 xOffset = (tid.y * 3 + tidCorrectedZ) % 5;
|
||||
FfxUInt32x2 coord = FfxUInt32x2(5 * tid.x + xOffset, tid.y);
|
||||
FfxFloat32x2 inPos = FfxFloat32x2(coord);
|
||||
FfxFloat32 outShadowTerm;
|
||||
FfxFloat32 outWeight;
|
||||
FfxFloat32x4 outEdges;
|
||||
FFX_CACAO_GenerateSSAOShadowsInternal(outShadowTerm, outEdges, outWeight, inPos.xy, 1, false, layerId);
|
||||
FfxFloat32x2 out0;
|
||||
out0.x = outShadowTerm;
|
||||
out0.y = FFX_CACAO_PackEdges(outEdges);
|
||||
FFX_CACAO_SSAOGeneration_StoreOutput(coord, out0, layerId);
|
||||
}
|
||||
|
||||
void FFX_CACAO_GenerateQ2(FfxUInt32x3 coord)
|
||||
{
|
||||
FfxFloat32x2 inPos = FfxFloat32x2(coord.xy);
|
||||
FfxUInt32 layerId = coord.z;
|
||||
FfxFloat32 outShadowTerm;
|
||||
FfxFloat32 outWeight;
|
||||
FfxFloat32x4 outEdges;
|
||||
FFX_CACAO_GenerateSSAOShadowsInternal(outShadowTerm, outEdges, outWeight, inPos.xy, 2, false, layerId);
|
||||
FfxFloat32x2 out0;
|
||||
out0.x = outShadowTerm;
|
||||
out0.y = FFX_CACAO_PackEdges(outEdges);
|
||||
FFX_CACAO_SSAOGeneration_StoreOutput(coord.xy, out0, layerId);
|
||||
}
|
||||
|
||||
void FFX_CACAO_GenerateQ3Base(FfxUInt32x3 coord)
|
||||
{
|
||||
FfxFloat32x2 inPos = FfxFloat32x2(coord.xy);
|
||||
FfxUInt32 layerId = coord.z;
|
||||
FfxFloat32 outShadowTerm;
|
||||
FfxFloat32 outWeight;
|
||||
FfxFloat32x4 outEdges;
|
||||
FFX_CACAO_GenerateSSAOShadowsInternal(outShadowTerm, outEdges, outWeight, inPos.xy, 3, true, layerId);
|
||||
FfxFloat32x2 out0;
|
||||
out0.x = outShadowTerm;
|
||||
out0.y = outWeight / (FfxFloat32(FFX_CACAO_ADAPTIVE_TAP_BASE_COUNT) * 4.0); //0.0; //frac(outWeight / 6.0);// / (FfxFloat32)(FFX_CACAO_MAX_TAPS * 4.0);
|
||||
FFX_CACAO_SSAOGeneration_StoreOutput(coord.xy, out0, layerId);
|
||||
}
|
||||
|
||||
void FFX_CACAO_GenerateQ3(FfxUInt32x3 coord)
|
||||
{
|
||||
FfxFloat32x2 inPos = FfxFloat32x2(coord.xy);
|
||||
FfxUInt32 layerId = coord.z;
|
||||
FfxFloat32 outShadowTerm;
|
||||
FfxFloat32 outWeight;
|
||||
FfxFloat32x4 outEdges;
|
||||
FFX_CACAO_GenerateSSAOShadowsInternal(outShadowTerm, outEdges, outWeight, inPos.xy, 3, false, layerId);
|
||||
FfxFloat32x2 out0;
|
||||
out0.x = outShadowTerm;
|
||||
out0.y = FFX_CACAO_PackEdges(outEdges);
|
||||
FFX_CACAO_SSAOGeneration_StoreOutput(coord.xy, out0, layerId);
|
||||
}
|
||||
611
betterRenderer/thirdparty/fsr2/include/FidelityFX/gpu/cacao/ffx_cacao_upscale.h
vendored
Normal file
611
betterRenderer/thirdparty/fsr2/include/FidelityFX/gpu/cacao/ffx_cacao_upscale.h
vendored
Normal file
@@ -0,0 +1,611 @@
|
||||
// This file is part of the FidelityFX SDK.
|
||||
//
|
||||
// Copyright (C) 2024 Advanced Micro Devices, Inc.
|
||||
//
|
||||
// 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.
|
||||
|
||||
#include "ffx_core.h"
|
||||
#include "ffx_cacao_defines.h"
|
||||
#include "ffx_cacao_utils.h"
|
||||
|
||||
#define FFX_CACAO_BILATERAL_UPSCALE_BUFFER_WIDTH (FFX_CACAO_BILATERAL_UPSCALE_WIDTH + 4)
|
||||
#define FFX_CACAO_BILATERAL_UPSCALE_BUFFER_HEIGHT (FFX_CACAO_BILATERAL_UPSCALE_HEIGHT + 4 + 4)
|
||||
|
||||
struct FFX_CACAO_BilateralBufferVal
|
||||
{
|
||||
FfxUInt32 packedDepths;
|
||||
FfxUInt32 packedSsaoVals;
|
||||
};
|
||||
|
||||
FFX_GROUPSHARED FFX_CACAO_BilateralBufferVal s_FFX_CACAO_BilateralUpscaleBuffer[FFX_CACAO_BILATERAL_UPSCALE_BUFFER_WIDTH][FFX_CACAO_BILATERAL_UPSCALE_BUFFER_HEIGHT];
|
||||
|
||||
void FFX_CACAO_BilateralUpscaleNxN(FfxUInt32x2 tid, FfxUInt32x2 gtid, FfxUInt32x2 gid, const FfxInt32 width, const FfxInt32 height, const bool useEdges)
|
||||
{
|
||||
// fill in group shared buffer
|
||||
{
|
||||
FfxUInt32 threadNum = (gtid.y * FFX_CACAO_BILATERAL_UPSCALE_WIDTH + gtid.x) * 3;
|
||||
FfxUInt32x2 bufferCoord = FfxUInt32x2(threadNum % FFX_CACAO_BILATERAL_UPSCALE_BUFFER_WIDTH, threadNum / FFX_CACAO_BILATERAL_UPSCALE_BUFFER_WIDTH);
|
||||
FfxUInt32x2 imageCoord = (gid * FfxUInt32x2(FFX_CACAO_BILATERAL_UPSCALE_WIDTH, FFX_CACAO_BILATERAL_UPSCALE_HEIGHT)) + bufferCoord - 2;
|
||||
|
||||
if (useEdges)
|
||||
{
|
||||
FfxFloat32x2 inputs[3];
|
||||
for (FfxInt32 j = 0; j < 3; ++j)
|
||||
{
|
||||
FfxInt32x2 p = FfxInt32x2(imageCoord.x + j, imageCoord.y);
|
||||
FfxInt32x2 pos = p / 2;
|
||||
FfxInt32 index = (p.x % 2) + 2 * (p.y % 2);
|
||||
inputs[j] = FFX_CACAO_BilateralUpscale_LoadSSAO(pos, index);
|
||||
}
|
||||
|
||||
for (FfxInt32 i = 0; i < 3; ++i)
|
||||
{
|
||||
FfxInt32 mx = FfxInt32(imageCoord.x % 2);
|
||||
FfxInt32 my = FfxInt32(imageCoord.y % 2);
|
||||
|
||||
FfxInt32 ic = mx + my * 2; // center index
|
||||
FfxInt32 ih = (1 - mx) + my * 2; // neighbouring, horizontal
|
||||
FfxInt32 iv = mx + (1 - my) * 2; // neighbouring, vertical
|
||||
FfxInt32 id = (1 - mx) + (1 - my) * 2; // diagonal
|
||||
|
||||
FfxFloat32x2 centerVal = inputs[i];
|
||||
|
||||
FfxFloat32 ao = centerVal.x;
|
||||
|
||||
FfxFloat32x4 edgesLRTB = FFX_CACAO_UnpackEdges(centerVal.y);
|
||||
|
||||
// convert index shifts to sampling offsets
|
||||
FfxFloat32 fmx = FfxFloat32(mx);
|
||||
FfxFloat32 fmy = FfxFloat32(my);
|
||||
|
||||
// in case of an edge, push sampling offsets away from the edge (towards pixel center)
|
||||
FfxFloat32 fmxe = (edgesLRTB.y - edgesLRTB.x);
|
||||
FfxFloat32 fmye = (edgesLRTB.w - edgesLRTB.z);
|
||||
|
||||
// calculate final sampling offsets and sample using bilinear filter
|
||||
FfxFloat32x2 p = imageCoord;
|
||||
FfxFloat32x2 uvH = (p + FfxFloat32x2(fmx + fmxe - 0.5, 0.5 - fmy)) * 0.5 * SSAOBufferInverseDimensions();
|
||||
FfxFloat32 aoH = FFX_CACAO_BilateralUpscale_SampleSSAOLinear(uvH, ih);
|
||||
FfxFloat32x2 uvV = (p + FfxFloat32x2(0.5 - fmx, fmy - 0.5 + fmye)) * 0.5 * SSAOBufferInverseDimensions();
|
||||
FfxFloat32 aoV = FFX_CACAO_BilateralUpscale_SampleSSAOLinear(uvV, iv);
|
||||
FfxFloat32x2 uvD = (p + FfxFloat32x2(fmx - 0.5 + fmxe, fmy - 0.5 + fmye)) * 0.5 * SSAOBufferInverseDimensions();
|
||||
FfxFloat32 aoD = FFX_CACAO_BilateralUpscale_SampleSSAOLinear(uvD, id);
|
||||
|
||||
// reduce weight for samples near edge - if the edge is on both sides, weight goes to 0
|
||||
FfxFloat32x4 blendWeights;
|
||||
blendWeights.x = 1.0;
|
||||
blendWeights.y = (edgesLRTB.x + edgesLRTB.y) * 0.5;
|
||||
blendWeights.z = (edgesLRTB.z + edgesLRTB.w) * 0.5;
|
||||
blendWeights.w = (blendWeights.y + blendWeights.z) * 0.5;
|
||||
|
||||
// calculate weighted average
|
||||
FfxFloat32 blendWeightsSum = dot(blendWeights, FfxFloat32x4(1.0, 1.0, 1.0, 1.0));
|
||||
ao = dot(FfxFloat32x4(ao, aoH, aoV, aoD), blendWeights) / blendWeightsSum;
|
||||
|
||||
++imageCoord.x;
|
||||
|
||||
FFX_CACAO_BilateralBufferVal bufferVal;
|
||||
|
||||
FfxUInt32x2 depthArrayBufferCoord = FfxUInt32x2((imageCoord / 2) + DeinterleavedDepthBufferOffset());
|
||||
FfxUInt32 depthArrayBufferIndex = ic;
|
||||
FfxFloat32 depth = FFX_CACAO_BilateralUpscale_LoadDownscaledDepth(depthArrayBufferCoord, depthArrayBufferIndex);
|
||||
|
||||
bufferVal.packedDepths = ffxPackF32(FfxFloat32x2(depth, depth));
|
||||
bufferVal.packedSsaoVals = ffxPackF32(FfxFloat32x2(ao, ao));
|
||||
|
||||
s_FFX_CACAO_BilateralUpscaleBuffer[bufferCoord.x + i][bufferCoord.y] = bufferVal;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (FfxInt32 i = 0; i < 3; ++i)
|
||||
{
|
||||
FfxFloat32x2 sampleLoc0 = (FfxFloat32x2(imageCoord / 2) + 0.5f) * SSAOBufferInverseDimensions();
|
||||
FfxFloat32x2 sampleLoc1 = sampleLoc0;
|
||||
FfxFloat32x2 sampleLoc2 = sampleLoc0;
|
||||
FfxFloat32x2 sampleLoc3 = sampleLoc0;
|
||||
switch ((imageCoord.y % 2) * 2 + (imageCoord.x % 2)) {
|
||||
case 0:
|
||||
sampleLoc1.x -= 0.5f * SSAOBufferInverseDimensions().x;
|
||||
sampleLoc2.y -= 0.5f * SSAOBufferInverseDimensions().y;
|
||||
sampleLoc3 -= 0.5f * SSAOBufferInverseDimensions();
|
||||
break;
|
||||
case 1:
|
||||
sampleLoc0.x += 0.5f * SSAOBufferInverseDimensions().x;
|
||||
sampleLoc2 += FfxFloat32x2(0.5f, -0.5f) * SSAOBufferInverseDimensions();
|
||||
sampleLoc3.y -= 0.5f * SSAOBufferInverseDimensions().y;
|
||||
break;
|
||||
case 2:
|
||||
sampleLoc0.y += 0.5f * SSAOBufferInverseDimensions().y;
|
||||
sampleLoc1 += FfxFloat32x2(-0.5f, 0.5f) * SSAOBufferInverseDimensions();
|
||||
sampleLoc3.x -= 0.5f * SSAOBufferInverseDimensions().x;
|
||||
break;
|
||||
case 3:
|
||||
sampleLoc0 += 0.5f * SSAOBufferInverseDimensions();
|
||||
sampleLoc1.y += 0.5f * SSAOBufferInverseDimensions().y;
|
||||
sampleLoc2.x += 0.5f * SSAOBufferInverseDimensions().x;
|
||||
break;
|
||||
}
|
||||
|
||||
FfxFloat32 ssaoVal0 = FFX_CACAO_BilateralUpscale_SampleSSAOPoint(sampleLoc0, 0);
|
||||
FfxFloat32 ssaoVal1 = FFX_CACAO_BilateralUpscale_SampleSSAOPoint(sampleLoc1, 1);
|
||||
FfxFloat32 ssaoVal2 = FFX_CACAO_BilateralUpscale_SampleSSAOPoint(sampleLoc2, 2);
|
||||
FfxFloat32 ssaoVal3 = FFX_CACAO_BilateralUpscale_SampleSSAOPoint(sampleLoc3, 3);
|
||||
|
||||
FfxUInt32x3 ssaoArrayBufferCoord = FfxUInt32x3(imageCoord / 2, 2 * (imageCoord.y % 2) + imageCoord.x % 2);
|
||||
FfxUInt32x2 depthArrayBufferCoord = FfxUInt32x2(ssaoArrayBufferCoord.xy + DeinterleavedDepthBufferOffset());
|
||||
FfxUInt32 depthArrayBufferIndex = ssaoArrayBufferCoord.z;
|
||||
++imageCoord.x;
|
||||
|
||||
FFX_CACAO_BilateralBufferVal bufferVal;
|
||||
|
||||
FfxFloat32 depth = FFX_CACAO_BilateralUpscale_LoadDownscaledDepth(depthArrayBufferCoord, depthArrayBufferIndex);
|
||||
FfxFloat32 ssaoVal = (ssaoVal0 + ssaoVal1 + ssaoVal2 + ssaoVal3) * 0.25f;
|
||||
|
||||
bufferVal.packedDepths = ffxPackF32(FfxFloat32x2(depth, depth));
|
||||
bufferVal.packedSsaoVals = ffxPackF32(FfxFloat32x2(ssaoVal, ssaoVal)); //CACAO_TODO half path?
|
||||
|
||||
s_FFX_CACAO_BilateralUpscaleBuffer[bufferCoord.x + i][bufferCoord.y] = bufferVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FFX_GROUP_MEMORY_BARRIER;
|
||||
|
||||
FfxFloat32 depths[4];
|
||||
// load depths
|
||||
{
|
||||
FfxInt32x2 fullBufferCoord = FfxInt32x2(2 * tid);
|
||||
FfxInt32x2 fullDepthBufferCoord = fullBufferCoord + DepthBufferOffset();
|
||||
|
||||
FfxFloat32x4 screenSpaceDepths = FFX_CACAO_BilateralUpscale_LoadDepths(fullDepthBufferCoord);
|
||||
|
||||
depths[0] = FFX_CACAO_ScreenSpaceToViewSpaceDepth(screenSpaceDepths.x);
|
||||
depths[1] = FFX_CACAO_ScreenSpaceToViewSpaceDepth(screenSpaceDepths.y);
|
||||
depths[2] = FFX_CACAO_ScreenSpaceToViewSpaceDepth(screenSpaceDepths.z);
|
||||
depths[3] = FFX_CACAO_ScreenSpaceToViewSpaceDepth(screenSpaceDepths.w);
|
||||
}
|
||||
|
||||
#if FFX_HALF
|
||||
FfxFloat16x4 packedDepths = FfxFloat16x4(depths[0], depths[1], depths[2], depths[3]);
|
||||
|
||||
FfxInt32x2 baseBufferCoord = FfxInt32x2(gtid) + FfxInt32x2(width, height);
|
||||
|
||||
FfxFloat16 epsilonWeight = FfxFloat16(1e-3f);
|
||||
FfxFloat16x2 nearestSsaoVals = ffxUnpackF16(s_FFX_CACAO_BilateralUpscaleBuffer[baseBufferCoord.x][baseBufferCoord.y].packedSsaoVals);
|
||||
FfxFloat16x4 packedTotals = epsilonWeight * FfxFloat16x4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
packedTotals.xy *= nearestSsaoVals;
|
||||
packedTotals.zw *= nearestSsaoVals;
|
||||
FfxFloat16x4 packedTotalWeights = epsilonWeight * FfxFloat16x4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
FfxFloat32 distanceSigma = BilateralSimilarityDistanceSigma();
|
||||
FfxFloat16x2 packedDistSigma = FfxFloat16x2(1.0f / distanceSigma, 1.0f / distanceSigma);
|
||||
FfxFloat32 sigma = BilateralSigmaSquared();
|
||||
FfxFloat16x2 packedSigma = FfxFloat16x2(1.0f / sigma, 1.0f / sigma);
|
||||
|
||||
for (FfxInt32 x = -width; x <= width; ++x)
|
||||
{
|
||||
for (FfxInt32 y = -height; y <= height; ++y)
|
||||
{
|
||||
FfxInt32x2 bufferCoord = baseBufferCoord + FfxInt32x2(x, y);
|
||||
|
||||
FFX_CACAO_BilateralBufferVal bufferVal = s_FFX_CACAO_BilateralUpscaleBuffer[bufferCoord.x][bufferCoord.y];
|
||||
|
||||
FfxFloat16x2 u = FfxFloat16x2(x, x) - FfxFloat16x2(0.0f, 0.5f);
|
||||
FfxFloat16x2 v1 = FfxFloat16x2(y, y) - FfxFloat16x2(0.0f, 0.0f);
|
||||
FfxFloat16x2 v2 = FfxFloat16x2(y, y) - FfxFloat16x2(0.5f, 0.5f);
|
||||
u = u * u;
|
||||
v1 = v1 * v1;
|
||||
v2 = v2 * v2;
|
||||
|
||||
FfxFloat16x2 dist1 = u + v1;
|
||||
FfxFloat16x2 dist2 = u + v2;
|
||||
|
||||
FfxFloat16x2 wx1 = exp(-dist1 * packedSigma);
|
||||
FfxFloat16x2 wx2 = exp(-dist2 * packedSigma);
|
||||
|
||||
FfxFloat16x2 bufferPackedDepths = ffxUnpackF16(bufferVal.packedDepths);
|
||||
|
||||
FfxFloat16x2 diff1 = packedDepths.xy - bufferPackedDepths;
|
||||
FfxFloat16x2 diff2 = packedDepths.zw - bufferPackedDepths;
|
||||
diff1 *= diff1;
|
||||
diff2 *= diff2;
|
||||
|
||||
FfxFloat16x2 wy1 = exp(-diff1 * packedDistSigma);
|
||||
FfxFloat16x2 wy2 = exp(-diff2 * packedDistSigma);
|
||||
|
||||
FfxFloat16x2 weight1 = wx1 * wy1;
|
||||
FfxFloat16x2 weight2 = wx2 * wy2;
|
||||
|
||||
FfxFloat16x2 packedSsaoVals = ffxUnpackF16(bufferVal.packedSsaoVals);
|
||||
packedTotals.xy += packedSsaoVals * weight1;
|
||||
packedTotals.zw += packedSsaoVals * weight2;
|
||||
packedTotalWeights.xy += weight1;
|
||||
packedTotalWeights.zw += weight2;
|
||||
}
|
||||
}
|
||||
|
||||
FfxUInt32x2 outputCoord = 2 * tid;
|
||||
FfxFloat16x4 outputValues = packedTotals / packedTotalWeights;
|
||||
#else
|
||||
FfxFloat32x4 packedDepths = FfxFloat32x4(depths[0], depths[1], depths[2], depths[3]);
|
||||
|
||||
FfxInt32x2 baseBufferCoord = FfxInt32x2(gtid) + FfxInt32x2(width, height);
|
||||
|
||||
FfxFloat32 epsilonWeight = FfxFloat32(1e-3f);
|
||||
FfxFloat32x2 nearestSsaoVals = ffxUnpackF32(s_FFX_CACAO_BilateralUpscaleBuffer[baseBufferCoord.x][baseBufferCoord.y].packedSsaoVals);
|
||||
FfxFloat32x4 packedTotals = epsilonWeight * FfxFloat32x4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
packedTotals.xy *= nearestSsaoVals;
|
||||
packedTotals.zw *= nearestSsaoVals;
|
||||
FfxFloat32x4 packedTotalWeights = epsilonWeight * FfxFloat32x4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
FfxFloat32 distanceSigma = BilateralSimilarityDistanceSigma();
|
||||
FfxFloat32x2 packedDistSigma = FfxFloat32x2(1.0f / distanceSigma, 1.0f / distanceSigma);
|
||||
FfxFloat32 sigma = BilateralSigmaSquared();
|
||||
FfxFloat32x2 packedSigma = FfxFloat32x2(1.0f / sigma, 1.0f / sigma);
|
||||
|
||||
for (FfxInt32 x = -width; x <= width; ++x)
|
||||
{
|
||||
for (FfxInt32 y = -height; y <= height; ++y)
|
||||
{
|
||||
FfxInt32x2 bufferCoord = baseBufferCoord + FfxInt32x2(x, y);
|
||||
|
||||
FFX_CACAO_BilateralBufferVal bufferVal = s_FFX_CACAO_BilateralUpscaleBuffer[bufferCoord.x][bufferCoord.y];
|
||||
|
||||
FfxFloat32x2 u = FfxFloat32x2(x, x) - FfxFloat32x2(0.0f, 0.5f);
|
||||
FfxFloat32x2 v1 = FfxFloat32x2(y, y) - FfxFloat32x2(0.0f, 0.0f);
|
||||
FfxFloat32x2 v2 = FfxFloat32x2(y, y) - FfxFloat32x2(0.5f, 0.5f);
|
||||
u = u * u;
|
||||
v1 = v1 * v1;
|
||||
v2 = v2 * v2;
|
||||
|
||||
FfxFloat32x2 dist1 = u + v1;
|
||||
FfxFloat32x2 dist2 = u + v2;
|
||||
|
||||
FfxFloat32x2 wx1 = exp(-dist1 * packedSigma);
|
||||
FfxFloat32x2 wx2 = exp(-dist2 * packedSigma);
|
||||
|
||||
FfxFloat32x2 bufferPackedDepths = ffxUnpackF32(bufferVal.packedDepths);
|
||||
|
||||
FfxFloat32x2 diff1 = packedDepths.xy - bufferPackedDepths;
|
||||
FfxFloat32x2 diff2 = packedDepths.zw - bufferPackedDepths;
|
||||
diff1 *= diff1;
|
||||
diff2 *= diff2;
|
||||
|
||||
FfxFloat32x2 wy1 = exp(-diff1 * packedDistSigma);
|
||||
FfxFloat32x2 wy2 = exp(-diff2 * packedDistSigma);
|
||||
|
||||
FfxFloat32x2 weight1 = wx1 * wy1;
|
||||
FfxFloat32x2 weight2 = wx2 * wy2;
|
||||
|
||||
FfxFloat32x2 packedSsaoVals = ffxUnpackF32(bufferVal.packedSsaoVals);
|
||||
packedTotals.xy += packedSsaoVals * weight1;
|
||||
packedTotals.zw += packedSsaoVals * weight2;
|
||||
packedTotalWeights.xy += weight1;
|
||||
packedTotalWeights.zw += weight2;
|
||||
}
|
||||
}
|
||||
|
||||
FfxUInt32x2 outputCoord = 2 * tid;
|
||||
FfxFloat32x4 outputValues = packedTotals / packedTotalWeights;
|
||||
outputValues = pow(outputValues, FfxFloat32x4(2.2, 2.2, 2.2, 2.2));
|
||||
#endif //FFX_HALF
|
||||
FFX_CACAO_BilateralUpscale_StoreOutput(outputCoord, FfxInt32x2(0, 0), outputValues.x); // totals[0] / totalWeights[0];
|
||||
FFX_CACAO_BilateralUpscale_StoreOutput(outputCoord, FfxInt32x2(1, 0), outputValues.y); // totals[1] / totalWeights[1];
|
||||
FFX_CACAO_BilateralUpscale_StoreOutput(outputCoord, FfxInt32x2(0, 1), outputValues.z); // totals[2] / totalWeights[2];
|
||||
FFX_CACAO_BilateralUpscale_StoreOutput(outputCoord, FfxInt32x2(1, 1), outputValues.w); // totals[3] / totalWeights[3];
|
||||
}
|
||||
|
||||
|
||||
void FFX_CACAO_UpscaleBilateral5x5Smart(FfxUInt32x2 tid, FfxUInt32x2 gtid, FfxUInt32x2 gid)
|
||||
{
|
||||
FFX_CACAO_BilateralUpscaleNxN(tid, gtid, gid, 2, 2, true);
|
||||
}
|
||||
|
||||
void FFX_CACAO_UpscaleBilateral5x5NonSmart(FfxUInt32x2 tid, FfxUInt32x2 gtid, FfxUInt32x2 gid)
|
||||
{
|
||||
FFX_CACAO_BilateralUpscaleNxN(tid, gtid, gid, 2, 2, false);
|
||||
}
|
||||
|
||||
void FFX_CACAO_UpscaleBilateral7x7(FfxUInt32x2 tid, FfxUInt32x2 gtid, FfxUInt32x2 gid)
|
||||
{
|
||||
FFX_CACAO_BilateralUpscaleNxN(tid, gtid, gid, 3, 3, true);
|
||||
}
|
||||
|
||||
#if FFX_HALF
|
||||
void FFX_CACAO_UpscaleBilateral5x5Half(FfxUInt32x2 tid, FfxUInt32x2 gtid, FfxUInt32x2 gid)
|
||||
{
|
||||
const FfxInt32 width = 2, height = 2;
|
||||
|
||||
// fill in group shared buffer
|
||||
{
|
||||
FfxUInt32 threadNum = (gtid.y * FFX_CACAO_BILATERAL_UPSCALE_WIDTH + gtid.x) * 3;
|
||||
FfxUInt32x2 bufferCoord = FfxUInt32x2(threadNum % FFX_CACAO_BILATERAL_UPSCALE_BUFFER_WIDTH, threadNum / FFX_CACAO_BILATERAL_UPSCALE_BUFFER_WIDTH);
|
||||
FfxUInt32x2 imageCoord = (gid * FfxUInt32x2(FFX_CACAO_BILATERAL_UPSCALE_WIDTH, FFX_CACAO_BILATERAL_UPSCALE_HEIGHT)) + bufferCoord - 2;
|
||||
|
||||
for (FfxInt32 i = 0; i < 3; ++i)
|
||||
{
|
||||
FfxFloat32x2 sampleLoc0 = (FfxFloat32x2(imageCoord / 2) + 0.5f) * SSAOBufferInverseDimensions();
|
||||
FfxFloat32x2 sampleLoc1 = sampleLoc0;
|
||||
switch ((imageCoord.y % 2) * 2 + (imageCoord.x % 2)) {
|
||||
case 0:
|
||||
sampleLoc1 -= 0.5f * SSAOBufferInverseDimensions();
|
||||
break;
|
||||
case 1:
|
||||
sampleLoc0.x += 0.5f * SSAOBufferInverseDimensions().x;
|
||||
sampleLoc1.y -= 0.5f * SSAOBufferInverseDimensions().y;
|
||||
break;
|
||||
case 2:
|
||||
sampleLoc0.y += 0.5f * SSAOBufferInverseDimensions().y;
|
||||
sampleLoc1.x -= 0.5f * SSAOBufferInverseDimensions().x;
|
||||
break;
|
||||
case 3:
|
||||
sampleLoc0 += 0.5f * SSAOBufferInverseDimensions();
|
||||
break;
|
||||
}
|
||||
|
||||
FfxFloat32 ssaoVal0 = FFX_CACAO_BilateralUpscale_SampleSSAOPoint(sampleLoc0, 0);
|
||||
FfxFloat32 ssaoVal1 = FFX_CACAO_BilateralUpscale_SampleSSAOPoint(sampleLoc1, 3);
|
||||
|
||||
FfxUInt32x2 depthArrayBufferCoord = FfxUInt32x2((imageCoord / 2) + DeinterleavedDepthBufferOffset());
|
||||
FfxUInt32 depthArrayBufferIndex = (imageCoord.y % 2) * 3;
|
||||
++imageCoord.x;
|
||||
|
||||
FFX_CACAO_BilateralBufferVal bufferVal;
|
||||
|
||||
FfxFloat32 depth = FFX_CACAO_BilateralUpscale_LoadDownscaledDepth(depthArrayBufferCoord, depthArrayBufferIndex);
|
||||
FfxFloat32 ssaoVal = (ssaoVal0 + ssaoVal1) * 0.5f;
|
||||
|
||||
bufferVal.packedDepths = ffxPackF16(FfxFloat16x2(depth, depth));
|
||||
bufferVal.packedSsaoVals = ffxPackF16(FfxFloat16x2(ssaoVal, ssaoVal));
|
||||
|
||||
s_FFX_CACAO_BilateralUpscaleBuffer[bufferCoord.x + i][bufferCoord.y] = bufferVal;
|
||||
}
|
||||
}
|
||||
|
||||
FFX_GROUP_MEMORY_BARRIER;
|
||||
|
||||
FfxFloat32 depths[4];
|
||||
// load depths
|
||||
{
|
||||
FfxInt32x2 fullBufferCoord = FfxInt32x2(2 * tid);
|
||||
FfxInt32x2 fullDepthBufferCoord = fullBufferCoord + DepthBufferOffset();
|
||||
|
||||
FfxFloat32x4 screenSpaceDepths = FFX_CACAO_BilateralUpscale_LoadDepths(fullDepthBufferCoord);
|
||||
|
||||
depths[0] = FFX_CACAO_ScreenSpaceToViewSpaceDepth(screenSpaceDepths.x);
|
||||
depths[1] = FFX_CACAO_ScreenSpaceToViewSpaceDepth(screenSpaceDepths.y);
|
||||
depths[2] = FFX_CACAO_ScreenSpaceToViewSpaceDepth(screenSpaceDepths.z);
|
||||
depths[3] = FFX_CACAO_ScreenSpaceToViewSpaceDepth(screenSpaceDepths.w);
|
||||
}
|
||||
FfxFloat16x4 packedDepths = FfxFloat16x4(depths[0], depths[1], depths[2], depths[3]);
|
||||
|
||||
FfxInt32x2 baseBufferCoord = FfxInt32x2(gtid) + FfxInt32x2(width, height);
|
||||
|
||||
FfxFloat16 epsilonWeight = FfxFloat16(1e-3f);
|
||||
FfxFloat16x2 nearestSsaoVals = ffxUnpackF16(s_FFX_CACAO_BilateralUpscaleBuffer[baseBufferCoord.x][baseBufferCoord.y].packedSsaoVals);
|
||||
FfxFloat16x4 packedTotals = epsilonWeight * FfxFloat16x4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
packedTotals.xy *= nearestSsaoVals;
|
||||
packedTotals.zw *= nearestSsaoVals;
|
||||
FfxFloat16x4 packedTotalWeights = epsilonWeight * FfxFloat16x4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
FfxFloat32 distanceSigma = BilateralSimilarityDistanceSigma();
|
||||
FfxFloat16x2 packedDistSigma = FfxFloat16x2(1.0f / distanceSigma, 1.0f / distanceSigma);
|
||||
FfxFloat32 sigma = BilateralSigmaSquared();
|
||||
FfxFloat16x2 packedSigma = FfxFloat16x2(1.0f / sigma, 1.0f / sigma);
|
||||
|
||||
for (FfxInt32 x = -width; x <= width; ++x)
|
||||
{
|
||||
for (FfxInt32 y = -height; y <= height; ++y)
|
||||
{
|
||||
FfxInt32x2 bufferCoord = baseBufferCoord + FfxInt32x2(x, y);
|
||||
|
||||
FFX_CACAO_BilateralBufferVal bufferVal = s_FFX_CACAO_BilateralUpscaleBuffer[bufferCoord.x][bufferCoord.y];
|
||||
|
||||
FfxFloat16x2 u = FfxFloat16x2(x, x) - FfxFloat16x2(0.0f, 0.5f);
|
||||
FfxFloat16x2 v1 = FfxFloat16x2(y, y) - FfxFloat16x2(0.0f, 0.0f);
|
||||
FfxFloat16x2 v2 = FfxFloat16x2(y, y) - FfxFloat16x2(0.5f, 0.5f);
|
||||
u = u * u;
|
||||
v1 = v1 * v1;
|
||||
v2 = v2 * v2;
|
||||
|
||||
FfxFloat16x2 dist1 = u + v1;
|
||||
FfxFloat16x2 dist2 = u + v2;
|
||||
|
||||
FfxFloat16x2 wx1 = exp(-dist1 * packedSigma);
|
||||
FfxFloat16x2 wx2 = exp(-dist2 * packedSigma);
|
||||
|
||||
FfxFloat16x2 bufferPackedDepths = ffxUnpackF16(bufferVal.packedDepths);
|
||||
|
||||
FfxFloat16x2 diff1 = packedDepths.xy - bufferPackedDepths;
|
||||
FfxFloat16x2 diff2 = packedDepths.zw - bufferPackedDepths;
|
||||
diff1 *= diff1;
|
||||
diff2 *= diff2;
|
||||
|
||||
FfxFloat16x2 wy1 = exp(-diff1 * packedDistSigma);
|
||||
FfxFloat16x2 wy2 = exp(-diff2 * packedDistSigma);
|
||||
|
||||
FfxFloat16x2 weight1 = wx1 * wy1;
|
||||
FfxFloat16x2 weight2 = wx2 * wy2;
|
||||
|
||||
FfxFloat16x2 packedSsaoVals = ffxUnpackF16(bufferVal.packedSsaoVals);
|
||||
packedTotals.xy += packedSsaoVals * weight1;
|
||||
packedTotals.zw += packedSsaoVals * weight2;
|
||||
packedTotalWeights.xy += weight1;
|
||||
packedTotalWeights.zw += weight2;
|
||||
}
|
||||
}
|
||||
|
||||
FfxUInt32x2 outputCoord = 2 * tid;
|
||||
FfxFloat16x4 outputValues = packedTotals / packedTotalWeights;
|
||||
FFX_CACAO_BilateralUpscale_StoreOutput(outputCoord, FfxInt32x2(0, 0), outputValues.x); // totals[0] / totalWeights[0];
|
||||
FFX_CACAO_BilateralUpscale_StoreOutput(outputCoord, FfxInt32x2(1, 0), outputValues.y); // totals[1] / totalWeights[1];
|
||||
FFX_CACAO_BilateralUpscale_StoreOutput(outputCoord, FfxInt32x2(0, 1), outputValues.z); // totals[2] / totalWeights[2];
|
||||
FFX_CACAO_BilateralUpscale_StoreOutput(outputCoord, FfxInt32x2(1, 1), outputValues.w); // totals[3] / totalWeights[3];
|
||||
}
|
||||
#else
|
||||
void FFX_CACAO_UpscaleBilateral5x5(FfxUInt32x2 tid, FfxUInt32x2 gtid, FfxUInt32x2 gid)
|
||||
{
|
||||
const FfxInt32 width = 2, height = 2;
|
||||
|
||||
// fill in group shared buffer
|
||||
{
|
||||
FfxUInt32 threadNum = (gtid.y * FFX_CACAO_BILATERAL_UPSCALE_WIDTH + gtid.x) * 3;
|
||||
FfxUInt32x2 bufferCoord = FfxUInt32x2(threadNum % FFX_CACAO_BILATERAL_UPSCALE_BUFFER_WIDTH, threadNum / FFX_CACAO_BILATERAL_UPSCALE_BUFFER_WIDTH);
|
||||
FfxUInt32x2 imageCoord = (gid * FfxUInt32x2(FFX_CACAO_BILATERAL_UPSCALE_WIDTH, FFX_CACAO_BILATERAL_UPSCALE_HEIGHT)) + bufferCoord - 2;
|
||||
|
||||
for (FfxInt32 i = 0; i < 3; ++i)
|
||||
{
|
||||
FfxFloat32x2 sampleLoc0 = (FfxFloat32x2(imageCoord / 2) + 0.5f) * SSAOBufferInverseDimensions();
|
||||
FfxFloat32x2 sampleLoc1 = sampleLoc0;
|
||||
switch ((imageCoord.y % 2) * 2 + (imageCoord.x % 2)) {
|
||||
case 0:
|
||||
sampleLoc1 -= 0.5f * SSAOBufferInverseDimensions();
|
||||
break;
|
||||
case 1:
|
||||
sampleLoc0.x += 0.5f * SSAOBufferInverseDimensions().x;
|
||||
sampleLoc1.y -= 0.5f * SSAOBufferInverseDimensions().y;
|
||||
break;
|
||||
case 2:
|
||||
sampleLoc0.y += 0.5f * SSAOBufferInverseDimensions().y;
|
||||
sampleLoc1.x -= 0.5f * SSAOBufferInverseDimensions().x;
|
||||
break;
|
||||
case 3:
|
||||
sampleLoc0 += 0.5f * SSAOBufferInverseDimensions();
|
||||
break;
|
||||
}
|
||||
|
||||
FfxFloat32 ssaoVal0 = FFX_CACAO_BilateralUpscale_SampleSSAOPoint(sampleLoc0, 0);
|
||||
FfxFloat32 ssaoVal1 = FFX_CACAO_BilateralUpscale_SampleSSAOPoint(sampleLoc1, 3);
|
||||
|
||||
FfxUInt32x2 depthArrayBufferCoord = FfxUInt32x2((imageCoord / 2) + DeinterleavedDepthBufferOffset());
|
||||
FfxUInt32 depthArrayBufferIndex = (imageCoord.y % 2) * 3;
|
||||
++imageCoord.x;
|
||||
|
||||
FFX_CACAO_BilateralBufferVal bufferVal;
|
||||
|
||||
FfxFloat32 depth = FFX_CACAO_BilateralUpscale_LoadDownscaledDepth(depthArrayBufferCoord, depthArrayBufferIndex);
|
||||
FfxFloat32 ssaoVal = (ssaoVal0 + ssaoVal1) * 0.5f;
|
||||
|
||||
bufferVal.packedDepths = ffxPackF32(FfxFloat32x2(depth, depth));
|
||||
bufferVal.packedSsaoVals = ffxPackF32(FfxFloat32x2(ssaoVal, ssaoVal));
|
||||
|
||||
s_FFX_CACAO_BilateralUpscaleBuffer[bufferCoord.x + i][bufferCoord.y] = bufferVal;
|
||||
}
|
||||
}
|
||||
|
||||
FFX_GROUP_MEMORY_BARRIER;
|
||||
|
||||
FfxFloat32 depths[4];
|
||||
// load depths
|
||||
{
|
||||
FfxInt32x2 fullBufferCoord = FfxInt32x2(2 * tid);
|
||||
FfxInt32x2 fullDepthBufferCoord = fullBufferCoord + DepthBufferOffset();
|
||||
|
||||
FfxFloat32x4 screenSpaceDepths = FFX_CACAO_BilateralUpscale_LoadDepths(fullDepthBufferCoord);
|
||||
|
||||
depths[0] = FFX_CACAO_ScreenSpaceToViewSpaceDepth(screenSpaceDepths.x);
|
||||
depths[1] = FFX_CACAO_ScreenSpaceToViewSpaceDepth(screenSpaceDepths.y);
|
||||
depths[2] = FFX_CACAO_ScreenSpaceToViewSpaceDepth(screenSpaceDepths.z);
|
||||
depths[3] = FFX_CACAO_ScreenSpaceToViewSpaceDepth(screenSpaceDepths.w);
|
||||
}
|
||||
FfxFloat32x4 packedDepths = FfxFloat32x4(depths[0], depths[1], depths[2], depths[3]);
|
||||
|
||||
FfxInt32x2 baseBufferCoord = FfxInt32x2(gtid) + FfxInt32x2(width, height);
|
||||
|
||||
FfxFloat32 epsilonWeight = FfxFloat32(1e-3f);
|
||||
FfxFloat32x2 nearestSsaoVals = ffxUnpackF32(s_FFX_CACAO_BilateralUpscaleBuffer[baseBufferCoord.x][baseBufferCoord.y].packedSsaoVals);
|
||||
FfxFloat32x4 packedTotals = epsilonWeight * FfxFloat32x4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
packedTotals.xy *= nearestSsaoVals;
|
||||
packedTotals.zw *= nearestSsaoVals;
|
||||
FfxFloat32x4 packedTotalWeights = epsilonWeight * FfxFloat32x4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
FfxFloat32 distanceSigma = BilateralSimilarityDistanceSigma();
|
||||
FfxFloat32x2 packedDistSigma = FfxFloat32x2(1.0f / distanceSigma, 1.0f / distanceSigma);
|
||||
FfxFloat32 sigma = BilateralSigmaSquared();
|
||||
FfxFloat32x2 packedSigma = FfxFloat32x2(1.0f / sigma, 1.0f / sigma);
|
||||
|
||||
for (FfxInt32 x = -width; x <= width; ++x)
|
||||
{
|
||||
for (FfxInt32 y = -height; y <= height; ++y)
|
||||
{
|
||||
FfxInt32x2 bufferCoord = baseBufferCoord + FfxInt32x2(x, y);
|
||||
|
||||
FFX_CACAO_BilateralBufferVal bufferVal = s_FFX_CACAO_BilateralUpscaleBuffer[bufferCoord.x][bufferCoord.y];
|
||||
|
||||
FfxFloat32x2 u = FfxFloat32x2(x, x) - FfxFloat32x2(0.0f, 0.5f);
|
||||
FfxFloat32x2 v1 = FfxFloat32x2(y, y) - FfxFloat32x2(0.0f, 0.0f);
|
||||
FfxFloat32x2 v2 = FfxFloat32x2(y, y) - FfxFloat32x2(0.5f, 0.5f);
|
||||
u = u * u;
|
||||
v1 = v1 * v1;
|
||||
v2 = v2 * v2;
|
||||
|
||||
FfxFloat32x2 dist1 = u + v1;
|
||||
FfxFloat32x2 dist2 = u + v2;
|
||||
|
||||
FfxFloat32x2 wx1 = exp(-dist1 * packedSigma);
|
||||
FfxFloat32x2 wx2 = exp(-dist2 * packedSigma);
|
||||
|
||||
FfxFloat32x2 bufferPackedDepths = ffxUnpackF32(bufferVal.packedDepths);
|
||||
|
||||
FfxFloat32x2 diff1 = packedDepths.xy - bufferPackedDepths;
|
||||
FfxFloat32x2 diff2 = packedDepths.zw - bufferPackedDepths;
|
||||
diff1 *= diff1;
|
||||
diff2 *= diff2;
|
||||
|
||||
FfxFloat32x2 wy1 = exp(-diff1 * packedDistSigma);
|
||||
FfxFloat32x2 wy2 = exp(-diff2 * packedDistSigma);
|
||||
|
||||
FfxFloat32x2 weight1 = wx1 * wy1;
|
||||
FfxFloat32x2 weight2 = wx2 * wy2;
|
||||
|
||||
FfxFloat32x2 packedSsaoVals = ffxUnpackF32(bufferVal.packedSsaoVals);
|
||||
packedTotals.xy += packedSsaoVals * weight1;
|
||||
packedTotals.zw += packedSsaoVals * weight2;
|
||||
packedTotalWeights.xy += weight1;
|
||||
packedTotalWeights.zw += weight2;
|
||||
}
|
||||
}
|
||||
|
||||
FfxUInt32x2 outputCoord = 2 * tid;
|
||||
FfxFloat32x4 outputValues = packedTotals / packedTotalWeights;
|
||||
FFX_CACAO_BilateralUpscale_StoreOutput(outputCoord, FfxInt32x2(0, 0), outputValues.x); // totals[0] / totalWeights[0];
|
||||
FFX_CACAO_BilateralUpscale_StoreOutput(outputCoord, FfxInt32x2(1, 0), outputValues.y); // totals[1] / totalWeights[1];
|
||||
FFX_CACAO_BilateralUpscale_StoreOutput(outputCoord, FfxInt32x2(0, 1), outputValues.z); // totals[2] / totalWeights[2];
|
||||
FFX_CACAO_BilateralUpscale_StoreOutput(outputCoord, FfxInt32x2(1, 1), outputValues.w); // totals[3] / totalWeights[3];
|
||||
}
|
||||
#endif //FFX_HALF
|
||||
|
||||
void FFX_CACAO_UpscaleBilateral5x5Pass(FfxUInt32x2 tid, FfxUInt32x2 gtid, FfxUInt32x2 gid)
|
||||
{
|
||||
#if FFX_CACAO_OPTION_APPLY_SMART
|
||||
FFX_CACAO_UpscaleBilateral5x5Smart(tid, gtid, gid);
|
||||
#else
|
||||
|
||||
#if FFX_HALF
|
||||
FFX_CACAO_UpscaleBilateral5x5Half(tid, gtid, gid);
|
||||
#else
|
||||
FFX_CACAO_UpscaleBilateral5x5NonSmart(tid, gtid, gid);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#undef FFX_CACAO_BILATERAL_UPSCALE_BUFFER_WIDTH
|
||||
#undef FFX_CACAO_BILATERAL_UPSCALE_BUFFER_HEIGHT
|
||||
104
betterRenderer/thirdparty/fsr2/include/FidelityFX/gpu/cacao/ffx_cacao_utils.h
vendored
Normal file
104
betterRenderer/thirdparty/fsr2/include/FidelityFX/gpu/cacao/ffx_cacao_utils.h
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
// This file is part of the FidelityFX SDK.
|
||||
//
|
||||
// Copyright (C) 2024 Advanced Micro Devices, Inc.
|
||||
//
|
||||
// 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.
|
||||
|
||||
// packing/unpacking for edges; 2 bits per edge mean 4 gradient values (0, 0.33, 0.66, 1) for smoother transitions!
|
||||
FfxFloat32 FFX_CACAO_PackEdges(FfxFloat32x4 edgesLRTB)
|
||||
{
|
||||
edgesLRTB = round(ffxSaturate(edgesLRTB) * 3.05);
|
||||
return dot(edgesLRTB, FfxFloat32x4(64.0 / 255.0, 16.0 / 255.0, 4.0 / 255.0, 1.0 / 255.0));
|
||||
}
|
||||
|
||||
FfxFloat32x4 FFX_CACAO_UnpackEdges(FfxFloat32 _packedVal)
|
||||
{
|
||||
FfxUInt32 packedVal = FfxUInt32(_packedVal * 255.5);
|
||||
FfxFloat32x4 edgesLRTB;
|
||||
edgesLRTB.x = FfxFloat32((packedVal >> 6) & 0x03) / 3.0; // there's really no need for mask (as it's an 8 bit input) but I'll leave it in so it doesn't cause any trouble in the future
|
||||
edgesLRTB.y = FfxFloat32((packedVal >> 4) & 0x03) / 3.0;
|
||||
edgesLRTB.z = FfxFloat32((packedVal >> 2) & 0x03) / 3.0;
|
||||
edgesLRTB.w = FfxFloat32((packedVal >> 0) & 0x03) / 3.0;
|
||||
|
||||
return ffxSaturate(edgesLRTB + InvSharpness());
|
||||
}
|
||||
|
||||
FfxFloat32 FFX_CACAO_ScreenSpaceToViewSpaceDepth(FfxFloat32 screenDepth)
|
||||
{
|
||||
FfxFloat32 depthLinearizeMul = DepthUnpackConsts().x;
|
||||
FfxFloat32 depthLinearizeAdd = DepthUnpackConsts().y;
|
||||
|
||||
return depthLinearizeMul * ffxInvertSafe(depthLinearizeAdd - screenDepth);
|
||||
}
|
||||
|
||||
FfxFloat32x4 FFX_CACAO_ScreenSpaceToViewSpaceDepth(FfxFloat32x4 screenDepth)
|
||||
{
|
||||
FfxFloat32 depthLinearizeMul = DepthUnpackConsts().x;
|
||||
FfxFloat32 depthLinearizeAdd = DepthUnpackConsts().y;
|
||||
|
||||
return depthLinearizeMul * ffxInvertSafe(depthLinearizeAdd - screenDepth);
|
||||
}
|
||||
|
||||
FfxFloat32x4 FFX_CACAO_CalculateEdges(const FfxFloat32 centerZ, const FfxFloat32 leftZ, const FfxFloat32 rightZ, const FfxFloat32 topZ, const FfxFloat32 bottomZ)
|
||||
{
|
||||
// slope-sensitive depth-based edge detection
|
||||
FfxFloat32x4 edgesLRTB = FfxFloat32x4(leftZ, rightZ, topZ, bottomZ) - centerZ;
|
||||
FfxFloat32x4 edgesLRTBSlopeAdjusted = edgesLRTB + edgesLRTB.yxwz;
|
||||
edgesLRTB = min(abs(edgesLRTB), abs(edgesLRTBSlopeAdjusted));
|
||||
return ffxSaturate((1.3 - edgesLRTB / (centerZ * 0.040)));
|
||||
}
|
||||
|
||||
FfxFloat32x3 FFX_CACAO_NDCToViewSpace(FfxFloat32x2 pos, FfxFloat32 viewspaceDepth)
|
||||
{
|
||||
FfxFloat32x3 ret;
|
||||
|
||||
ret.xy = (NDCToViewMul() * pos.xy + NDCToViewAdd()) * viewspaceDepth;
|
||||
|
||||
ret.z = viewspaceDepth;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
FfxFloat32x3 FFX_CACAO_DepthBufferUVToViewSpace(FfxFloat32x2 pos, FfxFloat32 viewspaceDepth)
|
||||
{
|
||||
FfxFloat32x3 ret;
|
||||
ret.xy = (DepthBufferUVToViewMul() * pos.xy + DepthBufferUVToViewAdd()) * viewspaceDepth;
|
||||
ret.z = viewspaceDepth;
|
||||
return ret;
|
||||
}
|
||||
|
||||
FfxFloat32x3 FFX_CACAO_CalculateNormal(const FfxFloat32x4 edgesLRTB, FfxFloat32x3 pixCenterPos, FfxFloat32x3 pixLPos, FfxFloat32x3 pixRPos, FfxFloat32x3 pixTPos, FfxFloat32x3 pixBPos)
|
||||
{
|
||||
// Get this pixel's viewspace normal
|
||||
FfxFloat32x4 acceptedNormals = FfxFloat32x4(edgesLRTB.x*edgesLRTB.z, edgesLRTB.z*edgesLRTB.y, edgesLRTB.y*edgesLRTB.w, edgesLRTB.w*edgesLRTB.x);
|
||||
|
||||
pixLPos = normalize(pixLPos - pixCenterPos);
|
||||
pixRPos = normalize(pixRPos - pixCenterPos);
|
||||
pixTPos = normalize(pixTPos - pixCenterPos);
|
||||
pixBPos = normalize(pixBPos - pixCenterPos);
|
||||
|
||||
FfxFloat32x3 pixelNormal = FfxFloat32x3(0, 0, -0.0005);
|
||||
pixelNormal += (acceptedNormals.x) * cross(pixLPos, pixTPos);
|
||||
pixelNormal += (acceptedNormals.y) * cross(pixTPos, pixRPos);
|
||||
pixelNormal += (acceptedNormals.z) * cross(pixRPos, pixBPos);
|
||||
pixelNormal += (acceptedNormals.w) * cross(pixBPos, pixLPos);
|
||||
pixelNormal = normalize(pixelNormal);
|
||||
|
||||
return pixelNormal;
|
||||
}
|
||||
Reference in New Issue
Block a user