[Bf-blender-cvs] [6484056] viewport_experiments: Second pass, blurs the downsampled buffer once.
Antony Riakiotakis
noreply at git.blender.org
Wed Oct 29 18:31:29 CET 2014
Commit: 6484056cc1bd23e632aff6c81c92d6cbbb6800a2
Author: Antony Riakiotakis
Date: Wed Oct 29 18:31:15 2014 +0100
Branches: viewport_experiments
https://developer.blender.org/rB6484056cc1bd23e632aff6c81c92d6cbbb6800a2
Second pass, blurs the downsampled buffer once.
===================================================================
M source/blender/gpu/intern/gpu_compositing.c
M source/blender/gpu/intern/gpu_extensions.c
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/intern/gpu_compositing.c b/source/blender/gpu/intern/gpu_compositing.c
index a73ce17..27cdfdd 100644
--- a/source/blender/gpu/intern/gpu_compositing.c
+++ b/source/blender/gpu/intern/gpu_compositing.c
@@ -486,6 +486,7 @@ bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D *v3d, struct RegionView3D
dof_shader_pass1 = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_ONE, rv3d->is_persp);
dof_shader_pass2 = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_TWO, rv3d->is_persp);
+ dof_shader_pass3 = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_THREE, rv3d->is_persp);
/* error occured, restore framebuffers and return */
if (!dof_shader_pass1 || !(dof_shader_pass2)) {
@@ -550,14 +551,48 @@ bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D *v3d, struct RegionView3D
/* second pass */
{
int near_coc_downsampled;
+ int invrendertargetdim_uniform;
+ float invrendertargetdim[2] = {1.0f / GPU_texture_opengl_width(fx->dof_near_coc_blurred_buffer),
+ 1.0f / GPU_texture_opengl_height(fx->dof_near_coc_blurred_buffer)};
near_coc_downsampled = GPU_shader_get_uniform(dof_shader_pass2, "colorbuffer");
+ invrendertargetdim_uniform = GPU_shader_get_uniform(dof_shader_pass2, "invrendertargetdim");
GPU_shader_bind(dof_shader_pass2);
GPU_texture_bind(fx->dof_near_coc_buffer, numslots++);
GPU_shader_uniform_texture(dof_shader_pass2, near_coc_downsampled, fx->dof_near_coc_buffer);
+ GPU_shader_uniform_vector(dof_shader_pass2, invrendertargetdim_uniform, 2, 1, invrendertargetdim);
+ /* if this is the last pass, prepare for rendering on the frambuffer */
+ GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_blurred_buffer, NULL);
+ GPU_framebuffer_texture_bind(fx->gbuffer, fx->dof_near_coc_blurred_buffer,
+ GPU_texture_opengl_width(fx->dof_near_coc_blurred_buffer), GPU_texture_opengl_height(fx->dof_near_coc_blurred_buffer));
+
+ glDisable(GL_DEPTH_TEST);
+ glDrawArrays(GL_QUADS, 0, 4);
+ /* disable bindings */
+ GPU_texture_unbind(fx->dof_near_coc_buffer);
+ GPU_depth_texture_mode(fx->depth_buffer, true, false);
+ GPU_texture_unbind(fx->depth_buffer);
+
+ GPU_framebuffer_texture_unbind(fx->gbuffer, fx->dof_near_coc_blurred_buffer);
+ GPU_framebuffer_texture_detach(fx->gbuffer, fx->dof_near_coc_blurred_buffer);
+
+ SWAP(GPUTexture *, target, src);
+ numslots = 0;
+ }
+
+ /* third pass */
+ {
+ int near_coc_downsampled;
+
+ near_coc_downsampled = GPU_shader_get_uniform(dof_shader_pass3, "colorbuffer");
+
+ GPU_shader_bind(dof_shader_pass3);
+
+ GPU_texture_bind(fx->dof_near_coc_blurred_buffer, numslots++);
+ GPU_shader_uniform_texture(dof_shader_pass3, near_coc_downsampled, fx->dof_near_coc_blurred_buffer);
/* if this is the last pass, prepare for rendering on the frambuffer */
if (passes_left-- == 1) {
@@ -571,7 +606,7 @@ bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D *v3d, struct RegionView3D
glDisable(GL_DEPTH_TEST);
glDrawArrays(GL_QUADS, 0, 4);
/* disable bindings */
- GPU_texture_unbind(src);
+ GPU_texture_unbind(fx->dof_near_coc_blurred_buffer);
GPU_depth_texture_mode(fx->depth_buffer, true, false);
GPU_texture_unbind(fx->depth_buffer);
diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c
index 489b80f..ff13f84 100644
--- a/source/blender/gpu/intern/gpu_extensions.c
+++ b/source/blender/gpu/intern/gpu_extensions.c
@@ -1593,6 +1593,10 @@ GPUShader *GPU_shader_get_builtin_fx_shader(int effects, bool persp)
strcat(defines, "#define SECOND_PASS\n");
GG.shaders.fx_shaders[offset] = GPU_shader_create(datatoc_gpu_shader_fx_dof_vert_glsl, datatoc_gpu_shader_fx_dof_frag_glsl, datatoc_gpu_shader_fx_lib_glsl, defines);
}
+ else if (effects == GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_THREE) {
+ strcat(defines, "#define THIRD_PASS\n");
+ GG.shaders.fx_shaders[offset] = GPU_shader_create(datatoc_gpu_shader_fx_dof_vert_glsl, datatoc_gpu_shader_fx_dof_frag_glsl, datatoc_gpu_shader_fx_lib_glsl, defines);
+ }
}
return GG.shaders.fx_shaders[offset];
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 c30312d..348f3ff 100644
--- a/source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl
@@ -59,15 +59,25 @@ void first_pass()
}
-/* second pass, just visualize the first pass contents */
+/* second pass, blur the near coc texture and calculate the coc */
void second_pass()
{
+ vec4 color = texture2D(colorbuffer, uvcoordsvar.xz);
+ color += texture2D(colorbuffer, uvcoordsvar.yz);
+ color += texture2D(colorbuffer, uvcoordsvar.xw);
+ color += texture2D(colorbuffer, uvcoordsvar.yw);
+
+ gl_FragColor = color/4.0;
+}
+
+/* second pass, just visualize the first pass contents */
+void third_pass()
+{
vec4 color = texture2D(colorbuffer, uvcoordsvar.xy);
gl_FragColor = vec4(color.a * color.rgb, 1.0);
}
-
void main()
{
#ifdef FIRST_PASS
@@ -75,6 +85,7 @@ void main()
#elif defined(SECOND_PASS)
second_pass();
#elif defined(THIRD_PASS)
+ third_pass();
#elif defined(FOURTH_PASS)
#endif
}
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 d4e9f04..1e417db 100644
--- a/source/blender/gpu/shaders/gpu_shader_fx_dof_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_fx_dof_vert.glsl
@@ -26,13 +26,22 @@ void vert_dof_first_pass()
gl_Position = gl_Vertex;
}
+void vert_dof_second_pass()
+{
+ vec4 halfpixel = vec4(-0.5, 0.5, -0.5, 0.5);
+ uvcoordsvar = gl_MultiTexCoord0.xxyy + halfpixel * vec4(invrendertargetdim.x, invrendertargetdim.x, invrendertargetdim.y, invrendertargetdim.y);
+
+ gl_Position = gl_Vertex;
+}
+
void main()
{
#ifdef FIRST_PASS
vert_dof_first_pass();
#elif defined(SECOND_PASS)
- vert_generic();
+ vert_dof_second_pass();
#elif defined(THIRD_PASS)
+ vert_generic();
#elif defined(FOURTH_PASS)
#else
vert_generic();
More information about the Bf-blender-cvs
mailing list