From 4fedf79f33ed00c3a1735591263098271a12e2c8 Mon Sep 17 00:00:00 2001 From: turanszkij Date: Wed, 29 Mar 2017 10:33:19 +0200 Subject: [PATCH] temporal AA update --- WickedEngine/skyPS.hlsl | 12 ++++++-- WickedEngine/skyVS.hlsl | 2 ++ WickedEngine/temporalAAResolvePS.hlsl | 44 +++++++++++++++------------ 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/WickedEngine/skyPS.hlsl b/WickedEngine/skyPS.hlsl index 2ebdbcf9f..7c8825f7a 100644 --- a/WickedEngine/skyPS.hlsl +++ b/WickedEngine/skyPS.hlsl @@ -1,12 +1,20 @@ +#include "objectHF.hlsli" #include "skyHF.hlsli" struct VSOut{ float4 pos : SV_POSITION; float3 nor : TEXCOORD0; float4 pos2D : SCREENPOSITION; + float4 pos2DPrev : SCREENPOSITIONPREV; }; -float4 main(VSOut PSIn) : SV_Target +GBUFFEROutputType_Thin main(VSOut input) { - return float4(GetSkyColor(PSIn.nor), 1); + float4 color = float4(GetSkyColor(input.nor), 1); + float2 velocity = ((input.pos2DPrev.xy / input.pos2DPrev.w - g_xFrame_TemporalAAJitterPrev) - (input.pos2D.xy / input.pos2D.w - g_xFrame_TemporalAAJitter)) * float2(0.5f, -0.5f); + + GBUFFEROutputType_Thin Out = (GBUFFEROutputType_Thin)0; + Out.g0 = color; + Out.g1 = float4(0, 0, velocity); + return Out; } diff --git a/WickedEngine/skyVS.hlsl b/WickedEngine/skyVS.hlsl index 0080348bb..8b0cfa602 100644 --- a/WickedEngine/skyVS.hlsl +++ b/WickedEngine/skyVS.hlsl @@ -5,6 +5,7 @@ struct VSOut{ float4 pos : SV_POSITION; float3 nor : TEXCOORD0; float4 pos2D : SCREENPOSITION; + float4 pos2DPrev : SCREENPOSITIONPREV; }; VSOut main(uint vid : SV_VERTEXID) @@ -12,5 +13,6 @@ VSOut main(uint vid : SV_VERTEXID) VSOut Out = (VSOut)0; Out.pos = Out.pos2D = mul(float4(ICOSPHERE[vid].xyz, 0), g_xCamera_VP); Out.nor=ICOSPHERE[vid].xyz; + Out.pos2DPrev = mul(float4(ICOSPHERE[vid].xyz, 0), g_xFrame_MainCamera_PrevVP); return Out; } diff --git a/WickedEngine/temporalAAResolvePS.hlsl b/WickedEngine/temporalAAResolvePS.hlsl index d3110879f..806d8995a 100644 --- a/WickedEngine/temporalAAResolvePS.hlsl +++ b/WickedEngine/temporalAAResolvePS.hlsl @@ -4,28 +4,32 @@ float4 main(VertexToPixelPostProcess PSIn) : SV_TARGET { float2 velocity = texture_gbuffer1.Load(uint3(PSIn.pos.xy,0)).zw; - //float4 neighborhood[9]; - //neighborhood[0] = xMaskTex.Load(uint3(PSIn.pos.xy + uint2(-1, -1), 0)); - //neighborhood[1] = xMaskTex.Load(uint3(PSIn.pos.xy + uint2(0, -1), 0)); - //neighborhood[2] = xMaskTex.Load(uint3(PSIn.pos.xy + uint2(1, -1), 0)); - //neighborhood[3] = xMaskTex.Load(uint3(PSIn.pos.xy + uint2(-1, 0), 0)); - //neighborhood[4] = xMaskTex.Load(uint3(PSIn.pos.xy + uint2(0, 0), 0)); // center - //neighborhood[5] = xMaskTex.Load(uint3(PSIn.pos.xy + uint2(1, 0), 0)); - //neighborhood[6] = xMaskTex.Load(uint3(PSIn.pos.xy + uint2(-1, 1), 0)); - //neighborhood[7] = xMaskTex.Load(uint3(PSIn.pos.xy + uint2(0, 1), 0)); - //neighborhood[8] = xMaskTex.Load(uint3(PSIn.pos.xy + uint2(1, 1), 0)); - //float4 neighborhoodMin = neighborhood[0]; - //float4 neighborhoodMax = neighborhood[0]; - //[unroll] - //for (uint i = 1; i < 9; ++i) - //{ - // neighborhoodMin = min(neighborhoodMin, neighborhood[i]); - // neighborhoodMax = max(neighborhoodMax, neighborhood[i]); - //} + float2 prevTC = PSIn.tex + velocity; + float2 dim; + xMaskTex.GetDimensions(dim.x, dim.y); + float2 texelSize = 1.0f / dim; + float4 neighborhood[9]; + neighborhood[0] = xMaskTex.SampleLevel(sampler_linear_clamp, prevTC + texelSize * uint2(-1, -1), 0); + neighborhood[1] = xMaskTex.SampleLevel(sampler_linear_clamp, prevTC + texelSize * uint2(0, -1), 0); + neighborhood[2] = xMaskTex.SampleLevel(sampler_linear_clamp, prevTC + texelSize * uint2(1, -1), 0); + neighborhood[3] = xMaskTex.SampleLevel(sampler_linear_clamp, prevTC + texelSize * uint2(-1, 0), 0); + neighborhood[4] = xMaskTex.SampleLevel(sampler_linear_clamp, prevTC, 0); // center + neighborhood[5] = xMaskTex.SampleLevel(sampler_linear_clamp, prevTC + texelSize * uint2(1, 0), 0); + neighborhood[6] = xMaskTex.SampleLevel(sampler_linear_clamp, prevTC + texelSize * uint2(-1, 1), 0); + neighborhood[7] = xMaskTex.SampleLevel(sampler_linear_clamp, prevTC + texelSize * uint2(0, 1), 0); + neighborhood[8] = xMaskTex.SampleLevel(sampler_linear_clamp, prevTC + texelSize * uint2(1, 1), 0); + float4 neighborhoodMin = neighborhood[0]; + float4 neighborhoodMax = neighborhood[0]; + [unroll] + for (uint i = 1; i < 9; ++i) + { + neighborhoodMin = min(neighborhoodMin, neighborhood[i]); + neighborhoodMax = max(neighborhoodMax, neighborhood[i]); + } + float4 history = clamp(neighborhood[4], neighborhoodMin, neighborhoodMax); - //float4 history = clamp(neighborhood[4], neighborhoodMin, neighborhoodMax); //float4 history = xMaskTex.Load(uint3(PSIn.pos.xy, 0)); - float4 history = xMaskTex.SampleLevel(sampler_linear_clamp, PSIn.tex + velocity, 0); + //float4 history = xMaskTex.SampleLevel(sampler_linear_clamp, PSIn.tex + velocity, 0); float4 current = xTexture.Load(uint3(PSIn.pos.xy,0));