Commit: 5efa0e03b52175163bb58353df304c40bd769c70
Author: Antony Riakiotakis
Date:   Sun Oct 26 15:43:46 2014 +0100
Branches: viewport_experiments
https://developer.blender.org/rB5efa0e03b52175163bb58353df304c40bd769c70

Add separate file for DOF effect and cleanup the parameter passing a little.

===================================================================

M       SConstruct
M       source/blender/gpu/CMakeLists.txt
M       source/blender/gpu/intern/gpu_compositing.c
M       source/blender/gpu/intern/gpu_extensions.c
A       source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl
M       source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl

===================================================================

diff --git a/SConstruct b/SConstruct
index c45dcf8..e53b6d9 100644
--- a/SConstruct
+++ b/SConstruct
@@ -755,6 +755,7 @@ if B.targets != ['cudakernels']:
     
data_to_c_simple("source/blender/gpu/shaders/gpu_shader_vsm_store_frag.glsl")
     
data_to_c_simple("source/blender/gpu/shaders/gpu_shader_vsm_store_vert.glsl")
     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl")
+    data_to_c_simple("source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl")
     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_fx_vert.glsl")
     data_to_c_simple("intern/opencolorio/gpu_shader_display_transform.glsl")
 
diff --git a/source/blender/gpu/CMakeLists.txt 
b/source/blender/gpu/CMakeLists.txt
index 7091ef9..d2551b0 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -58,6 +58,7 @@ set(SRC
        intern/gpu_renderer.c
 
        shaders/gpu_shader_fx_ssao_frag.glsl
+       shaders/gpu_shader_fx_dof_frag.glsl
        shaders/gpu_shader_fx_vert.glsl
        shaders/gpu_shader_material.glsl
        shaders/gpu_shader_sep_gaussian_blur_frag.glsl
@@ -92,6 +93,7 @@ data_to_c_simple(shaders/gpu_shader_vsm_store_frag.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_vsm_store_vert.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_fx_vert.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_fx_ssao_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_fx_dof_frag.glsl SRC)
 
 if(WITH_GAMEENGINE)
        add_definitions(-DWITH_GAMEENGINE)
diff --git a/source/blender/gpu/intern/gpu_compositing.c 
b/source/blender/gpu/intern/gpu_compositing.c
index a55f323..9d211b1 100644
--- a/source/blender/gpu/intern/gpu_compositing.c
+++ b/source/blender/gpu/intern/gpu_compositing.c
@@ -231,8 +231,11 @@ bool GPU_initialize_fx_passes(GPUFX *fx, rcti *rect, rcti 
*scissor_rect, int fxf
 
 bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D *v3d, struct 
RegionView3D *rv3d) {
        GPUShader *fx_shader;
-       int numslots = 0, i;
-       
+       int numslots = 0;
+
+       /* dimensions of screen (used in many shaders)*/
+       float screen_dim[2] = {fx->gbuffer_dim[0], fx->gbuffer_dim[1]};
+
        if (fx->effects == 0)
                return false;
        
@@ -241,7 +244,6 @@ bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D 
*v3d, struct RegionView3D
        glPopAttrib();
        GPU_framebuffer_restore();
        
-
        /* set up quad buffer */
        glVertexPointer(2, GL_FLOAT, 0, fullscreencos);
        glTexCoordPointer(2, GL_FLOAT, 0, fullscreenuvs);
@@ -252,7 +254,7 @@ bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D 
*v3d, struct RegionView3D
        
        /* ssao pass */
        if (fx->effects & V3D_FX_SSAO) {
-               fx_shader = 
GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_DEPTH_OF_FIELD);
+               fx_shader = 
GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_SSAO);
                if (fx_shader) {
                        /* view vectors for the corners of the view frustum. 
Can be used to recreate the world space position easily */
                        float ssao_viewvecs[3][4] = {
@@ -261,14 +263,10 @@ bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D 
*v3d, struct RegionView3D
                            {-1.0f, 1.0f, -1.0f, 1.0f}
                        };
                        int i;
-                       int screendim_uniform, color_uniform, depth_uniform, 
dof_uniform, blurred_uniform;
+                       int screendim_uniform, color_uniform, depth_uniform;
                        int ssao_uniform, ssao_color_uniform, 
ssao_viewvecs_uniform, ssao_sample_params_uniform;
                        int ssao_jitter_uniform, ssao_direction_uniform;
-                       float fac = v3d->dof_fstop * v3d->dof_aperture;
-                       float dof_params[2] = {v3d->dof_aperture * fabs(fac / 
(v3d->dof_focal_distance - fac)),
-                                              v3d->dof_focal_distance};
                        float ssao_params[4] = {v3d->ssao_distance_max, 
v3d->ssao_darkening, v3d->ssao_attenuation, 0.0f};
-                       float screen_dim[2] = {fx->gbuffer_dim[0], 
fx->gbuffer_dim[1]};
                        float sample_params[4];
 
                        float invproj[4][4];
@@ -311,10 +309,7 @@ bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D 
*v3d, struct RegionView3D
                        sample_params[2] = fx->gbuffer_dim[0] / 64.0;
                        sample_params[3] = fx->gbuffer_dim[1] / 64.0;
 
-                       dof_uniform = GPU_shader_get_uniform(fx_shader, 
"dof_params");
-                       blurred_uniform = GPU_shader_get_uniform(fx_shader, 
"blurredcolorbuffer");
                        screendim_uniform = GPU_shader_get_uniform(fx_shader, 
"screendim");
-
                        ssao_uniform = GPU_shader_get_uniform(fx_shader, 
"ssao_params");
                        ssao_color_uniform = GPU_shader_get_uniform(fx_shader, 
"ssao_color");
                        color_uniform = GPU_shader_get_uniform(fx_shader, 
"colorbuffer");
@@ -327,7 +322,6 @@ bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D 
*v3d, struct RegionView3D
                        GPU_shader_bind(fx_shader);
 
                        GPU_shader_uniform_vector(fx_shader, screendim_uniform, 
2, 1, screen_dim);
-                       GPU_shader_uniform_vector(fx_shader, dof_uniform, 2, 1, 
dof_params);
                        GPU_shader_uniform_vector(fx_shader, ssao_uniform, 4, 
1, ssao_params);
                        GPU_shader_uniform_vector(fx_shader, 
ssao_color_uniform, 4, 1, v3d->ssao_color);
                        GPU_shader_uniform_vector(fx_shader, 
ssao_viewvecs_uniform, 4, 3, ssao_viewvecs[0]);
@@ -335,13 +329,6 @@ bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D 
*v3d, struct RegionView3D
                        GPU_shader_uniform_vector(fx_shader, 
ssao_direction_uniform, 2, 16, ssao_sample_directions[0]);
 
                        GPU_texture_bind(fx->color_buffer, numslots++);
-                       GPU_shader_uniform_texture(fx_shader, blurred_uniform, 
fx->color_buffer);
-                       /* generate mipmaps for the color buffer */
-                       //              glGenerateMipmapEXT(GL_TEXTURE_2D);
-                       //              glTexParameteri(GL_TEXTURE_2D, 
GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
-                       //              glTexEnvf(GL_TEXTURE_FILTER_CONTROL, 
GL_TEXTURE_LOD_BIAS, 2.0);
-
-                       GPU_texture_bind(fx->color_buffer, numslots++);
                        GPU_shader_uniform_texture(fx_shader, color_uniform, 
fx->color_buffer);
 
                        GPU_texture_bind(fx->depth_buffer, numslots++);
@@ -350,27 +337,62 @@ bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D 
*v3d, struct RegionView3D
 
                        GPU_texture_bind(fx->jitter_buffer, numslots++);
                        GPU_shader_uniform_texture(fx_shader, 
ssao_jitter_uniform, fx->jitter_buffer);
+
+                       /* set invalid color in case shader fails */
+                       glColor3f(1.0, 0.0, 1.0);
+
+                       /* draw */
+                       glDisable(GL_DEPTH_TEST);
+                       glDrawArrays(GL_QUADS, 0, 4);
+                       /* disable bindings */
+                       GPU_texture_unbind(fx->color_buffer);
+                       GPU_depth_texture_mode(fx->depth_buffer, true, false);
+                       GPU_texture_unbind(fx->depth_buffer);
+
+                       /* same texture may be bound to more than one slot. Use 
this to explicitly disable texturing everywhere */
+                       for (i = numslots; i > 0; i--) {
+                               glActiveTexture(GL_TEXTURE0 + i - 1);
+                               glBindTexture(GL_TEXTURE_2D, 0);
+                               glDisable(GL_TEXTURE_2D);
+                       }
+                       numslots = 0;
                }
