From f5e1d4f462af56e54dad1b8b67df4d814c401704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Sat, 19 Nov 2022 14:57:11 +0100 Subject: [PATCH] visibility buffer shader fixes --- WickedEngine/shaders/visibility_resolveCS.hlsl | 5 ++--- WickedEngine/shaders/visibility_velocityCS.hlsl | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/WickedEngine/shaders/visibility_resolveCS.hlsl b/WickedEngine/shaders/visibility_resolveCS.hlsl index 3725af3e8..9fac81cce 100644 --- a/WickedEngine/shaders/visibility_resolveCS.hlsl +++ b/WickedEngine/shaders/visibility_resolveCS.hlsl @@ -77,9 +77,8 @@ void main(uint2 Gid : SV_GroupID, uint groupIndex : SV_GroupIndex) if (surface.load(prim, ray.Origin, ray.Direction)) { float4 tmp = mul(GetCamera().view_projection, float4(surface.P, 1)); - tmp.xyz /= tmp.w; - depth = tmp.z; - depth = saturate(depth); // this avoids NAN + tmp.xyz /= max(0.0001, tmp.w); // max: avoid nan + depth = saturate(tmp.z); // saturate: avoid blown up values bin = surface.material.shaderType; } diff --git a/WickedEngine/shaders/visibility_velocityCS.hlsl b/WickedEngine/shaders/visibility_velocityCS.hlsl index 0434a76be..4a27ad6c3 100644 --- a/WickedEngine/shaders/visibility_velocityCS.hlsl +++ b/WickedEngine/shaders/visibility_velocityCS.hlsl @@ -39,7 +39,8 @@ void main(uint2 DTid : SV_DispatchThreadID) float2 pos2D = clipspace; float4 pos2DPrev = mul(GetCamera().previous_view_projection, float4(pre, 1)); - pos2DPrev.xy /= pos2DPrev.w; + pos2DPrev.xy /= max(0.0001, pos2DPrev.w); // max: avoid nan + pos2DPrev.xy = clamp(pos2DPrev.xy, -1, 1); // clamp: avoid blown up values float2 velocity = ((pos2DPrev.xy - GetCamera().temporalaa_jitter_prev) - (pos2D.xy - GetCamera().temporalaa_jitter)) * float2(0.5, -0.5); output_velocity[pixel] = velocity;