[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17800] branches/soc-2007-joeedh/source/ blender: made strands faster, by modifing the bucketing system

Joseph Eagar joeedh at gmail.com
Fri Dec 12 12:33:16 CET 2008


Revision: 17800
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17800
Author:   joeedh
Date:     2008-12-12 12:33:15 +0100 (Fri, 12 Dec 2008)

Log Message:
-----------
made strands faster, by modifing the bucketing system

Modified Paths:
--------------
    branches/soc-2007-joeedh/source/blender/blenkernel/BKE_bucketbuffer.h
    branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c
    branches/soc-2007-joeedh/source/blender/render/intern/source/strand.c
    branches/soc-2007-joeedh/source/blender/render/intern/source/zbuf.c
    branches/soc-2007-joeedh/source/blender/render/intern/source/zbuf_dsm.c

Modified: branches/soc-2007-joeedh/source/blender/blenkernel/BKE_bucketbuffer.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/BKE_bucketbuffer.h	2008-12-12 10:55:36 UTC (rev 17799)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/BKE_bucketbuffer.h	2008-12-12 11:33:15 UTC (rev 17800)
@@ -36,6 +36,8 @@
 	struct RE_BucketEntry *next;
 	int obi[MAX_BUCKETENTRY];
 	int nr[MAX_BUCKETENTRY];
+	int seg[MAX_BUCKETENTRY]; //for strands
+	float z[MAX_BUCKETENTRY];
 	int used;
 } RE_BucketEntry;
 

Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c	2008-12-12 10:55:36 UTC (rev 17799)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c	2008-12-12 11:33:15 UTC (rev 17800)
@@ -284,9 +284,18 @@
 			x2 = x % buf->tsizex;
 			y2 = y % buf->tsizey;
 
-			if (tile->r_rect[y2*tile->sizex+x2] != -1) maxsamples[0] = MAX(maxsamples[0], tile->funcarray[tile->r_rect[y2*tile->sizex+x2]].totsamples);
-			if (tile->g_rect[y2*tile->sizex+x2] != -1) maxsamples[1] = MAX(maxsamples[1], tile->funcarray[tile->g_rect[y2*tile->sizex+x2]].totsamples);
-			if (tile->b_rect[y2*tile->sizex+x2] != -1) maxsamples[2] = MAX(maxsamples[2], tile->funcarray[tile->b_rect[y2*tile->sizex+x2]].totsamples);
+			if (tile->r_rect[y2*tile->sizex+x2] != -1) 
+				maxsamples[0] = MAX(maxsamples[0], 
+				tile->funcarray[tile->r_rect[y2*tile->sizex+x2]].totsamples);
+				
+			if (tile->g_rect[y2*tile->sizex+x2] != -1) 
+				maxsamples[1] = MAX(maxsamples[1], 
+				tile->funcarray[tile->g_rect[y2*tile->sizex+x2]].totsamples);
+
+			if (tile->b_rect[y2*tile->sizex+x2] != -1) 
+				maxsamples[2] = MAX(maxsamples[2], 
+				tile->funcarray[tile->b_rect[y2*tile->sizex+x2]].totsamples);
+
 			TCS_UnlockTile(tile);
 		}
 	}
@@ -297,9 +306,12 @@
 			x2 = x % buf->tsizex;
 			y2 = y % buf->tsizey;
 