+       }
 
-               /* set invalid color in case shader fails */
-               glColor3f(1.0, 0.0, 1.0);
 
-               /* draw */
-               glDisable(GL_DEPTH_TEST);
-               glDrawArrays(GL_QUADS, 0, 4);
+       /* second pass, dof */
+       if (fx->effects & V3D_FX_DEPTH_OF_FIELD) {
+               fx_shader = 
GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_DEPTH_OF_FIELD);
+               if (fx_shader) {
+                       float fac = v3d->dof_fstop * v3d->dof_aperture;
+                       float dof_params[2] = {v3d->dof_aperture * fabs(fac / 
(v3d->dof_focal_distance - fac)),
+                                              v3d->dof_focal_distance};
+                       int screendim_uniform, color_uniform, depth_uniform, 
dof_uniform, blurred_uniform;
+
+                       dof_uniform = GPU_shader_get_uniform(fx_shader, 
"dof_params");
+                       blurred_uniform = GPU_shader_get_uniform(fx_shader, 
"blurredcolorbuffer");
+                       screendim_uniform = GPU_shader_get_uniform(fx_shader, 
"screendim");
+                       color_uniform = GPU_shader_get_uniform(fx_shader, 
"colorbuffer");
+                       depth_uniform = GPU_shader_get_uniform(fx_shader, 
"depthbuffer");
+
+                       GPU_shader_uniform_vector(fx_shader, dof_uniform, 2, 1, 
dof_params);
+                       GPU_shader_uniform_vector(fx_shader, screendim_uniform, 
2, 1, screen_dim);
 
-               /* disable bindings */
-               GPU_texture_unbind(fx->color_buffer);
-               GPU_depth_texture_mode(fx->depth_buffer, true, false);
-               GPU_texture_unbind(fx->depth_buffer);
 
-               /* same texture may be bound to more than one slot. Use this to 
explicitly disable texturing everywhere */
-               for (i = numslots; i > 0; i--) {
-                       glActiveTexture(GL_TEXTURE0 + i - 1);
-                       glBindTexture(GL_TEXTURE_2D, 0);
-                       glDisable(GL_TEXTURE_2D);
+                       GPU_texture_bind(fx->color_buffer, numslots++);
+                       GPU_shader_uniform_texture(fx_shader, blurred_uniform, 
fx->color_buffer);
+                       /* generate mipmaps for the color buffer */
+                       //              glGenerateMipmapEXT(GL_TEXTURE_2D);
+                       //              glTexParameteri(GL_TEXTURE_2D, 
GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+                       //              glTexEnvf(GL_TEXTURE_FILTER_CONTROL, 
GL_TEXTURE_LOD_BIAS, 2.0);
+
+                       GPU_texture_bind(fx->color_buffer, numslots++);
+                       GPU_shader_uniform_texture(fx_shader, color_uniform, 
fx->color_buffer);
+
+                       GPU_texture_bind(fx->depth_buffer, numslots++);
+                       GPU_depth_texture_mode(fx->depth_buffer, false, true);
+                       GPU_shader_uniform_texture(fx_shader, depth_uniform, 
fx->depth_buffer);
                }
