Merge branch 'master' into reversed_depthbuffer

This commit is contained in:
turanszkij
2017-09-01 23:25:43 +02:00
5 changed files with 65 additions and 42 deletions
+8 -7
View File
@@ -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);
}
+27 -21
View File
@@ -3,18 +3,36 @@
#include "imageHF.hlsli"
#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)
{
@@ -22,18 +40,6 @@ float loadDepth(float2 texCoord)
texture_lineardepth.GetDimensions(dim.x, dim.y);
return texture_lineardepth.Load(int3(dim*texCoord, 0)).r;
}
float4 loadNormal(float2 texCoord)
{
float2 dim;
texture_gbuffer1.GetDimensions(dim.x, dim.y);
return texture_gbuffer1.Load(int3(dim*texCoord, 0));
}
float4 loadVelocity(float2 texCoord)
{
float2 dim;
texture_gbuffer2.GetDimensions(dim.x, dim.y);
return texture_gbuffer2.Load(int3(dim*texCoord, 0));
}
float4 loadMask(float2 texCoord)
{
float2 dim;
+2 -2
View File
@@ -46,7 +46,7 @@ static const float3 AO_SAMPLES[ NUM_SAMPLES ] =
float4 main(VertexToPixelPostProcess input ):SV_Target
{
float3 normal = decode(loadNormal(input.tex.xy).xy);
float3 normal = decode(texture_gbuffer1.SampleLevel(sampler_linear_clamp,input.tex.xy,0).xy);
float3 fres = normalize(xMaskTex.Load(int3((64 * input.tex.xy * 400) % 64, 0)).xyz * 2.0 - 1.0);
@@ -70,7 +70,7 @@ float4 main(VertexToPixelPostProcess input ):SV_Target
float2 newTex = ep.xy + ray.xy;
//occFrag = xNormalMap.SampleLevel(Sampler, newTex,0).xyz;
occFrag = decode(loadNormal(newTex).xy);
occFrag = decode(texture_gbuffer1.SampleLevel(sampler_linear_clamp, newTex, 0).xy);
if(!occFrag.x && !occFrag.y && !occFrag.z)
break;
+27 -11
View File
@@ -1,24 +1,28 @@
// 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"
// This hack can improve bright areas:
#define HDR_CORRECTION
float4 main(VertexToPixelPostProcess PSIn) : SV_TARGET
{
float2 velocity = texture_gbuffer1.Load(uint3(PSIn.pos.xy,0)).zw;
float2 velocity = GetVelocity(PSIn.pos.xy);
float2 prevTC = PSIn.tex + velocity;
float4 neighborhood[9];
neighborhood[0] = xTexture.Load(uint3(PSIn.pos.xy + float2(-1, -1), 0));
neighborhood[1] = xTexture.Load(uint3(PSIn.pos.xy + float2(0, -1), 0));
neighborhood[2] = xTexture.Load(uint3(PSIn.pos.xy + float2(1, -1), 0));
neighborhood[3] = xTexture.Load(uint3(PSIn.pos.xy + float2(-1, 0), 0));
neighborhood[4] = xTexture.Load(uint3(PSIn.pos.xy + float2(0, 0), 0)); // center
neighborhood[5] = xTexture.Load(uint3(PSIn.pos.xy + float2(1, 0), 0));
neighborhood[6] = xTexture.Load(uint3(PSIn.pos.xy + float2(-1, 1), 0));
neighborhood[7] = xTexture.Load(uint3(PSIn.pos.xy + float2(0, 1), 0));
neighborhood[8] = xTexture.Load(uint3(PSIn.pos.xy + float2(1, 1), 0));
neighborhood[0] = xTexture[PSIn.pos.xy + float2(-1, -1)];
neighborhood[1] = xTexture[PSIn.pos.xy + float2(0, -1)];
neighborhood[2] = xTexture[PSIn.pos.xy + float2(1, -1)];
neighborhood[3] = xTexture[PSIn.pos.xy + float2(-1, 0)];
neighborhood[4] = xTexture[PSIn.pos.xy + float2(0, 0)]; // center
neighborhood[5] = xTexture[PSIn.pos.xy + float2(1, 0)];
neighborhood[6] = xTexture[PSIn.pos.xy + float2(-1, 1)];
neighborhood[7] = xTexture[PSIn.pos.xy + float2(0, 1)];
neighborhood[8] = xTexture[PSIn.pos.xy + float2(1, 1)];
float4 neighborhoodMin = neighborhood[0];
float4 neighborhoodMax = neighborhood[0];
[unroll]
@@ -28,18 +32,30 @@ float4 main(VertexToPixelPostProcess PSIn) : SV_TARGET
neighborhoodMax = max(neighborhoodMax, neighborhood[i]);
}
// we cannot avoid the linear filter here because point sampling could sample irrelevant pixels but we try to correct it later:
float4 history = xMaskTex.SampleLevel(sampler_linear_clamp, prevTC, 0);
// simple correction of image signal incoherency (eg. moving shadows or lighting changes):
history = clamp(history, neighborhoodMin, neighborhoodMax);
// our currently rendered frame sample:
float4 current = neighborhood[4];
float blendfactor = saturate(lerp(0.05f, 1.0f, length(velocity) * 10 * length(neighborhoodMax - neighborhoodMin))); // todo
// the linear filtering can cause blurry image, try to account for that:
float subpixelCorrection = frac(max(abs(velocity.x)*g_xWorld_InternalResolution.x, abs(velocity.y)*g_xWorld_InternalResolution.y)) * 0.5f;
// compute a nice blend factor:
float blendfactor = saturate(lerp(0.05f, 0.8f, subpixelCorrection));
// if information can not be found on the screen, revert to aliased image:
blendfactor = any(prevTC - saturate(prevTC)) ? 1.0f : blendfactor;
#ifdef HDR_CORRECTION
history.rgb = tonemap(history.rgb);
current.rgb = tonemap(current.rgb);
#endif
// do the temporal super sampling by linearly accumulating previous samples with the current one:
float4 resolved = float4(lerp(history.rgb, current.rgb, blendfactor), 1);
#ifdef HDR_CORRECTION
+1 -1
View File
@@ -9,7 +9,7 @@ namespace wiVersion
// minor features, major updates
const int minor = 12;
// minor bug fixes, alterations, refactors, updates
const int revision = 6;
const int revision = 8;
long GetVersion()