-			if (tile->r_rect[y2*tile->sizex+x2] != -1) arect[(y*sx+x)*4] = (float)tile->funcarray[tile->r_rect[y2*tile->sizex+x2]].totsamples / (float)maxsamples[0];
-			if (tile->g_rect[y2*tile->sizex+x2] != -1) arect[(y*sx+x)*4+1] = (float)tile->funcarray[tile->g_rect[y2*tile->sizex+x2]].totsamples / (float)maxsamples[1];
-			if (tile->b_rect[y2*tile->sizex+x2] != -1) arect[(y*sx+x)*4+2] = (float)tile->funcarray[tile->b_rect[y2*tile->sizex+x2]].totsamples / (float)maxsamples[2];
+			if (tile->r_rect[y2*tile->sizex+x2] != -1) 
+				arect[(y*sx+x)*4] = (float)tile->funcarray[tile->r_rect[y2*tile->sizex+x2]].totsamples / (float)maxsamples[0];
+			if (tile->g_rect[y2*tile->sizex+x2] != -1) 
+				arect[(y*sx+x)*4+1] = (float)tile->funcarray[tile->g_rect[y2*tile->sizex+x2]].totsamples / (float)maxsamples[1];
+			if (tile->b_rect[y2*tile->sizex+x2] != -1) 
+				arect[(y*sx+x)*4+2] = (float)tile->funcarray[tile->b_rect[y2*tile->sizex+x2]].totsamples / (float)maxsamples[2];
 			arect[(y*sx+x)*4+3] = 1.0f;
 
 			TCS_UnlockTile(tile);
@@ -320,7 +332,7 @@
 	DeepThreadData thread_data[BLENDER_MAX_THREADS];
 	float fac, shbview[4][4], review[4][4], mat[4][4];
 	int x, y, lastsizex, lastsizey, stop=0, done=0, lastdone=0;
-	int mergescratchlen, lay = (1<<20)-1;
+	int mergescratchlen, lay = (1<<20)-1; //fix lay
 	char rendertitle[300];
 	rendertitle[0] = 0;
 	
@@ -335,12 +347,16 @@
 	
 	if (G.rt==71)
 		dbuf->max_depth = 2000*6;
+	else if (G.rt==72)
+		dbuf->max_depth = 112*6;
 	else
 		dbuf->max_depth = 30000*6;
 
 	dbuf->max_layers = 0;
 	
-	mergescratchlen = sizeof(_ClrEntry) > sizeof(DSMLayerSample) ? sizeof(_ClrEntry)*dbuf->max_depth : sizeof(DSMLayerSample)*dbuf->max_depth;
+	mergescratchlen = sizeof(_ClrEntry) > sizeof(DSMLayerSample) ? 
+		          sizeof(_ClrEntry)*dbuf->max_depth : 
+			  sizeof(DSMLayerSample)*dbuf->max_depth;
 	
 	for (x=0; x<re->r.threads; x++) {
 		dbuf->s1[x] = MEM_mapallocN(mergescratchlen, "dbuf->s1");
@@ -929,7 +945,9 @@
 	zbuffer_dsm(re, &pa, projmat, (APixstr**)dbuf->lastbuf[threadnr], 
 	           (APixstr**)dbuf->lastbufstrand[threadnr], APixbuf, 
 	            APixbufstrand, &apsmbase, lay, shb, btile, sscache);
-
+	
+	printf("zbuffer done.\n");
+	
 	if (pa.clipflag) MEM_freeN(pa.clipflag);
 
 	aprect= APixbuf;

Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/strand.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/strand.c	2008-12-12 10:55:36 UTC (rev 17799)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/strand.c	2008-12-12 11:33:15 UTC (rev 17800)
@@ -79,6 +79,8 @@
 	return ((1.0f-fac)*ma->strand_sta + (fac)*ma->strand_end);
 }
 
+//#define fast_sqrt(s) {int _i; float x=s/2.0f; for (_i=0; _i<5; _i++) { x = (s/x+x)/2.0; } s = x;}
+#if 0
 void strand_eval_point(StrandSegment *sseg, StrandPoint *spoint)
 {
 	Material *ma;
@@ -179,7 +181,109 @@
 
 	VECCOPY(spoint->dsco, cross);
 }
+#endif
 
