- rewrite depthblur.fp to workaround what seemed to be a bug in the NVidia driver

This commit is contained in:
Magnus Norddahl 2019-04-16 16:17:23 +02:00
parent 5913f72c9f
commit 15dae4cfe6
3 changed files with 35 additions and 36 deletions

View File

@ -697,6 +697,10 @@ void PPAmbientOcclusion::Render(PPRenderState *renderstate, float m5, int sceneW
ssaoUniforms.Scale = sceneScale;
ssaoUniforms.Offset = sceneOffset;
DepthBlurUniforms blurUniforms;
blurUniforms.BlurSharpness = blurSharpness;
blurUniforms.PowExponent = gl_ssao_exponent;
AmbientCombineUniforms combineUniforms;
combineUniforms.SampleCount = gl_multisample;
combineUniforms.Scale = screen->SceneScale();
@ -735,11 +739,6 @@ void PPAmbientOcclusion::Render(PPRenderState *renderstate, float m5, int sceneW
// Blur SSAO texture
if (gl_ssao_debug < 2)
{
DepthBlurUniforms blurUniforms;
blurUniforms.BlurSharpness = blurSharpness;
blurUniforms.PowExponent = gl_ssao_exponent;
blurUniforms.InvFullResolution = { 1.0f / AmbientWidth, 0.0f };
renderstate->Clear();
renderstate->Shader = &BlurHorizontal;
renderstate->Uniforms.Set(blurUniforms);
@ -749,8 +748,6 @@ void PPAmbientOcclusion::Render(PPRenderState *renderstate, float m5, int sceneW
renderstate->SetNoBlend();
renderstate->Draw();
blurUniforms.InvFullResolution = { 0.0f, 1.0f / AmbientHeight };
renderstate->Clear();
renderstate->Shader = &BlurVertical;
renderstate->Uniforms.Set(blurUniforms);

View File

@ -634,7 +634,7 @@ struct DepthBlurUniforms
{
float BlurSharpness;
float PowExponent;
FVector2 InvFullResolution;
float Padding0, Padding1;
static std::vector<UniformFieldDesc> Desc()
{
@ -642,7 +642,8 @@ struct DepthBlurUniforms
{
{ "BlurSharpness", UniformType::Float, offsetof(DepthBlurUniforms, BlurSharpness) },
{ "PowExponent", UniformType::Float, offsetof(DepthBlurUniforms, PowExponent) },
{ "InvFullResolution", UniformType::Vec2, offsetof(DepthBlurUniforms, InvFullResolution) }
{ "Padding0", UniformType::Float, offsetof(DepthBlurUniforms, Padding0) },
{ "Padding1", UniformType::Float, offsetof(DepthBlurUniforms, Padding1) }
};
}
};

View File

@ -6,42 +6,43 @@ layout(binding=0) uniform sampler2D AODepthTexture;
#define KERNEL_RADIUS 3.0
void main()
void AddSample(vec2 blurSample, float r, float centerDepth, inout float totalAO, inout float totalW)
{
const float blurSigma = KERNEL_RADIUS * 0.5;
const float blurFalloff = 1.0 / (2.0 * blurSigma * blurSigma);
vec2 centerSample = texture(AODepthTexture, TexCoord).xy;
float ao = blurSample.x;
float z = blurSample.y;
float deltaZ = (z - centerDepth) * BlurSharpness;
float w = exp2(-r * r * blurFalloff - deltaZ * deltaZ);
totalAO += w * ao;
totalW += w;
}
void main()
{
vec2 centerSample = textureOffset(AODepthTexture, TexCoord, ivec2( 0, 0)).xy;
float centerDepth = centerSample.y;
float totalAO = centerSample.x;
float totalW = 1.0;
for (float r = 1.0; r <= KERNEL_RADIUS; r += 1.0)
{
vec4 blurSample = texture(AODepthTexture, TexCoord - InvFullResolution * r);
float ao = blurSample.x;
float z = blurSample.y;
float deltaZ = (z - centerDepth) * BlurSharpness;
float w = exp2(-r * r * blurFalloff - deltaZ * deltaZ);
totalAO += w * ao;
totalW += w;
}
for (float r = 1.0; r <= KERNEL_RADIUS; r += 1.0)
{
vec4 blurSample = texture(AODepthTexture, InvFullResolution * r + TexCoord);
float ao = blurSample.x;
float z = blurSample.y;
float deltaZ = (z - centerDepth) * BlurSharpness;
float w = exp2(-r * r * blurFalloff - deltaZ * deltaZ);
totalAO += w * ao;
totalW += w;
}
#if defined(BLUR_HORIZONTAL)
AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(-3, 0)).xy, 3.0, centerDepth, totalAO, totalW);
AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(-2, 0)).xy, 2.0, centerDepth, totalAO, totalW);
AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(-1, 0)).xy, 1.0, centerDepth, totalAO, totalW);
AddSample(textureOffset(AODepthTexture, TexCoord, ivec2( 1, 0)).xy, 1.0, centerDepth, totalAO, totalW);
AddSample(textureOffset(AODepthTexture, TexCoord, ivec2( 2, 0)).xy, 2.0, centerDepth, totalAO, totalW);
AddSample(textureOffset(AODepthTexture, TexCoord, ivec2( 3, 0)).xy, 3.0, centerDepth, totalAO, totalW);
#else
AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(0, -3)).xy, 3.0, centerDepth, totalAO, totalW);
AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(0, -2)).xy, 2.0, centerDepth, totalAO, totalW);
AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(0, -1)).xy, 1.0, centerDepth, totalAO, totalW);
AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(0, 1)).xy, 1.0, centerDepth, totalAO, totalW);
AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(0, 2)).xy, 2.0, centerDepth, totalAO, totalW);
AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(0, 3)).xy, 3.0, centerDepth, totalAO, totalW);
#endif
float fragAO = totalAO / totalW;