-               numslots = 0;
        }
 
        glDisableClientState(GL_VERTEX_ARRAY);
diff --git a/source/blender/gpu/intern/gpu_extensions.c 
b/source/blender/gpu/intern/gpu_extensions.c
index 3d312c8..bce7414 100644
--- a/source/blender/gpu/intern/gpu_extensions.c
+++ b/source/blender/gpu/intern/gpu_extensions.c
@@ -82,6 +82,7 @@ extern char datatoc_gpu_shader_sep_gaussian_blur_vert_glsl[];
 extern char datatoc_gpu_shader_sep_gaussian_blur_frag_glsl[];
 extern char datatoc_gpu_shader_fx_vert_glsl[];
 extern char datatoc_gpu_shader_fx_ssao_frag_glsl[];
+extern char datatoc_gpu_shader_fx_dof_frag_glsl[];
 
 typedef struct GPUShaders {
        GPUShader *vsm_store;
@@ -1569,10 +1570,10 @@ GPUShader *GPU_shader_get_builtin_fx_shader(int effects)
                return NULL;
        
        if (!GG.shaders.fx_shaders[effects]) {
-               if (effects == GPU_SHADER_FX_DEPTH_OF_FIELD)
+               if (effects == GPU_SHADER_FX_SSAO)
                        GG.shaders.fx_shaders[effects] = 
GPU_shader_create(datatoc_gpu_shader_fx_vert_glsl, 
datatoc_gpu_shader_fx_ssao_frag_glsl, NULL, NULL);
                else if (effects == GPU_SHADER_FX_DEPTH_OF_FIELD)
-                       GG.shaders.fx_shaders[effects] = 
GPU_shader_create(datatoc_gpu_shader_fx_vert_glsl, 
datatoc_gpu_shader_fx_ssao_frag_glsl, NULL, NULL);
+                       GG.shaders.fx_shaders[effects] = 
GPU_shader_create(datatoc_gpu_shader_fx_vert_glsl, 
datatoc_gpu_shader_fx_dof_frag_glsl, NULL, NULL);
        }
        
        return GG.shaders.fx_shaders[effects];
diff --git a/source/blender/gpu/shaders/gpu_sh

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to