From bbe1b54818d7bb349ddf63efbcb18347a78cf714 Mon Sep 17 00:00:00 2001 From: Antony Riakiotakis Date: Mon, 16 Feb 2015 14:42:36 +0100 Subject: [PATCH] Fix T43689, viewport compositing does not respect alpha settings for background. For SSAO supporting this is no problem, for DOF we would ideally do blurred alpha, but alpha channel in blurred buffers is occupied by coc field, so use original color alpha instead. It's not entirely correct but it's better than nothing. --- source/blender/gpu/intern/gpu_compositing.c | 8 +++++++- source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl | 4 +++- source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl | 5 +++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/source/blender/gpu/intern/gpu_compositing.c b/source/blender/gpu/intern/gpu_compositing.c index b423c14bd4b..cf288070126 100644 --- a/source/blender/gpu/intern/gpu_compositing.c +++ b/source/blender/gpu/intern/gpu_compositing.c @@ -257,7 +257,7 @@ bool GPU_fx_compositor_initialize_passes( GPUFX *fx, const rcti *rect, const rcti *scissor_rect, const GPUFXSettings *fx_settings) { - int w = BLI_rcti_size_x(rect) + 1, h = BLI_rcti_size_y(rect) + 1; + int w = BLI_rcti_size_x(rect), h = BLI_rcti_size_y(rect); char err_out[256]; int num_passes = 0; char fx_flag = fx_settings->fx_flag; @@ -282,6 +282,12 @@ bool GPU_fx_compositor_initialize_passes( return false; } + /* scissor is missing when drawing offscreen, in that case, dimensions match exactly. In opposite case + * add one to match viewport dimensions */ + if (!scissor_rect) { + w++, h++; + } + fx->num_passes = 0; /* dof really needs a ping-pong buffer to work */ if (fx_flag & GPU_FX_FLAG_DOF) diff --git a/source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl b/source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl index d52ab2243fe..e9dab04de5d 100644 --- a/source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl @@ -186,7 +186,9 @@ void fifth_pass() vec4 color = factors.x * color_orig + factors.y * smallblurred + factors.z * mediumblurred + factors.w * highblurred; color /= dot(factors, vec4(1.0)); - gl_FragColor = vec4(color.rgb, 1.0); + /* using original color is not correct, but use that for now because alpha of + * blurred buffers uses CoC instead */ + gl_FragColor = vec4(color.rgb, color_orig.a); } diff --git a/source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl b/source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl index b33fda92a46..86e10af8c0d 100644 --- a/source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl @@ -77,6 +77,7 @@ float calculate_ssao_factor(float depth) void main() { float depth = texture2D(depthbuffer, uvcoordsvar.xy).r; - vec4 color = mix(texture2D(colorbuffer, uvcoordsvar.xy), ssao_color, calculate_ssao_factor(depth)); - gl_FragColor = vec4(color.rgb, 1.0); + vec4 scene_col = texture2D(colorbuffer, uvcoordsvar.xy); + vec3 final_color = mix(scene_col.rgb, ssao_color.rgb, calculate_ssao_factor(depth)); + gl_FragColor = vec4(final_color.rgb, scene_col.a); }