From fd7f1fd89aeb6225d2efd52f2a8668c357dd327c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Wed, 8 Jan 2025 17:35:59 +0100 Subject: [PATCH] Nvidia vulkan nan fix --- .../shaders/volumetricCloud_upsamplePS.hlsl | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/WickedEngine/shaders/volumetricCloud_upsamplePS.hlsl b/WickedEngine/shaders/volumetricCloud_upsamplePS.hlsl index fdf9e2274..ae87b6d28 100644 --- a/WickedEngine/shaders/volumetricCloud_upsamplePS.hlsl +++ b/WickedEngine/shaders/volumetricCloud_upsamplePS.hlsl @@ -8,7 +8,6 @@ Texture2D cloud_depth_current : register(t1); static const int UPSAMPLE_SAMPLE_RADIUS = 1; -#define GAUSSIAN_UPSAMPLE #define GAUSSIAN_SIGMA_SPATIAL 0.5 #define GAUSSIAN_SIGMA_RANGE 100.0 @@ -52,23 +51,19 @@ float4 main(float4 pos : SV_Position, float2 uv : TEXCOORD) : SV_Target const float4 depthDiff = abs(tToDepthBuffer - lineardepth_lowres); float depthDiffMax = max(max(depthDiff.x, depthDiff.y), max(depthDiff.z, depthDiff.w)); - bool validResult = false; half4 result = 0; [branch] if (depthDiffMax < tToDepthBuffer * 0.2) { // small error, take bilinear sample: - - validResult = true; result = cloud_current.SampleLevel(sampler_linear_clamp, uv, 0); } else { // large error, calculate weight and color depending on depth difference with gaussian configuration - half4 color = 0; - half weightSum = 0; + float weightSum = 0; // Note: weights need full precision on Nvidia Vulkan! [unroll] for (int y = -UPSAMPLE_SAMPLE_RADIUS; y <= UPSAMPLE_SAMPLE_RADIUS; y++) @@ -83,25 +78,21 @@ float4 main(float4 pos : SV_Position, float2 uv : TEXCOORD) : SV_Target half4 cloudResult = cloud_current.SampleLevel(sampler_linear_clamp, neighborReprojectionUV, 0); half cloudDepth = cloud_depth_current[neighborReprojectionCoord].g; - -#ifdef GAUSSIAN_UPSAMPLE - half spatialWeight = Gaussian(length(float2(offset)), GAUSSIAN_SIGMA_SPATIAL); - half rangeWeight = Gaussian(abs(tToDepthBuffer - cloudDepth), GAUSSIAN_SIGMA_RANGE); - half weight = spatialWeight * rangeWeight; -#else - half currentDepthDiff = abs(tToDepthBuffer - cloudDepth); - half weight = 1.0 / (currentDepthDiff * UPSAMPLE_TOLERANCE + 1.0); -#endif + float spatialWeight = Gaussian(length(float2(offset)), GAUSSIAN_SIGMA_SPATIAL); + float rangeWeight = Gaussian(abs(tToDepthBuffer - cloudDepth), GAUSSIAN_SIGMA_RANGE); + float weight = spatialWeight * rangeWeight; color += cloudResult * weight; weightSum += weight; } } - validResult = weightSum > 0.0; - result = color / weightSum; + if (weightSum > 0) + { + result = color / weightSum; + } } - return validResult ? result : 0; + return result; }