move window matrix translation into its own function. (no functional changes)
authorCampbell Barton <ideasman42@gmail.com>
Sat, 2 Oct 2010 19:06:20 +0000 (19:06 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 2 Oct 2010 19:06:20 +0000 (19:06 +0000)
source/blender/blenlib/BLI_math_geom.h
source/blender/blenlib/intern/math_geom.c
source/blender/editors/render/render_opengl.c

index 5d84de7531aa06c505d2f7a2f22a5f38457414c9..d2b9e6caf967142e5bb861af732529189baaf33e 100644 (file)
@@ -149,6 +149,8 @@ void perspective_m4(float mat[4][4], float left, float right,
        float bottom, float top, float nearClip, float farClip);
 void orthographic_m4(float mat[4][4], float left, float right,
        float bottom, float top, float nearClip, float farClip);
+void window_translate_m4(float winmat[][4], float perspmat[][4],
+       float x, float y);
 
 int box_clip_bounds_m4(float boundbox[2][3],
        float bounds[4], float winmat[4][4]);
index 68b1feea632db87bf5d264101cd7784dd86c1ee1..3c34f4cda01da2806ec82789e1bb3de14a509879 100644 (file)
@@ -1647,6 +1647,26 @@ void perspective_m4(float mat[][4],float left, float right, float bottom, float
 
 }
 
+/* translate a matrix created by orthographic_m4 or perspective_m4 in viewspace XY coords (used to jitter the view)
+ * transforms in worldspace coords. */
+void window_translate_m4(float winmat[][4], float perspmat[][4], float x, float y)
+{
+       if(winmat[2][3] == -1.0f) {
+               /* in the case of a win-matrix, this means perspective always */
+               float v1[3]= {perspmat[0][0], perspmat[1][0], perspmat[2][0]};
+               float v2[3]= {perspmat[0][1], perspmat[1][1], perspmat[2][1]};
+               float len1= (1.0f / len_v3(v1));
+               float len2= (1.0f / len_v3(v2));
+               
+               winmat[2][0] += len1 * winmat[0][0] * x;
+               winmat[2][1] += len2 * winmat[1][1] * y;
+       }
+       else {
+               winmat[3][0] += x;
+               winmat[3][1] += y;
+       }
+}
+
 static void i_multmatrix(float icand[][4], float Vm[][4])
 {
        int row, col;
index 262a832cd160a03e2a1783ead031100d9548e97d..825a6fc70432203e1c0d87e477f5e1706cfb9451 100644 (file)
@@ -153,45 +153,21 @@ static void screen_opengl_render_apply(OGLRender *oglrender)
                else {
                        /* simple accumulation, less hassle then FSAA FBO's */
 #                      define SAMPLES 5 /* fixed, easy to have more but for now this is ok */
-                       const float jit_ofs[SAMPLES][2] = {{0, 0}, {1,1}, {-1,-1}, {-1,1}, {1,-1}};
+                       const float jit_ofs[SAMPLES][2] = {{0, 0}, {0.5f, 0.5f}, {-0.5f,-0.5f}, {-0.5f, 0.5f}, {0.5f, -0.5f}};
                        float winmat_jitter[4][4];
                        float *accum_buffer= MEM_mallocN(sizex * sizey * sizeof(float) * 4, "accum1");
                        float *accum_tmp= MEM_mallocN(sizex * sizey * sizeof(float) * 4, "accum2");
                        int j, i;
                        float *from, *to;
-                       float pixelsize[2];
 
                        /* first sample buffer, also initializes 'rv3d->persmat' */
                        ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, winmat);
                        glReadPixels(0, 0, sizex, sizey, GL_RGBA, GL_FLOAT, accum_buffer);
 
-                       if(is_ortho) {
-                               pixelsize[0]= 0.5f / sizex;
-                               pixelsize[1]= 0.5f / sizey;
-                       }
-                       else {
-                               /* copied from view3d_main_area_setup_view */
-                               float v1[3]= {rv3d->persmat[0][0], rv3d->persmat[1][0], rv3d->persmat[2][0]};
-                               float v2[3]= {rv3d->persmat[0][1], rv3d->persmat[1][1], rv3d->persmat[2][1]};
-                               float len1= (1.0f / len_v3(v1)) / (float)sizex;
-                               float len2= (1.0f / len_v3(v2)) / (float)sizey;
-
-                               pixelsize[0]= 0.5 * len1 * winmat[0][0];
-                               pixelsize[1]= 0.5 * len2 * winmat[1][1];
-                       }
-
                        /* skip the first sample */
                        for(j=1; j < SAMPLES; j++) {
                                copy_m4_m4(winmat_jitter, winmat);
-
-                               if(is_ortho) {
-                                       winmat_jitter[3][0] += jit_ofs[j][0] * pixelsize[0];
-                                       winmat_jitter[3][1] += jit_ofs[j][1] * pixelsize[1];
-                               }
-                               else {
-                                       winmat_jitter[2][0] += jit_ofs[j][0] * pixelsize[0];
-                                       winmat_jitter[2][1] += jit_ofs[j][1] * pixelsize[1];
-                               }
+                               window_translate_m4(winmat_jitter, rv3d->persmat, jit_ofs[j][0] / sizex, jit_ofs[j][1] / sizey);
 
                                ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, winmat_jitter);
                                glReadPixels(0, 0, sizex, sizey, GL_RGBA, GL_FLOAT, accum_tmp);