Commit: d2d3bd35c1c310369678f45ad45fe88aa1e1a3ea
Author: Antony Riakiotakis
Date:   Tue Oct 28 19:44:05 2014 +0100
Branches: viewport_experiments
https://developer.blender.org/rBd2d3bd35c1c310369678f45ad45fe88aa1e1a3ea

Use optimized view space reconstruction for ortho case as well.

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

M       source/blender/gpu/intern/gpu_compositing.c
M       source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl
M       source/blender/gpu/shaders/gpu_shader_fx_lib.glsl
M       source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl

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

diff --git a/source/blender/gpu/intern/gpu_compositing.c 
b/source/blender/gpu/intern/gpu_compositing.c
index 6dde144..dfd7105 100644
--- a/source/blender/gpu/intern/gpu_compositing.c
+++ b/source/blender/gpu/intern/gpu_compositing.c
@@ -278,6 +278,8 @@ bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D 
*v3d, struct RegionView3D
        int numslots = 0;
        float invproj[4][4];
        int i;
+       /* number of passes left. when there are no more passes, the result is 
passed to the frambuffer */
+       int passes_left;
        /* dimensions of screen (used in many shaders)*/
        float screen_dim[2] = {fx->gbuffer_dim[0], fx->gbuffer_dim[1]};
        /* view vectors for the corners of the view frustum. Can be used to 
recreate the world space position easily */
@@ -311,14 +313,23 @@ bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D 
*v3d, struct RegionView3D
                mul_m4_v4(invproj, viewvecs[i]);
                /* normalized trick see 
http://www.derschmale.com/2014/01/26/reconstructing-positions-from-the-depth-buffer
 */
                mul_v3_fl(viewvecs[i], 1.0f / viewvecs[i][3]);
-               mul_v3_fl(viewvecs[i], 1.0f / viewvecs[i][2]);
-               viewvecs[i][2] = 1.0;
+               if (rv3d->is_persp)
+                       mul_v3_fl(viewvecs[i], 1.0f / viewvecs[i][2]);
+               viewvecs[i][3] = 1.0;
        }
 
        /* we need to store the differences */
        viewvecs[1][0] -= viewvecs[0][0];
        viewvecs[1][1] = viewvecs[2][1] - viewvecs[0][1];
 
+       /* calculate a depth offset as well */
+       if (!rv3d->is_persp) {
+               float vec_far[] = {-1.0f, -1.0f, 1.0f, 1.0f};
+               mul_m4_v4(invproj, vec_far);
+               mul_v3_fl(vec_far, 1.0f / vec_far[3]);
+               viewvecs[1][2] = vec_far[2] - viewvecs[0][2];
+       }
+
        /* ssao pass */
        if (fx->effects & V3D_FX_SSAO) {
                fx_shader = 
GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_SSAO, rv3d->is_persp);
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 6f0521e..c12b27d 100644
--- a/source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl
@@ -28,7 +28,7 @@ void main()
 {
     float depth = texture2D(depthbuffer, uvcoordsvar.xy).r;
 
-    vec3 position = get_view_space_from_depth(uvcoordsvar.xy, viewvecs[0].xy, 
viewvecs[1].xy, depth);
+    vec3 position = get_view_space_from_depth(uvcoordsvar.xy, viewvecs[0].xyz, 
viewvecs[1].xyz, depth);
     float coc = calculate_dof_coc(position);
 
     gl_FragColor = vec4(coc, coc, coc, 1.0);
diff --git a/source/blender/gpu/shaders/gpu_shader_fx_lib.glsl 
b/source/blender/gpu/shaders/gpu_shader_fx_lib.glsl
index 26ad0c3..d5841a9 100644
--- a/source/blender/gpu/shaders/gpu_shader_fx_lib.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_fx_lib.glsl
@@ -8,7 +8,7 @@ vec3 calculate_view_space_normal(in vec3 viewposition)
 
 #ifdef PERSP_MATRIX
 
-vec3 get_view_space_from_depth(in vec2 uvcoords, in vec2 viewvec_origin, in 
vec2 viewvec_diff, float depth)
+vec3 get_view_space_from_depth(in vec2 uvcoords, in vec3 viewvec_origin, in 
vec3 viewvec_diff, float depth)
 {
     /* simple depth reconstruction, see 
http://www.derschmale.com/2014/01/26/reconstructing-positions-from-the-depth-buffer
      * we change the factors from the article to fit the OpennGL model.  */
@@ -17,27 +17,20 @@ vec3 get_view_space_from_depth(in vec2 uvcoords, in vec2 
viewvec_origin, in vec2
 
     float zview = -gl_ProjectionMatrix[3][2] / (d + gl_ProjectionMatrix[2][2]);
 
-    return vec3(zview * (viewvec_origin + uvcoords * viewvec_diff), zview);
+    return zview * (viewvec_origin + vec3(uvcoords, 0.0) * viewvec_diff);
 }
 
 #else
 
-vec3 get_view_space_from_depth(in vec2 uvcoords, in vec2 viewvec_origin, in 
vec2 viewvec_diff, float depth)
+vec3 get_view_space_from_depth(in vec2 uvcoords, in vec3 viewvec_origin, in 
vec3 viewvec_diff, float depth)
 {
     /* simple depth reconstruction, see 
http://www.derschmale.com/2014/01/26/reconstructing-positions-from-the-depth-buffer
-     * we change the factors from the article to fit the OpennGL model.
-    float d = 2.0 * depth - 1.0;
-
-    float zview = -gl_ProjectionMatrix[2][3] / (d + gl_ProjectionMatrix[2][2]);
-
-    vec3 pos = vec3(zview * (ssao_viewvecs[0].xy + uvcoords * 
ssao_viewvecs[1].xy), zview);
-    */
-    vec4 pos = 2.0 * vec4(uvcoords.xy, depth, 1.0) - vec4(1.0);
+     * we change the factors from the article to fit the OpennGL model.  */
 
-    pos = gl_ProjectionMatrixInverse * pos;
-    pos /= pos.w;
+    float d = 2.0 * depth - 1.0;
+    vec3 offset = vec3(uvcoords, d);
 
-    return pos.xyz;
+    return vec3(viewvec_origin + offset * viewvec_diff);
 }
 
 #endif
\ No newline at end of file
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 3f112b3..1f6c9d1f 100644
--- a/source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl
@@ -32,7 +32,7 @@ float calculate_ssao_factor(float depth)
     if (depth == 1.0)
         return 0.0;
 
-    vec3 position = get_view_space_from_depth(uvcoordsvar.xy, viewvecs[0].xy, 
viewvecs[1].xy, depth);
+    vec3 position = get_view_space_from_depth(uvcoordsvar.xy, viewvecs[0].xyz, 
viewvecs[1].xyz, depth);
     vec3 normal = calculate_view_space_normal(position);
 
     // find the offset in screen space by multiplying a point in camera space 
at the depth of the point by the projection matrix.
@@ -55,7 +55,7 @@ float calculate_ssao_factor(float depth)
 
             float depth_new = texture2D(depthbuffer, uvcoords).r;
             if (depth_new != 1.0) {
-                vec3 pos_new = get_view_space_from_depth(uvcoords, 
viewvecs[0].xy, viewvecs[1].xy, depth_new);
+                vec3 pos_new = get_view_space_from_depth(uvcoords, 
viewvecs[0].xyz, viewvecs[1].xyz, depth_new);
                 vec3 dir = pos_new - position;
                 float len = length(dir);
                 float f = dot(dir, normal);

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

Reply via email to