[Bf-committers] Patch to fix aliasing problems.

Robert Wenzlaff bf-committers@blender.org
Thu, 28 Aug 2003 22:56:10 -0400


--Boundary-00=_KDsT/3af8n2mCW5
Content-Type: text/plain;
  charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

   I made a simple change to pixelblending.c and clipped the float 
contributions of the samples to 1.0.  It seems to greatly reduce the aliasing 
experienced with excessivly bright background objects (ie; spec+ref>1.0).

I also added a button to the render buttons so you can turn it on/off for side 
by side comparisons/artifact searches...

Fixing this has been a goal of mine since the source was released...
Now I can die (but probably won't for some time).
-- 
Robert Wenzlaff                  rwenzlaff@soylent-green.com


--Boundary-00=_KDsT/3af8n2mCW5
Content-Type: text/x-diff;
  charset="us-ascii";
  name="ClipOSA.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="ClipOSA.patch"

Index: source/blender/render/intern/source/pixelblending.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/render/intern/source/pixelblending.c,v
retrieving revision 1.4
diff -u -r1.4 pixelblending.c
--- source/blender/render/intern/source/pixelblending.c	27 Apr 2003 14:05:41 -0000	1.4
+++ source/blender/render/intern/source/pixelblending.c	29 Aug 2003 02:32:09 -0000
@@ -40,6 +40,8 @@
 /* global includes */
 #include "render.h"
 #include "render_intern.h"
+#include "DNA_scene_types.h"
+#include "BKE_global.h"
 
 /* local includes */
 #include "vanillaRenderPipe_types.h"
@@ -54,6 +56,7 @@
 #include <config.h>
 #endif
 
+extern Global G;
 /* ------------------------------------------------------------------------- */
 /* Debug/behaviour defines                                                   */
 /* if defined: alpha blending with floats clips colour, as with shorts       */
@@ -617,10 +620,17 @@
 
 	if (doGamma()) {
 		/* use a LUT and interpolation to do the gamma correction */
-		for(a=0; a < osaNr; a++, scol+=4) {
-			intcol[0] += gammaCorrect(scol[0]); 
-			intcol[1] += gammaCorrect(scol[1]); 
-			intcol[2] += gammaCorrect(scol[2]); 
+		for(a=0; a < osaNr; a++, scol+=4) { 
+			if ( G.scene->r.scemode & R_CLIPOSA ){ 
+				intcol[0] += gammaCorrect(((scol[0]<1.0) ? scol[0] : 1.0)); 
+				intcol[1] += gammaCorrect(((scol[1]<1.0) ? scol[1] : 1.0)); 
+				intcol[2] += gammaCorrect(((scol[2]<1.0) ? scol[2] : 1.0)); 
+			}
+			else {
+				intcol[0] += gammaCorrect(scol[0]); 
+				intcol[1] += gammaCorrect(scol[1]); 
+				intcol[2] += gammaCorrect(scol[2]);
+			} 
 			intcol[3] += scol[3];
 		}
 
@@ -638,14 +648,24 @@
 	} else {
 		/* no gamma */
 		for(a=0; a < osaNr; a++, scol+=4) {
-			intcol[0] += scol[0]; intcol[1] += scol[1];
-			intcol[2] += scol[2]; intcol[3] += scol[3];
+			if ( G.scene->r.scemode & R_CLIPOSA ){ 
+				intcol[0] += ((scol[0]<1.0) ? scol[0] : 1.0); 
+				intcol[1] += ((scol[1]<1.0) ? scol[1] : 1.0); 
+				intcol[2] += ((scol[2]<1.0) ? scol[2] : 1.0); 
+			}
+			else {
+				intcol[0] += scol[0]; 
+				intcol[1] += scol[1]; 
+				intcol[2] += scol[2];
+			} 	 
+			intcol[3] += scol[3];
 		}
     
 		dest[0]= intcol[0]/osaNr;
 		dest[1]= intcol[1]/osaNr;
 		dest[2]= intcol[2]/osaNr;
 		dest[3]= intcol[3]/osaNr;
+		
 	}
 	
 } /* end void sampleFloatColVToFloatColV(unsigned short *, unsigned short *) */
Index: source/blender/src/buttons.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/buttons.c,v
retrieving revision 1.35
diff -u -r1.35 buttons.c
--- source/blender/src/buttons.c	21 Aug 2003 12:49:28 -0000	1.35
+++ source/blender/src/buttons.c	29 Aug 2003 02:32:26 -0000
@@ -343,6 +343,8 @@
 #define B_FILETYPEMENU  1638
 #define B_SELECTCODEC   1639
 #define B_RTCHANGED		1640
+#define B_CLIPOSA	1641
+
 
 #ifdef __NLA
 /* *********************** */
@@ -6651,7 +6653,8 @@
 
 	uiDefButS(block, TOG|BIT|9,REDRAWVIEWCAM, "Border",	565,11,58,24, &G.scene->r.mode, 0, 0, 0, 0, "Render a small cut-out of the image");
 	uiDefButS(block, TOG|BIT|2,0, "Gamma",	626,11,58,24, &G.scene->r.mode, 0, 0, 0, 0, "Enable gamma correction");
-
+	uiDefButS(block, TOG|BIT|8,0, "ClipOSA",	516,11,48,24, &G.scene->r.scemode, 0, 0, 0, 0, "Clip OSA contriutions to reduce aliasing.");
+	
 	uiBlockSetCol(block, BUTSALMON);
 	uiDefBut(block, BUT,B_DOANIM,"ANIM",		692,142,192,47, 0, 0, 0, 0, 0, "Start rendering a sequence");
 	
Index: source/blender/makesdna/DNA_scene_types.h
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/makesdna/DNA_scene_types.h,v
retrieving revision 1.10
diff -u -r1.10 DNA_scene_types.h
--- source/blender/makesdna/DNA_scene_types.h	13 Jul 2003 20:16:49 -0000	1.10
+++ source/blender/makesdna/DNA_scene_types.h	29 Aug 2003 02:32:26 -0000
@@ -156,6 +156,7 @@
 	 * 0: enable sequence output rendering                                   
 	 * 1: render daemon                                                      
 	 * 4: add extensions to filenames
+	 * 8: Clip OSA samples in OSA sum.
 	 */
 	short scemode;
 
@@ -288,6 +289,7 @@
 
 #define R_EXTENSION		0x0010
 #define R_OGL			0x0020
+#define R_CLIPOSA		0x0100
 
 /* alphamode */
 #define R_ADDSKY		0

--Boundary-00=_KDsT/3af8n2mCW5--