Fix T51216: SSAO attenuation not being scale invariant.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Fri, 14 Apr 2017 22:02:55 +0000 (00:02 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Fri, 14 Apr 2017 22:43:22 +0000 (00:43 +0200)
Unfortunately this does break compatibility in that the viewport will look a
bit different depending on the settings, but the old behavior was simply not
usable for higher distances.

source/blender/gpu/intern/gpu_compositing.c
source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl

index 964c2b5051ec464637dda648f07faf440f03a3e7..2f2a16f9e1dc3aff76039e61c140f5a0ea727cba 100644 (file)
@@ -798,7 +798,9 @@ bool GPU_fx_do_composite_pass(
                ssao_shader = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_SSAO, is_persp);
                if (ssao_shader) {
                        const GPUSSAOSettings *fx_ssao = fx->settings.ssao;
-                       float ssao_params[4] = {fx_ssao->distance_max, fx_ssao->factor, fx_ssao->attenuation, 0.0f};
+                       /* adjust attenuation to be scale invariant */
+                       float attenuation = fx_ssao->attenuation / (fx_ssao->distance_max * fx_ssao->distance_max);
+                       float ssao_params[4] = {fx_ssao->distance_max, fx_ssao->factor, attenuation, 0.0f};
                        float sample_params[3];
 
                        sample_params[0] = fx->ssao_sample_count_cache;
index 50c8e25516296dfdda9186300fb84af13b5396df..f19ff4ec65ab305e38bbd22bb608046c7f99dc93 100644 (file)
@@ -75,7 +75,7 @@ float calculate_ssao_factor(float depth)
                        float f = dot(dir, normal);
 
                        /* use minor bias here to avoid self shadowing */
-                       if (f > 0.05 * len + 0.0001)
+                       if (f > 0.05 * len)
                                factor += f * 1.0 / (len * (1.0 + len * len * ssao_params.z));
                }
        }