[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11590] branches/soc-2007-joeedh/source/ blender/render/intern/source: Visibility function compression now works.

Joseph Eagar joeedh at gmail.com
Tue Aug 14 14:35:00 CEST 2007


Revision: 11590
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11590
Author:   joeedh
Date:     2007-08-14 14:35:00 +0200 (Tue, 14 Aug 2007)

Log Message:
-----------
Visibility function compression now works.  However, its not as good as made
out in the pixar paper, so the cache system will still need to be used,
along most like with the old brute-force optimization I was using

Next step: do some refactoring so three visibility functions are created, one
each for x, y, and z.  Then hook the cache system back up.  Then tackle the stupid
shading code.

Modified Paths:
--------------
    branches/soc-2007-joeedh/source/blender/render/intern/source/shadbuf.c
    branches/soc-2007-joeedh/source/blender/render/intern/source/zbuf.c

Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/shadbuf.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/shadbuf.c	2007-08-14 12:17:46 UTC (rev 11589)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/shadbuf.c	2007-08-14 12:35:00 UTC (rev 11590)
@@ -675,11 +675,15 @@
 		//int prev = i==0 ? sample[i].depth : sample[i-1].depth;
 		//if ( zs > ((sample[i].depth>>1) + (prev>>1)) + bias ) {
 		if (zs > sample[i].depth+bias) {
+			//another attempt at halfway depth method:
+			//int depth = i < func->totsamples-1 ? sample[i].depth>>1+sample[i+1].depth>>1 : i!=func->totsamples-1?sample[i+1].depth:0;
 			if ( (i != func->totsamples-1 && zs < (sample[i+1].depth+bias)) || i == func->totsamples-1 ) {
-				BASSERT(sample[i].clr[3] >= -0.0001);
+				BASSERT(sample[i].clr[3] >= -0.00001);
+				if (sample[i+1].clr[3] <= -0.00001) printf("alpha < 0! %f\n", (float)sample[i+1].clr[3]);
 				BASSERT(zs > sample[i].depth+bias);
 				if (i+1 < func->totsamples) { 
 					BASSERT(sample[i+1].clr[3] >= 0);
+					if (sample[i+1].clr[3] <= -0.00001) printf("alpha < 0! %f\n", (float)sample[i+1].clr[3]);
 					BASSERT(sample[i].depth < sample[i+1].depth);
 					alpha = lerp(sample[i].depth, sample[i+1].depth, zs, sample[i].clr[3], sample[i+1].clr[3]);
 				} else alpha = sample[i].clr[3];

Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/zbuf.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/zbuf.c	2007-08-14 12:17:46 UTC (rev 11589)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/zbuf.c	2007-08-14 12:35:00 UTC (rev 11590)
@@ -3223,7 +3223,7 @@
 			tile->x = x;
 			tile->y = y;
 
-			tile->arena = BLI_memarena_new(1<<13); /*FIXMEGREP: tweak this to find optimal value.*/
+			tile->arena = BLI_memarena_new(1<<20); /*FIXMEGREP: tweak this to find optimal value.*/
 			BLI_memarena_use_mapalloc(tile->arena);
 			tile->layer_rect = BLI_memarena_alloc(tile->arena, sizeof(void*)*tile->sizex*tile->sizey);
 			memset(tile->layer_rect, 0, sizeof(void*)*tile->sizex*tile->sizey);
@@ -3272,7 +3272,7 @@
 
 				printf("sx: %d, sy: %d, dx: %d, dy: %d\n", rentile.sizex, rentile.sizey, dbuf->sizex, dbuf->sizey);
 
-				rentile.arena = BLI_memarena_new(1<<13); /*FIXMEGREP: tweak this to find optimal value.*/
+				rentile.arena = BLI_memarena_new(1<<20); /*FIXMEGREP: tweak this to find optimal value.*/
 				BLI_memarena_use_mapalloc(rentile.arena);
 				rentile.layer_rect = BLI_memarena_alloc(rentile.arena, sizeof(void*)*rentile.sizex*rentile.sizey);
 				memset(rentile.layer_rect, 0, sizeof(void*)*rentile.sizex*rentile.sizey);
@@ -3349,28 +3349,108 @@
 	return 0;
 }
 
+/*
+ This function removes extraneous points
+ from a density function.  It works by
+ casting a triangular "beam" from a vertex,
+ then clipping it with subsequent vertices's
+ opacity - err and opacity + err, until it
+ no longer exists.
 
-static DSMLayerSample *DSM_CompressFunction(MemArena *arena, DSMFunction *func, float error)
+ See original Deep Shadow Maps paper for more details.
+*/
+static void DSM_CompressFunction(MemArena *arena, DSMFunction *func, float error)
 {
-	DSMLayerSample *sample, *cursample;
-	double slope, threshold[2];
-	int totface, a, b, c;
+	DSMLayerSample *samp = func->samples, *cursamp, *newsamp;
+	/*start and end are slopes*/
+	double start, end, ostartpoint, oendpoint, startpoint = -1, endpoint = -1, err=error/2.0;
+	int totface=0, a=0, olda, count=0;
 	
-	sample = BLI_memarena_alloc(arena, sizeof(DSMLayerSample)*func->totsamples);
-	memcpy(sample, func->samples, sizeof(DSMLayerSample)*func->totsamples);
+	if (err==0) err = 0.001;
+
+	cursamp = func->samples;
 	
-	return sample;
-	/*
-	samp = cursamp = func->samples;
-	for (a=0; a<func->totsamples; a++) {
-		threshold[0] = 1.0f;
-		threshold[1] = -1.0f;
+	if (G.rt == 88) {
+		memcpy(cursamp, func->samples, sizeof(DSMLayerSample)*func->totsamples);
+		func->samples = cursamp;
+		return;
+	}
+
+	while (a < func->totsamples) {
+		*cursamp = samp[a];
 		
-		while (1) {
-			
+		/*store the number of original samples between this one and
+		  the last, this is actually used by the (probably coded post-
+		  GSoC) soft shadow method.*/
+		if (a != 0) {
+			cursamp->orig_totsamples = olda;
 		}
+
+		if (a == func->totsamples - 1) {
+			totface++;
+			break;
+		}
+
+		start = (samp[a+1].clr[3]+err) - cursamp->clr[3];
+		end   = (samp[a+1].clr[3]-err) - cursamp->clr[3];
+		if (samp[a+1].depth != cursamp->depth) {
+			start /= (double)(samp[a+1].depth - cursamp->depth);
+			end   /= (double)(samp[a+1].depth - cursamp->depth);
+		}
 		
-	}*/	
+		a += 1;
+		olda = a;
+		while (a < func->totsamples) {
+			ostartpoint = startpoint;
+			oendpoint = endpoint;
+			if (samp[a].depth == cursamp->depth) {
+				startpoint = cursamp->clr[3] + err;
+				endpoint = cursamp->clr[3] - err;
+			} else {
+				startpoint = cursamp->clr[3] + start * (double)(samp[a].depth - cursamp->depth);
+				endpoint   = cursamp->clr[3] + end * (double)(samp[a].depth - cursamp->depth);
+			}
+			if (startpoint > samp[a].clr[3] && endpoint < samp[a].clr[3]) {
+				if (startpoint > samp[a].clr[3]) {
+					start = (samp[a].clr[3]+err) - cursamp->clr[3];
+					if (samp[a].depth != cursamp->depth) {
+						start /= (double)(samp[a].depth - cursamp->depth);
+					}
+				}
+				if (endpoint < samp[a].clr[3]) {
+					end = (samp[a].clr[3]-err) - cursamp->clr[3];
+					if (samp[a].depth != cursamp->depth) {
+						end /= (double)(samp[a].depth - cursamp->depth);
+					}
+				}			
+			} else {
+				a -= 1;
+				break;
+			}
+			olda -= a;
+
+			/*I know, this is a bad way to do float-double equality.  Oh well.*/
+			//if (ABS(start - end) < 0.00001) break;
+			a += 1;
+		}
+		cursamp++;
+		totface++;
+		count = a;
+
+		if (a >= func->totsamples) {
+			*cursamp = samp[func->totsamples-1];
+			cursamp++;
+			totface++;
+		}
+	}
+	
+	if (G.rt) printf("totface: %d, func->totsamples: %d, error: %f, err: %f\n", totface, func->totsamples, error, (float)err);
+	
+	newsamp = BLI_memarena_alloc(arena, sizeof(DSMLayerSample)*totface);
+	memcpy(newsamp, samp, sizeof(DSMLayerSample)*totface);
+
+	func->totsamples = totface;
+	func->samples = newsamp;
 }
 
 static void shade_dsmsample(Render *re, VlakRen *vlr, int facenr, float *diff,
@@ -3448,7 +3528,7 @@
 }
 
 
