From 4e26e376f4dd2f1b785936dc2b0ad314ff1afabd Mon Sep 17 00:00:00 2001 From: turanszkij Date: Mon, 28 Aug 2017 20:32:28 +0200 Subject: [PATCH] updated motion blur --- WickedEngine/motionBlurPS.hlsl | 15 ++++++------ WickedEngine/postProcessHF.hlsli | 33 ++++++++++++++++++++----- WickedEngine/temporalAAResolvePS.hlsl | 35 +++------------------------ WickedEngine/wiVersion.cpp | 2 +- 4 files changed, 39 insertions(+), 46 deletions(-) diff --git a/WickedEngine/motionBlurPS.hlsl b/WickedEngine/motionBlurPS.hlsl index 9591ff97e..f86800458 100644 --- a/WickedEngine/motionBlurPS.hlsl +++ b/WickedEngine/motionBlurPS.hlsl @@ -1,21 +1,22 @@ +#define DILATE_VELOCITY + #include "postProcessHF.hlsli" #include "reconstructPositionHF.hlsli" + float4 main(VertexToPixelPostProcess PSIn) : SV_TARGET { - float3 color = float3(0,0,0); - float numSampling = 0.0f; + float3 color = 0; + float numSampling = 1.0f; - float2 vel = texture_gbuffer1.Load(uint3(PSIn.pos.xy, 0)).zw; + float2 vel = GetVelocity(PSIn.pos.xy); vel *= 0.025f; - numSampling++; - [unroll] for(float i=-7.5f;i<=7.5f;i+=1.0f){ - color.rgb += xTexture.SampleLevel(Sampler,saturate(PSIn.tex+vel*i*0.5f),0).rgb; + color.rgb += xTexture.SampleLevel(sampler_linear_clamp,saturate(PSIn.tex+vel*i*0.5f),0).rgb; numSampling++; } - return float4(color/numSampling,1); + return float4(color / numSampling, 1); } \ No newline at end of file diff --git a/WickedEngine/postProcessHF.hlsli b/WickedEngine/postProcessHF.hlsli index 74824e7c9..2fecf13a0 100644 --- a/WickedEngine/postProcessHF.hlsli +++ b/WickedEngine/postProcessHF.hlsli @@ -5,13 +5,34 @@ #include "packHF.hlsli" #include "depthConvertHF.hlsli" -/*inline float getDepth(float4 c) + +float2 GetVelocity(in int2 pixel) { - float z_b = c.x; - float z_n = 2.0 * z_b - 1.0; - float lin = 2.0 * zNearP * zFarP / (zFarP + zNearP - z_n * (zFarP - zNearP)); - return lin*0.01f; -}*/ +#ifdef DILATE_VELOCITY + float bestDepth = g_xFrame_MainCamera_ZFarP; + int2 bestPixel = int2(0, 0); + + [unroll] + for (int i = -1; i <= 1; ++i) + { + [unroll] + for (int j = -1; j <= 1; ++j) + { + float depth = texture_lineardepth[pixel]; + [flatten] + if (depth < bestDepth) + { + bestDepth = depth; + bestPixel = pixel + int2(i, j); + } + } + } + + return texture_gbuffer1[bestPixel].zw; +#else + return texture_gbuffer1[pixel].zw; +#endif // DILATE_VELOCITY +} float loadDepth(float2 texCoord) { diff --git a/WickedEngine/temporalAAResolvePS.hlsl b/WickedEngine/temporalAAResolvePS.hlsl index ac572cb34..b09ea98a0 100644 --- a/WickedEngine/temporalAAResolvePS.hlsl +++ b/WickedEngine/temporalAAResolvePS.hlsl @@ -1,3 +1,6 @@ +// This can retrieve better velocity vectors so moving objects could be better anti aliased: +#define DILATE_VELOCITY + #include "postProcessHF.hlsli" #include "reconstructPositionHF.hlsli" #include "tonemapHF.hlsli" @@ -5,38 +8,6 @@ // This hack can improve bright areas: #define HDR_CORRECTION -// This can retrieve better velocity vectors so moving objects could be better anti aliased: -#define DILATE_VELOCITY - - -float2 GetVelocity(in int2 pixel) -{ -#ifdef DILATE_VELOCITY - float bestDepth = g_xFrame_MainCamera_ZFarP; - int2 bestPixel = int2(0, 0); - - [unroll] - for (int i = -1; i <= 1; ++i) - { - [unroll] - for (int j = -1; j <= 1; ++j) - { - float depth = texture_lineardepth[pixel]; - [flatten] - if (depth < bestDepth) - { - bestDepth = depth; - bestPixel = pixel + int2(i, j); - } - } - } - - return texture_gbuffer1[bestPixel].zw; -#else - return texture_gbuffer1[pixel].zw; -#endif // DILATE_VELOCITY -} - float4 main(VertexToPixelPostProcess PSIn) : SV_TARGET { float2 velocity = GetVelocity(PSIn.pos.xy); diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 45849c893..d7d778425 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 12; // minor bug fixes, alterations, refactors, updates - const int revision = 7; + const int revision = 8; long GetVersion()