[Bf-blender-cvs] [de27811] viewport_experiments: Correctly downsample circles of confusion and use parallelism to do it more efficient.
Antony Riakiotakis
noreply at git.blender.org
Wed Oct 29 19:41:23 CET 2014
Commit: de27811177870233337649a813d3aad95fe31ff4
Author: Antony Riakiotakis
Date: Wed Oct 29 19:41:12 2014 +0100
Branches: viewport_experiments
https://developer.blender.org/rBde27811177870233337649a813d3aad95fe31ff4
Correctly downsample circles of confusion and use parallelism to do it
more efficient.
===================================================================
M source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl
M source/blender/gpu/shaders/gpu_shader_fx_dof_vert.glsl
M source/blender/gpu/shaders/gpu_shader_fx_lib.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 348f3ff..12d88c8 100644
--- a/source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl
@@ -19,6 +19,11 @@ uniform vec4 viewvecs[3];
varying vec2 color_uv1;
varying vec2 color_uv2;
+varying vec2 depth_uv1;
+varying vec2 depth_uv2;
+varying vec2 depth_uv3;
+varying vec2 depth_uv4;
+
float calculate_dof_coc(in float zdepth)
{
float coc = dof_params.x * abs(1.0 - dof_params.y / zdepth);
@@ -28,9 +33,9 @@ float calculate_dof_coc(in float zdepth)
}
/* near coc only! when distance is nearer than focus plane first term is bigger than one */
-float calculate_near_coc(in float zdepth)
+vec4 calculate_near_coc(in vec4 zdepth)
{
- float coc = dof_params.x * max(dof_params.y / zdepth - 1.0, 0.0);
+ vec4 coc = dof_params.x * max(vec4(dof_params.y) / zdepth - vec4(1.0), vec4(0.0));
/* multiply by 1.0 / sensor size to get the normalized size */
return coc * dof_params.z;
@@ -40,22 +45,58 @@ float calculate_near_coc(in float zdepth)
* lower resolution image */
void first_pass()
{
- float depth = texture2D(depthbuffer, uvcoordsvar.xy).r;
+ vec4 depth;
+ vec4 zdepth;
+ vec4 coc;
+ float final_coc;
/* amount to add to uvs so that they move one row further */
- vec2 offset_row = vec2(0.0, 2.0 * invrendertargetdim.y);
+ 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];
/* heavily blur the image */
vec4 color = texture2D(colorbuffer, color_uv1);
- color += texture2D(colorbuffer, color_uv1 + offset_row);
+ color += texture2D(colorbuffer, color_uv1 + offset_row[1]);
color += texture2D(colorbuffer, color_uv2);
- color += texture2D(colorbuffer, color_uv2 + offset_row);
+ color += texture2D(colorbuffer, color_uv2 + offset_row[1]);
color /= 4.0;
- float zdepth = get_view_space_z_from_depth(viewvecs[0].z, viewvecs[1].z, depth);
- float coc = calculate_near_coc(zdepth);
+ depth.r = texture2D(depthbuffer, depth_uv1).r;
+ depth.g = texture2D(depthbuffer, depth_uv2).r;
+ depth.b = texture2D(depthbuffer, depth_uv3).r;
+ depth.a = texture2D(depthbuffer, depth_uv4).r;
+
+ zdepth = get_view_space_z_from_depth(vec4(viewvecs[0].z), vec4(viewvecs[1].z), depth);
+ coc = calculate_near_coc(zdepth);
+
+ depth.r = texture2D(depthbuffer, depth_uv1 + offset_row[0]).r;
+ depth.g = texture2D(depthbuffer, depth_uv2 + offset_row[0]).r;
+ depth.b = texture2D(depthbuffer, depth_uv3 + offset_row[0]).r;
+ depth.a = texture2D(depthbuffer, depth_uv4 + offset_row[0]).r;
+
+ zdepth = get_view_space_z_from_depth(vec4(viewvecs[0].z), vec4(viewvecs[1].z), depth);
+ coc = max(calculate_near_coc(zdepth), coc);
+
+ depth.r = texture2D(depthbuffer, depth_uv1 + offset_row[1]).r;
+ depth.g = texture2D(depthbuffer, depth_uv2 + offset_row[1]).r;
+ depth.b = texture2D(depthbuffer, depth_uv3 + offset_row[1]).r;
+ depth.a = texture2D(depthbuffer, depth_uv4 + offset_row[1]).r;
+
+ zdepth = get_view_space_z_from_depth(vec4(viewvecs[0].z), vec4(viewvecs[1].z), depth);
+ coc = max(calculate_near_coc(zdepth), coc);
+
+ depth.r = texture2D(depthbuffer, depth_uv1 + offset_row[2]).r;
+ depth.g = texture2D(depthbuffer, depth_uv2 + offset_row[2]).r;
+ depth.b = texture2D(depthbuffer, depth_uv3 + offset_row[2]).r;
+ depth.a = texture2D(depthbuffer, depth_uv4 + offset_row[2]).r;
+
+ zdepth = get_view_space_z_from_depth(vec4(viewvecs[0].z), vec4(viewvecs[1].z), depth);
+ coc = max(calculate_near_coc(zdepth), coc);
- gl_FragColor = vec4(color.rgb, coc);
+ final_coc = max(max(coc.x, coc.y), max(coc.z, coc.w));
+ gl_FragColor = vec4(color.rgb, final_coc);
}
@@ -75,7 +116,7 @@ void third_pass()
{
vec4 color = texture2D(colorbuffer, uvcoordsvar.xy);
- gl_FragColor = vec4(color.a * color.rgb, 1.0);
+ gl_FragColor = vec4(color.a, color.a, color.a, 1.0);
}
void main()
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 1e417db..ba6c4db 100644
--- a/source/blender/gpu/shaders/gpu_shader_fx_dof_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_fx_dof_vert.glsl
@@ -7,6 +7,11 @@ varying vec4 uvcoordsvar;
varying vec2 color_uv1;
varying vec2 color_uv2;
+varying vec2 depth_uv1;
+varying vec2 depth_uv2;
+varying vec2 depth_uv3;
+varying vec2 depth_uv4;
+
//very simple shader for gull screen FX, just pass values on
void vert_generic()
@@ -17,12 +22,15 @@ void vert_generic()
void vert_dof_first_pass()
{
- uvcoordsvar = gl_MultiTexCoord0;
-
/* we offset the texture coordinates by 1.5 pixel, then we reuse that to sample the surrounding pixels */
color_uv1 = gl_MultiTexCoord0.xy + vec2(-1.5, -1.5) * invrendertargetdim;
color_uv2 = gl_MultiTexCoord0.xy + vec2(0.5, -1.5) * invrendertargetdim;
+ depth_uv1 = gl_MultiTexCoord0.xy + vec2(-1.5, -1.5) * invrendertargetdim;;
+ depth_uv2 = gl_MultiTexCoord0.xy + vec2(-0.5, -1.5) * invrendertargetdim;;
+ depth_uv3 = gl_MultiTexCoord0.xy + vec2(0.5, -1.5) * invrendertargetdim;;
+ depth_uv4 = gl_MultiTexCoord0.xy + vec2(1.5, -1.5) * invrendertargetdim;;
+
gl_Position = gl_Vertex;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_fx_lib.glsl b/source/blender/gpu/shaders/gpu_shader_fx_lib.glsl
index bf4a1ea..a138d2e 100644
--- a/source/blender/gpu/shaders/gpu_shader_fx_lib.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_fx_lib.glsl
@@ -21,12 +21,12 @@ vec3 get_view_space_from_depth(in vec2 uvcoords, in vec3 viewvec_origin, in vec3
return zview * (viewvec_origin + vec3(uvcoords, 0.0) * viewvec_diff);
}
-float get_view_space_z_from_depth(in float near, in float range, in float depth)
+vec4 get_view_space_z_from_depth(in vec4 near, in vec4 range, in vec4 depth)
{
- float d = 2.0 * depth - 1.0;
+ vec4 d = 2.0 * depth - vec4(1.0);
/* return positive value, so sign differs! */
- return gl_ProjectionMatrix[3][2] / (d + gl_ProjectionMatrix[2][2]);
+ return vec4(gl_ProjectionMatrix[3][2]) / (d + vec4(gl_ProjectionMatrix[2][2]));
}
#else
@@ -39,7 +39,7 @@ vec3 get_view_space_from_depth(in vec2 uvcoords, in vec3 viewvec_origin, in vec3
return vec3(viewvec_origin + offset * viewvec_diff);
}
-float get_view_space_z_from_depth(in float near, in float range, in float depth)
+vec4 get_view_space_z_from_depth(in vec4 near, in vec4 range, in vec4 depth)
{
return -(near + depth * range);
}
More information about the Bf-blender-cvs
mailing list