diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-10-02 23:06:20 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-10-02 23:06:20 +0400 |
commit | 5faa29b01dd6b47219d1aabb3217459ba1e2f56d (patch) | |
tree | e952316f62db823d26803a7920b533cd49bfa4e0 /source | |
parent | 283372ab3c828d53173825f9f7e5908fc2548302 (diff) |
move window matrix translation into its own function. (no functional changes)
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenlib/BLI_math_geom.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 20 | ||||
-rw-r--r-- | source/blender/editors/render/render_opengl.c | 28 |
3 files changed, 24 insertions, 26 deletions
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index 5d84de7531a..d2b9e6caf96 100644 --- a/source/blender/blenlib/BLI_math_geom.h +++ b/source/blender/blenlib/BLI_math_geom.h @@ -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]); diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 68b1feea632..3c34f4cda01 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -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; diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c index 262a832cd16..825a6fc7043 100644 --- a/source/blender/editors/render/render_opengl.c +++ b/source/blender/editors/render/render_opengl.c @@ -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); |