+void strand_eval_point(StrandSegment *sseg, StrandPoint *spoint)
+{
+	Material *ma;
+	StrandBuffer *strandbuf;
+	float *simplify;
+	float p[4][3], data[4], cross[3], crosslen, w, dx, dy, t;
+	int type;
+
+	strandbuf= sseg->buffer;
+	ma= sseg->buffer->ma;
+	t= spoint->t;
+	type= (strandbuf->flag & R_STRAND_BSPLINE)? KEY_BSPLINE: KEY_CARDINAL;
+
+	VECCOPY(p[0], sseg->v[0]->co);
+	VECCOPY(p[1], sseg->v[1]->co);
+	VECCOPY(p[2], sseg->v[2]->co);
+	VECCOPY(p[3], sseg->v[3]->co);
+
+	if(sseg->obi->flag & R_TRANSFORMED) {
+		Mat4MulVecfl(sseg->obi->mat, p[0]);
+		Mat4MulVecfl(sseg->obi->mat, p[1]);
+		Mat4MulVecfl(sseg->obi->mat, p[2]);
+		Mat4MulVecfl(sseg->obi->mat, p[3]);
+	}
+
+	if(t == 0.0f) {
+		VECCOPY(spoint->co, p[1]);
+		spoint->strandco= sseg->v[1]->strandco;
+
+		spoint->dtstrandco= (sseg->v[2]->strandco - sseg->v[0]->strandco);
+		if(sseg->v[0] != sseg->v[1])
+			spoint->dtstrandco *= 0.5f;
+	}
+	else if(t == 1.0f) {
+		VECCOPY(spoint->co, p[2]);
+		spoint->strandco= sseg->v[2]->strandco;
+
+		spoint->dtstrandco= (sseg->v[3]->strandco - sseg->v[1]->strandco);
+		if(sseg->v[3] != sseg->v[2])
+			spoint->dtstrandco *= 0.5f;
+	}
+	else {
+		set_four_ipo(t, data, type);
+		spoint->co[0]= data[0]*p[0][0] + data[1]*p[1][0] + data[2]*p[2][0] + data[3]*p[3][0];
+		spoint->co[1]= data[0]*p[0][1] + data[1]*p[1][1] + data[2]*p[2][1] + data[3]*p[3][1];
+		spoint->co[2]= data[0]*p[0][2] + data[1]*p[1][2] + data[2]*p[2][2] + data[3]*p[3][2];
+		spoint->strandco= (1.0f-t)*sseg->v[1]->strandco + t*sseg->v[2]->strandco;
+	}
+
+	set_afgeleide_four_ipo(t, data, type);
+	spoint->dtco[0]= data[0]*p[0][0] + data[1]*p[1][0] + data[2]*p[2][0] + data[3]*p[3][0];
+	spoint->dtco[1]= data[0]*p[0][1] + data[1]*p[1][1] + data[2]*p[2][1] + data[3]*p[3][1];
+	spoint->dtco[2]= data[0]*p[0][2] + data[1]*p[1][2] + data[2]*p[2][2] + data[3]*p[3][2];
+
+	VECCOPY(spoint->tan, spoint->dtco);
+	Normalize(spoint->tan);
+
+	VECCOPY(spoint->nor, spoint->co);
+	VECMUL(spoint->nor, -1.0f);
+	Normalize(spoint->nor);
+
+	spoint->width= strand_eval_width(ma, spoint->strandco);
+	
+	/* simplification */
+	simplify= RE_strandren_get_simplify(strandbuf->obr, sseg->strand, 0);
+	spoint->alpha= (simplify)? simplify[1]: 1.0f;
+
+	/* outer points */
+	Crossf(cross, spoint->co, spoint->tan);
+
+	w= spoint->co[2]*strandbuf->winmat[2][3] + strandbuf->winmat[3][3];
+	dx= strandbuf->winx*cross[0]*strandbuf->winmat[0][0]/w;
+	dy= strandbuf->winy*cross[1]*strandbuf->winmat[1][1]/w;
+	w= sqrt(dx*dx + dy*dy);
+
+	if(w > 0.0f) {
+		if(strandbuf->flag & R_STRAND_B_UNITS) {
+			crosslen= VecLength(cross);
+			w= 2.0f*crosslen*strandbuf->minwidth/w;
+
+			if(spoint->width < w) {
+				spoint->alpha= spoint->width/w;
+				spoint->width= w;
+			}
+
+			if(simplify)
+				/* squared because we only change width, not length */
+				spoint->width *= simplify[0]*simplify[0];
+
+			VecMulf(cross, spoint->width*0.5f/crosslen);
+		}
+		else
+			VecMulf(cross, spoint->width/w);
+	}
+
+	VecSubf(spoint->co1, spoint->co, cross);
+	VecAddf(spoint->co2, spoint->co, cross);
+
+	VECCOPY(spoint->dsco, cross);
+}
+
 /* *************** */
 
 static void interpolate_vec1(float *v1, float *v2, float t, float negt, float *v)
