[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13486] branches/soc-2007-joeedh/source/ blender: Combined a few of the core DSM loops for speed; this is

Joseph Eagar joeedh at gmail.com
Wed Jan 30 21:18:59 CET 2008


Revision: 13486
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13486
Author:   joeedh
Date:     2008-01-30 21:18:59 +0100 (Wed, 30 Jan 2008)

Log Message:
-----------
Combined a few of the core DSM loops for speed; this is
unfinished as theres a few more I could combine (I'm
referring to run-time loops, I haven't actually combined
any code loops yet, I just made one loop process more
data).

Also, added the option that if the shadow alpha material
setting isn't 1.0, then color is ignored for shadows.
This is to facilitate rendering strands, which are made
transparent to simulate the fact that real strands are
many times smaller then the width of a pixel.  Thus,
they arn't really transparent but merely look that way,
and thus shouldn't case colored shadows.

Next up I suppose I should try tackling evaluating
textures for shadows again.  Note that I'm not sure
if it'll be possible to handle node materials or not;
I'll have to look at that.

Modified Paths:
--------------
    branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h
    branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_bucketbuffer.c
    branches/soc-2007-joeedh/source/blender/makesdna/DNA_material_types.h
    branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c

Modified: branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h	2008-01-30 18:18:33 UTC (rev 13485)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h	2008-01-30 20:18:59 UTC (rev 13486)
@@ -94,17 +94,19 @@
 	/*needed for zbuffering*/
 	void **lastbuf, **lastbufstrand;
 	ListBase *buckets;
+
+	void *s2, *s3;
 } DSMBuffer;
 
 //32 16 8 4 2 1
 #define MAX_SAMPLELAYERS	32
 #define DSM_FINAL_TILESIZE	32
-#define DSM_TILE_MEMARENASIZE	(1<<18)
+#define DSM_TILE_MEMARENASIZE	(1<<16)
 #define DSM_AASAMPLES		(shb->samp) //(G.rt>8 ? 1 : (G.rt==0 ? 1 : G.rt))
 #define DSM_AAWIDTH			(shb->soft)
 
 /*little bit smaller memarena buffer size for the final diced
-  25x25 tiles*/
+  32x32 tiles*/
 #define DSM_TILE_FINALMEMARENASIZE (1<<16)
 
 void _DSM_maketile(TCS_TileBuffer *self, TCS_TilePool *pool, TCS_Tile *vtile);

Modified: branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_bucketbuffer.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_bucketbuffer.c	2008-01-30 18:18:33 UTC (rev 13485)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_bucketbuffer.c	2008-01-30 20:18:59 UTC (rev 13486)
@@ -230,17 +230,17 @@
 	buf->sizey = sizey;
 	
 	/*test if we need to add extra tiles along the x axix*/
-	fac = ((float)sizex/(float)tsizex) + 0.0000001;
-
-	if ((int)((fac - (int)fac)*(float)tsizex) > 0.000001) {
-		tilex += 1;
+	fac = ((float)sizex/(float)tsizex) + 0.0000001;
+
+	if ((int)((fac - (int)fac)*(float)tsizex) > 0.000001) {
+		tilex += 1;
 	}
 	
 	/*test if we need to add extra tiles along the y axix*/
-	fac = ((float)sizey/(float)tsizey) + 0.0000001;
-
-	if ((int)((fac - (int)fac)*(float)tsizey) > 0.000001) {
-		tiley += 1;
+	fac = ((float)sizey/(float)tsizey) + 0.0000001;
+
+	if ((int)((fac - (int)fac)*(float)tsizey) > 0.000001) {
+		tiley += 1;
 	}
 	
 	buf->tilex = tilex;
@@ -259,11 +259,11 @@
 			tile->x = x;
 			tile->y = y;
 			
-			/*right and top border tiles arn't always the same size as the others*/
-			if (x == tilex-1) tile->sizex = sizex - tsizex*x;
-			else tile->sizex = tsizex;
-
-			if (y == tiley-1) tile->sizey = sizey - tsizey*y;
+			/*right and top border tiles arn't always the same size as the others*/
+			if (x == tilex-1) tile->sizex = sizex - tsizex*x;
+			else tile->sizex = tsizex;
+
+			if (y == tiley-1) tile->sizey = sizey - tsizey*y;
 			else tile->sizey = tsizey;
 			
 			TCS_AddToPool(pool, tile);

Modified: branches/soc-2007-joeedh/source/blender/makesdna/DNA_material_types.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/makesdna/DNA_material_types.h	2008-01-30 18:18:33 UTC (rev 13485)
+++ branches/soc-2007-joeedh/source/blender/makesdna/DNA_material_types.h	2008-01-30 20:18:59 UTC (rev 13486)
@@ -89,7 +89,7 @@
 	char strand_uvname[32];
 	
 	float sbias;			/* shadow bias */
-	float shad_alpha;		/* in use for irregular shadowbuffer */
+	float shad_alpha;		/* in use for irregular shadowbuffer/deep shadow maps */
 	
 	/* for buttons and render*/
 	char rgbsel, texact, pr_type, use_nodes;

Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c	2008-01-30 18:18:33 UTC (rev 13485)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c	2008-01-30 20:18:59 UTC (rev 13486)
@@ -156,13 +156,19 @@
 	  iirc is because the visibilty function calculation
 	  kindof expands things (note this is usually more then
 	  compensated by the final visibility function compression).*/
+	
+	if (G.rt==71)
+		dbuf->max_depth = 2000*6;
+	else
+		dbuf->max_depth = 30000*6;
 
-	dbuf->max_depth = 30000*6;
 	dbuf->max_layers = 0;
 
 	mergescratchlen = sizeof(_ClrEntry) > sizeof(DSMLayerSample) ? sizeof(_ClrEntry)*dbuf->max_depth : sizeof(DSMLayerSample)*dbuf->max_depth;
 	rowscratch = MEM_mallocN(sizeof(_ClrEntry)*dbuf->max_depth, "_ClrEntry");
 	mergescratch = MEM_mapallocN(mergescratchlen, "mergescratch in zbuf.c");
+	dbuf->s2 = MEM_mallocN(mergescratchlen, "dbuf->s2");
+	dbuf->s3 = MEM_mallocN(mergescratchlen, "dbuf->s3");
 
 	if (tilesize > shb->size) tilesize = shb->size;
 	
@@ -232,6 +238,8 @@
 		}
 	}
 	
