[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32262] trunk/blender/source/blender: move window matrix translation into its own function.
Campbell Barton
ideasman42 at gmail.com
Sat Oct 2 21:06:20 CEST 2010
Revision: 32262
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32262
Author: campbellbarton
Date: 2010-10-02 21:06:20 +0200 (Sat, 02 Oct 2010)
Log Message:
-----------
move window matrix translation into its own function. (no functional changes)
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/BLI_math_geom.h
trunk/blender/source/blender/blenlib/intern/math_geom.c
trunk/blender/source/blender/editors/render/render_opengl.c
Modified: trunk/blender/source/blender/blenlib/BLI_math_geom.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_geom.h 2010-10-02 18:25:12 UTC (rev 32261)
+++ trunk/blender/source/blender/blenlib/BLI_math_geom.h 2010-10-02 19:06:20 UTC (rev 32262)
@@ -149,6 +149,8 @@
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]);
Modified: trunk/blender/source/blender/blenlib/intern/math_geom.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_geom.c 2010-10-02 18:25:12 UTC (rev 32261)
+++ trunk/blender/source/blender/blenlib/intern/math_geom.c 2010-10-02 19:06:20 UTC (rev 32262)
@@ -1647,6 +1647,26 @@
}
+/* 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;
Modified: trunk/blender/source/blender/editors/render/render_opengl.c
===================================================================
--- trunk/blender/source/blender/editors/render/render_opengl.c 2010-10-02 18:25:12 UTC (rev 32261)
+++ trunk/blender/source/blender/editors/render/render_opengl.c 2010-10-02 19:06:20 UTC (rev 32262)
@@ -153,46 +153,22 @@
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);
+ window_translate_m4(winmat_jitter, rv3d->persmat, jit_ofs[j][0] / sizex, jit_ofs[j][1] / sizey);
- 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];
- }
-
ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, winmat_jitter);
glReadPixels(0, 0, sizex, sizey, GL_RGBA, GL_FLOAT, accum_tmp);
More information about the Bf-blender-cvs
mailing list