@@ -534,7 +638,7 @@
 			t = u*spart->t[0] + v*spart->t[1] + (1.0f-u-v)*spart->t[2];
 			s = fabs(u*spart->s[0] + v*spart->s[1] + (1.0f-u-v)*spart->s[2]);
 
-			apn= spart->apixbuf + offset;
+			apn = spart->apixbuf + offset;
 			while(apn) {
 				if (spart->shadow_mode == 0) {
 					CHECK_ADD(0);
@@ -560,6 +664,7 @@
 	}
 }
 
+
 static int strand_test_clip(float winmat[][4], ZSpan *zspan, float *bounds, float *co, float *zcomp)
 {
 	float hoco[4];

Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/zbuf.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/zbuf.c	2008-12-12 10:55:36 UTC (rev 17799)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/zbuf.c	2008-12-12 11:33:15 UTC (rev 17800)
@@ -1432,13 +1432,15 @@
 #undef BUCKET_ADD
 #endif
 
-#define BUCKET_ADD(_tile, _first, _last, _nr, _obi, _totentries)\
+#define BUCKET_ADD(_tile, _first, _last, _nr, _obi, _totentries, z, seg1)\
 if (!_first || (_last && (_last->used >= MAX_BUCKETENTRY))) {\
 		if (!_first) {\
 			_first = _last = MEM_mallocN(sizeof(RE_BucketEntry), "new bucket entry");\
 			_first->used = 1;\
 			_first->nr[0] = _nr;\
 			_first->obi[0] = _obi;\
+			_first->z[0] = z;\
+			_first->seg[0] = seg1;\
 			_first->next = NULL;\
 			TCS_AdjustTileMemSize(_tile, sizeof(RE_BucketEntry));\
 			_totentries++;\
@@ -1448,13 +1450,17 @@
 			_last->next = NULL;\
 			_last->used = 1;\
 			_last->nr[0] = _nr;\
+			_last->seg[0] = seg1;\
 			_last->obi[0] = _obi;\
+			_last->z[0] = z;\
 			TCS_AdjustTileMemSize(_tile, sizeof(RE_BucketEntry));\
 			_totentries++;\
 		}\
 } else {\
 	_last->nr[_last->used] = _nr;\
 	_last->obi[_last->used] = _obi;\
+	_last->z[_last->used] = z;\
+	_last->seg[_last->used] = seg1;\
 	_last->used++;\
 	_totentries++;\
 }
@@ -1506,6 +1512,93 @@
 	return clipflag;
 }
 
+//,
+#define V_DECLARE(vec) int _##vec##_count=0; void *_##vec##_tmp
+#define V_SIZE(vec) ((vec)==NULL ? 0 : MEM_allocN_len(vec) / sizeof(*vec))
+#define V_COUNT(vec) _##vec##_count
+#define MSTR(s) #s
+#define V_GROW(vec) \
+	V_SIZE(vec) > _##vec##_count ? _##vec##_count++ : \
+	((_##vec##_tmp = MEM_callocN(sizeof(*vec)*(_##vec##_count*_##vec##_count+2), #vec " " __FILE__ " ")),\

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list