[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32260] trunk/blender/source/blender/ editors/render/render_opengl.c: Anti-Aliasing support for opengl render ( belated durian todo),
Campbell Barton
ideasman42 at gmail.com
Sat Oct 2 19:10:28 CEST 2010
Revision: 32260
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32260
Author: campbellbarton
Date: 2010-10-02 19:10:28 +0200 (Sat, 02 Oct 2010)
Log Message:
-----------
Anti-Aliasing support for opengl render (belated durian todo),
Simple FSA accumulation method means no fancy opengl features needed.
Fixed at 5 samples per pixel for now.
Modified Paths:
--------------
trunk/blender/source/blender/editors/render/render_opengl.c
Modified: trunk/blender/source/blender/editors/render/render_opengl.c
===================================================================
--- trunk/blender/source/blender/editors/render/render_opengl.c 2010-10-02 16:42:12 UTC (rev 32259)
+++ trunk/blender/source/blender/editors/render/render_opengl.c 2010-10-02 17:10:28 UTC (rev 32260)
@@ -128,18 +128,85 @@
*/
if(view_context) {
+ int is_ortho;
GPU_offscreen_bind(oglrender->ofs); /* bind */
/* render 3d view */
if(rv3d->persp==RV3D_CAMOB && v3d->camera) {
RE_GetCameraWindow(oglrender->re, v3d->camera, scene->r.cfra, winmat);
+ is_ortho= scene->r.mode * R_ORTHO;
+
+ }
+ else {
+ rctf viewplane;
+ float clipsta, clipend;
+
+ is_ortho= get_view3d_viewplane(v3d, rv3d, ar->winx, ar->winy, &viewplane, &clipsta, &clipend, NULL);
+ if(is_ortho) orthographic_m4(winmat, viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend);
+ else perspective_m4(winmat, viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend);
+ }
+
+ if((scene->r.mode & R_OSA) == 0) {
ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, winmat);
+ glReadPixels(0, 0, sizex, sizey, GL_RGBA, GL_FLOAT, rr->rectf);
}
else {
- ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, NULL);
+ /* simple accumulation, less hassle then FSAA FBO's */
+# define SAMPLES 5 /* fixed, easy to have more but for now this is ok */
+
+ float winmat_jitter[4][4];
+ float *accum_buffer= MEM_callocN(sizex * sizey * sizeof(float) * 4, "accum1");
+ float *accum_tmp= MEM_callocN(sizex * sizey * sizeof(float) * 4, "accum2");
+ int j, i;
+ float jiy[SAMPLES][2] = {{1,1}, {-1,-1}, {-1,1}, {1,-1}, {0, 0}};
+ float *from, *to;
+ float pixelsize[2];
+
+ 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];
+ }
+
+ for(j=0; j < SAMPLES; j++) {
+ copy_m4_m4(winmat_jitter, winmat);
+
+ if(is_ortho) {
+ winmat_jitter[3][0] += jiy[j][0] * pixelsize[0];
+ winmat_jitter[3][1] += jiy[j][1] * pixelsize[1];
+ }
+ else {
+ winmat_jitter[2][0] += jiy[j][0] * pixelsize[0];
+ winmat_jitter[2][1] += jiy[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);
+
+ i= (sizex*sizey * 4) - 1;
+ from= accum_tmp;
+ to= accum_buffer;
+ do {*to++ += *from++; } while (i--);
+ }
+
+ from= accum_buffer;
+ to= rr->rectf;
+
+ i= (sizex * sizey * 4) - 1;
+ do { *to++= *from++ * (1.0/SAMPLES); } while (i--);
+
+ MEM_freeN(accum_buffer);
+ MEM_freeN(accum_tmp);
}
-
- glReadPixels(0, 0, sizex, sizey, GL_RGBA, GL_FLOAT, rr->rectf);
GPU_offscreen_unbind(oglrender->ofs); /* unbind */
}
More information about the Bf-blender-cvs
mailing list