Commit: 7798ecd74338c2549835f3ee4ad3220f423a5a50 Author: Antony Riakiotakis Date: Mon Nov 3 14:06:47 2014 +0100 Branches: viewport_experiments https://developer.blender.org/rB7798ecd74338c2549835f3ee4ad3220f423a5a50
Add another level of small blur to bridge between no/medium blurring. Algorithm used is now a full implementation of "Practical Post-Process depth of field", presented here [1], with a few modifications as to how circle of confusion is applied at the final pass. [1] http://http.developer.nvidia.com/GPUGems3/gpugems3_ch28.html =================================================================== M source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl M source/blender/gpu/shaders/gpu_shader_fx_dof_vert.glsl =================================================================== 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 ad4d666..385d18d 100644 --- a/source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl @@ -58,8 +58,8 @@ void first_pass() /* amount to add to uvs so that they move one row further */ vec2 offset_row[3]; offset_row[0] = vec2(0.0, invrendertargetdim.y); - offset_row[1] = 2 * offset_row[0]; - offset_row[2] = 3 * offset_row[0]; + offset_row[1] = 2.0 * offset_row[0]; + offset_row[2] = 3.0 * offset_row[0]; /* heavily blur the image */ vec4 color = texture2D(colorbuffer, color_uv1); @@ -140,7 +140,21 @@ void fourth_pass() color += texture2D(colorbuffer, uvcoordsvar.xw); color += texture2D(colorbuffer, uvcoordsvar.yw); - gl_FragColor = color/4.0; + gl_FragColor = color / 4.0; +} + +vec4 small_sample_blur(in sampler2D colorbuffer, in vec2 uv, in vec4 color) +{ + float weight = 1.0/ 17.0; + vec4 result = weight * color; + weight *= 4.0; + + result += weight * texture2D(colorbuffer, uv + color_uv1.xy); + result += weight * texture2D(colorbuffer, uv - color_uv1.xy); + result += weight * texture2D(colorbuffer, uv + color_uv2.yx); + result += weight * texture2D(colorbuffer, uv - color_uv2.yx); + + return result; } @@ -151,6 +165,7 @@ void fifth_pass() vec4 color_orig = texture2D(colorbuffer, uvcoordsvar.xy); vec4 highblurred = texture2D(blurredcolorbuffer, uvcoordsvar.xy); vec4 mediumblurred = texture2D(mblurredcolorbuffer, uvcoordsvar.xy); + vec4 smallblurred = small_sample_blur(colorbuffer, uvcoordsvar.xy, color_orig); float depth = texture2D(depthbuffer, uvcoordsvar.xy).r; float zdepth = get_view_space_z_from_depth(vec4(viewvecs[0].z), vec4(viewvecs[1].z), vec4(depth)).r; @@ -159,13 +174,17 @@ void fifth_pass() /* calculate final coc here */ float coc = max(max(coc_far, mediumblurred.a), 0.0); - factors.x = 1.0 - clamp(2.0 * coc, 0.0, 1.0); - factors.y = 1.0 - clamp(abs(2.0 * (coc - 0.5)), 0.0, 1.0); - factors.z = clamp(5.0 * (coc - 0.5), 0.0, 1.0); + float width = 2.5; + float radius = 0.2; + + factors.x = 1.0 - clamp(width * coc, 0.0, 1.0); + factors.y = 1.0 - clamp(abs(width * (coc - 2.0 * radius)), 0.0, 1.0); + factors.z = 1.0 - clamp(abs(width * (coc - 3.0 * radius)), 0.0, 1.0); + factors.w = 1.0 - clamp(abs(width * (coc - 4.0 * radius)), 0.0, 1.0); /* blend! */ - vec4 color = factors.x * color_orig + factors.y * mediumblurred + factors.z * highblurred; + vec4 color = factors.x * color_orig + factors.y * smallblurred + factors.z * mediumblurred + factors.w * highblurred; - color /= (factors.x + factors.y + factors.z); + color /= dot(factors, vec4(1.0)); gl_FragColor = vec4(color.rgb, 1.0); } diff --git a/source/blender/gpu/shaders/gpu_shader_fx_dof_vert.glsl b/source/blender/gpu/shaders/gpu_shader_fx_dof_vert.glsl index 62063ba..61055c7 100644 --- a/source/blender/gpu/shaders/gpu_shader_fx_dof_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_fx_dof_vert.glsl @@ -42,12 +42,23 @@ void vert_dof_fourth_pass() gl_Position = gl_Vertex; } +void vert_dof_fifth_pass() +{ + vec4 halfpixel = vec4(-0.5, 0.5, -0.5, 0.5); + color_uv1 = vec2(0.5, 1.5) * invrendertargetdim; + + uvcoordsvar = gl_MultiTexCoord0; + gl_Position = gl_Vertex; +} + void main() { #ifdef FIRST_PASS vert_dof_first_pass(); #elif defined(FOURTH_PASS) vert_dof_fourth_pass(); +#elif defined(FIFTH_PASS) + vert_dof_fifth_pass(); #else vert_generic(); #endif _______________________________________________ Bf-blender-cvs mailing list [email protected] http://lists.blender.org/mailman/listinfo/bf-blender-cvs