-DSMFunction *DSM_MergeLayerList(MemArena *arena, _ClrEntry *row, ListBase *transfuncs, int totface, char *scratchmem, int scratchlen, float *weight, int samplewid)
+DSMFunction *DSM_MergeLayerList(MemArena *arena, _ClrEntry *row, ListBase *transfuncs, int totface, char *scratchmem, int scratchlen, float *weight, int samplewid, float error)
 {
 	DSMFunction *func;
 	DSMLayerSample *samp;
@@ -3515,7 +3595,7 @@
 	}
 	
 	//func->totsamples = i;
-	func->samples = DSM_CompressFunction(arena, func, 0.1);
+	DSM_CompressFunction(arena, func, error);
 
 	return func;
 }
@@ -3713,8 +3793,12 @@
 					if (lastsamples[row2[a].samplenr] && lastsamples[row2[a].samplenr]->ispolygon) {
 						/*add polygon "step" to the transmittance function*/
 						row[totface] = *lastsamples[row2[a].samplenr];
-						row[totface].depth = row2[a].depth - 1;
+						row[totface].depth = row2[a].depth - 2;
 						if (row[totface].depth < 0) row[totface].depth = 0;
+						if (row[totface].depth <= lastsamples[row2[a].samplenr]->depth) {
+							/*bleh this is bad*/
+							row[totface].depth = row[totface].depth - 1;
+						}
 						totface++;
 					} else {
 						/*add vis of 1.0 header sample to transmittance function*/
@@ -3743,6 +3827,7 @@
 
 					if (a != totface - 1 && row[a+1].depth < row[a].depth) {
 						printf("EVVVVIIIL! one: %d, two: %d\n", row[a].depth, row[a+1].depth);
+
 					}
 					
 					if (accum[row[a].samplenr] > 0.001) { 
@@ -3810,7 +3895,7 @@
 				/*compute the final visibility function by averaging the subpixel functions
 				  together*/
 				tile->layer_rect[y*tile->sizex+x] = DSM_MergeLayerList(tile->arena, row2, transfuncs, totface, mergescratch, 
-					                                   mergescratchlen, buf->weight, buf->samp);
+					                                   mergescratchlen, buf->weight, buf->samp, 0.175/sqrt(buf->samp*buf->samp));
 				
 			}
 		}





More information about the Bf-blender-cvs mailing list