+	MEM_freeN(dbuf->s2);
+	MEM_freeN(dbuf->s3);
 	MEM_freeN(dbuf->lastbuf);
 	MEM_freeN(dbuf->lastbufstrand);
 	dbuf->lastbuf = NULL;
@@ -335,6 +343,203 @@
 }
 #endif
 
+static void DSM_CompressFunction(MemArena *arena, DSMFunction *func, float error);
+
+/*The Loop of Doom.
+  One loop to merge them all, One loop to find them;
+  One loop to compress them all, and in the darkness, bind them!*/
+#define COMPSTATE_PROCESSING	0
+#define COMPSTATE_PROCESSING2	1
+#define COMPSTATE_COMPRESSING	2
+#define COMPSTATE_DONE			3
+
+void DSM_MergeLayerListNew(DSMTile *tile, int x, int y, _ClrEntry *row, ListBase (*transfuncs)[3],
+								   int totface, void *scratchmem1, void *scratchmem2, void *scratchmem3,
+								   int scratchlen, float *weight, int samplewid, float error)
+{
+	DSMFunction *func[3];
+	DSMLayerSample *cursamp[3]={NULL, NULL, NULL}, *samp;
+	DSMLayerSample *sout[3] = {scratchmem1, scratchmem2, scratchmem3};
+	_ClrEntry *csamp, *lastcsamp[3]={NULL, NULL, NULL};
+	double slope[3]={0.0, 0.0, 0.0}, accum[3] = {1.0, 1.0, 1.0}, s1, s2;
+	double start[3], end[3], ostartpoint[3], oendpoint[3];
+	double startpoint[3] = {-1.0, -1.0, -1.0}, endpoint[3] = {-1.0, -1.0, -1.0}, err=error; // /2.0;
+	int i, ci, totfaces[3] = {0, 0, 0}, cursor[3]={0, 0, 0};
+	int state[3] = {COMPSTATE_PROCESSING, COMPSTATE_PROCESSING, COMPSTATE_PROCESSING};
+	int totface2[3] = {0, 0, 0}, count[3]={0, 0, 0};
+
+	for (i=0; i<3; i++) {
+		func[i] = BLI_memarena_alloc(tile->arena, sizeof(DSMFunction));
+		func[i]->samples = (DSMLayerSample*) sout[i];
+		cursamp[i] = sout[i];
+		func[i]->totsamples = 0;
+		func[i]->zmin = 0x7FFFFFFF;
+		func[i]->zmax = -0x7FFFFFFF;
+	}
+
+	/*we add 1 to totface to compensate for how compression must lag behind merging.*/
+	for (i=0, csamp=row; i<totface; i++, csamp++) {
+		ci = csamp->index;
+		BASSERT(ci >= 0 && ci < 3);
+		samp = func[ci]->samples + totfaces[ci];
+
+		/*we've hit a sample in one of the other rgb color component
+		  visibility functions, or we've hit an excluded sample, so continue*/
+		if (!csamp->srclist) {
+			continue;
+		}
+
+		samp->orig_totsamples = 0;
+		samp->depth = csamp->depth;
+		if (samp->depth > func[ci]->zmax) func[ci]->zmax = csamp->depth;
+		if (samp->depth < func[ci]->zmin) func[ci]->zmin = csamp->depth;
+
+		if (lastcsamp[ci]) accum[ci] = accum[ci] + (double)(csamp->depth-lastcsamp[ci]->depth)*slope[ci];
+		samp->value = (float) accum[ci];
+		
+		if (csamp->next && csamp->next->depth == csamp->depth) {
+			accum[ci] += weight[csamp->samplenr]*(csamp->next->value-csamp->value);
+		}
+
+		if (csamp->next) {
+			if (csamp->next->depth != csamp->depth) {
+				s2 = ((double)(csamp->next->value - csamp->value)) / (double)(csamp->next->depth - csamp->depth);
+				if (csamp->prev) {
+					if (csamp->prev->depth != csamp->depth) {
+						s1 = ((double)(csamp->value - csamp->prev->value)) / (double)(csamp->depth - csamp->prev->depth);
+						slope[ci] += weight[csamp->samplenr]*(s2 - s1);
+					} else {
+						slope[ci] += weight[csamp->samplenr]*s2;
+					}
+				} else {
+					slope[ci] += weight[csamp->samplenr]*s2;
+				}
+			} else {
+				if (csamp->prev && csamp->prev->depth != csamp->depth) {
+					s1 = csamp->value - csamp->prev->value;
+					s1 /= csamp->depth - csamp->prev->depth;
+					slope[ci] -= weight[csamp->samplenr]*s1;
+				}
+			}
+		} else {
+			if (csamp->prev) {
+				if (csamp->prev->depth == csamp->depth) {
+					//accum[ci] += weight[csamp->samplenr]*(csamp->value-csamp->prev->value);
+				} else {
+					s1 = ((double)(csamp->value - csamp->prev->value)) / (double)(csamp->depth - csamp->prev->depth);
+					slope[ci] -= weight[csamp->samplenr]*s1;
+				}
+			}			
+		}
+
+		if (accum[ci] < -0.001f) {
+			printf("EVIL! accum: %f\n", accum[ci]);
+			accum[ci] = 0.0f;
+		}
+		else if (accum[ci] > 1.001f) {
+			printf("EVIL 2! accum: %f\n", accum[ci]);
+			accum[ci] = 1.0f;
+		}
+
+		lastcsamp[ci] = csamp;
+
+		totfaces[ci]++;
+		
+		/*
+		//continue;
+		//compression has to lag behind merging by 1 samples.
+		if (totfaces[ci] <= 1) continue;
+
+		if (state[ci] == COMPSTATE_PROCESSING) {
+			*cursamp[ci] = sout[ci][cursor[ci]];
+			
+			//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.
+			cursamp[ci]->orig_totsamples = 0;
+
+			if (state[ci] != COMPSTATE_DONE && cursor[ci] >= totfaces[ci]) { //func[ci]->totsamples - 1) {
+				totface2[ci]++;
+				state[ci] = COMPSTATE_DONE;
+				continue;
+			}
+
+			start[ci] = (sout[ci][cursor[ci]+1].value+err) - cursamp[ci]->value;
+			end[ci]   = (sout[ci][cursor[ci]+1].value-err) - cursamp[ci]->value;
+			if (sout[ci][cursor[ci]+1].depth != cursamp[ci]->depth) {
+				start[ci] /= (double)(sout[ci][cursor[ci]+1].depth - cursamp[ci]->depth);
+				end[ci]   /= (double)(sout[ci][cursor[ci]+1].depth - cursamp[ci]->depth);
+			}
+			cursor[ci] += 1;
+
+			state[ci] = COMPSTATE_COMPRESSING;
+		}
+		
+		if (state[ci] == COMPSTATE_COMPRESSING) {
+			ostartpoint[ci] = startpoint[ci];
+			oendpoint[ci] = endpoint[ci];
+			if (sout[ci][cursor[ci]].depth == cursamp[ci]->depth) {
+				//startpoint = cursamp->value + err;
+				//endpoint = cursamp->value - err;
+				break;
+			} else {
+				startpoint[ci] = cursamp[ci]->value + start[ci] * (double)(sout[ci][cursor[ci]].depth - cursamp[ci]->depth);
+				endpoint[ci]   = cursamp[ci]->value + end[ci] * (double)(sout[ci][cursor[ci]].depth - cursamp[ci]->depth);
+			}
+			if (startpoint[ci] > sout[ci][cursor[ci]].value && endpoint[ci] < sout[ci][cursor[ci]].value) {
+				if (startpoint[ci] > sout[ci][cursor[ci]].value+err) {
+					start[ci] = (sout[ci][cursor[ci]].value+err) - cursamp[ci]->value;
+					if (sout[ci][cursor[ci]].depth != cursamp[ci]->depth) {
+						start[ci] /= (double)(sout[ci][cursor[ci]].depth - cursamp[ci]->depth);
+					}
+				}
+				if (endpoint[ci] < sout[ci][cursor[ci]].value-err) {
+					end[ci] = (sout[ci][cursor[ci]].value-err) - cursamp[ci]->value;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list