[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12370] branches/soc-2007-joeedh/source/ blender: Work-in-progress commit (I've decided to follow Genscher' s example :) ).

Joseph Eagar joeedh at gmail.com
Wed Oct 24 09:27:07 CEST 2007


Revision: 12370
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12370
Author:   joeedh
Date:     2007-10-24 09:27:06 +0200 (Wed, 24 Oct 2007)

Log Message:
-----------
Work-in-progress commit (I've decided to follow Genscher's example :) ).
The code doesn't really work at the moment.

This commit adds bucketing (which works) and soft shadows with dsm (which
 doesn't, dsm shadows don't render at all).

There's some evil error where a point within the lamp camera's viewing
 frustum is somehow being projected with a final z value way outside the 0.
 . .1 homogonous range (usually greater then 10).  If anyone knows why this
 could happen, please speak up!

Joe

Modified Paths:
--------------
    branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h
    branches/soc-2007-joeedh/source/blender/render/intern/include/shadbuf.h
    branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c
    branches/soc-2007-joeedh/source/blender/render/intern/source/shadeoutput.c
    branches/soc-2007-joeedh/source/blender/render/intern/source/zbuf.c

Modified: branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h	2007-10-24 06:08:00 UTC (rev 12369)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h	2007-10-24 07:27:06 UTC (rev 12370)
@@ -15,6 +15,13 @@
 
 #define MAX_DSMLAYERS	16
 
+/*the entire tree for a tile can be allocated at once,
+  since tiles are set at um either 16x16 or 64x64. */
+typedef struct DSMFuncQuadTree {
+	int zenter, zexit;
+	struct DSMFuncQuadTree *nodes[4];
+} DSMFuncQuadTree;
+
 /*ok heres how it works.  A "layer"
   is the total number of samples going from light
   energy 1.0 to 0.0, then repeating.*/
@@ -76,8 +83,10 @@
 } DSMBuffer;
 
 #define MAX_SAMPLELAYERS	32
-#define DSM_FINAL_TILESIZE	32
+#define DSM_FINAL_TILESIZE	52
 #define DSM_TILE_MEMARENASIZE	(1<<18)
+#define DSM_AASAMPLES		2
+#define DSM_AAWIDTH			3.0f
 
 /*little bit smaller memarena buffer size for the final diced
   25x25 tiles*/

Modified: branches/soc-2007-joeedh/source/blender/render/intern/include/shadbuf.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/include/shadbuf.h	2007-10-24 06:08:00 UTC (rev 12369)
+++ branches/soc-2007-joeedh/source/blender/render/intern/include/shadbuf.h	2007-10-24 07:27:06 UTC (rev 12370)
@@ -73,6 +73,7 @@
  * Deep Shadow Buffer
  */
 
+void DSM_getSoftShadow(ShadBuf *shb, float *rco, float *dxco, float *dyco, float inp, float *shadowclr);
 float DSM_getShadow(ShadBuf *buf, float *rco, float *dxco, float *dyco, float inp, int component);
 void DSM_CreateBuffer(Render *re, ShadBuf *buf, int tilesize);
 void DSM_FreeBuffer(DSMBuffer *dbuf);

Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c	2007-10-24 06:08:00 UTC (rev 12369)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c	2007-10-24 07:27:06 UTC (rev 12370)
@@ -33,6 +33,7 @@
 #include <string.h>
 
 #include "BLI_arithb.h"
+#include "MTC_matrixops.h"
 #include "BLI_blenlib.h"
 #include "BLI_threads.h"
 #include "BLI_jitter.h"
@@ -77,6 +78,11 @@
 static void freepsA(ListBase *lb);
 static APixstr *addpsA(ZSpan *zspan);
 
+/* Modified zbufclipwire from zbuf.c
+  v1 and v2 are in homogenous coordinates.  returns true if 
+  drawing should happen.  v1 and v2 are modified (clipped).*/
+int DSM_zbufclipwire(int rectx, int recty, float *v1, float *v2);
+
 void DSM_MakeTilePool(int maxbytes)
 {
 	deepbuffer_pool = TCS_MakePool(maxbytes, "dsm");
@@ -210,25 +216,159 @@
 	return buckets;
 }
 
+#if 0
+DSMBuffer *DSM_DiceBuffeR(DSMBuffer *oldbuf, int size, int tilesize, TCS_TilePool *pool)
+{
+	DSMBuffer *dbuf = MEM_mapallocN(sizeof(DSMBuffer), "DSMBuffer");
+	DSMTile *oldtile, *newtile;
+	float fac;
+	int x, y, x2, y2, rfac;
+
+	if (tilesize > size) tilesize = size;
+
+	TCS_InitBuffer(&TCS_DeepShadowBuffer, dbuf);
+
+	dbuf->max_depth = 30000*6;
+	dbuf->tsizex = dbuf->tsizey = tilesize;
+	dbuf->sizex = dbuf->sizey = size;
+	dbuf->tilex = dbuf->tiley = size / tilesize;
+	
+	/*add extra tiles if necassary.
+
+	  python tests indicated the + 0.000001 is needed; I have no idea why,
+	  some sort of numerical error I assume.  of course python uses doubles and
+	  not floats, but I rather doubt that floats are going to behave any better.*/
+	fac = ((float)buf->size/(float)tilesize) + 0.0000001;
+
+	if ((int)((fac - (int)fac)*(float)tilesize) > 0.000001) {
+		dbuf->tilex += 1;
+		dbuf->tiley += 1;
+	}
+
+	dbuf->vfunc_rect = MEM_mapallocN(sizeof(DSMTile)*dbuf->tilex*dbuf->tiley, "dsm tiles");
+
+	for (y=0; y<dbuf->tiley; y++) {
+		for (x=0; x<dbuf->tilex; x++) {
+			newtile = &dbuf->vfunc_rect[y*dbuf->tilex+x];
+			
+			/*right and top border tiles arn't always the same size as the others*/
+			if (x == dbuf->tilex-1) newtile->sizex = dbuf->sizex - dbuf->tsizex*x; //dbuf->sizex - dbuf->tsizex*(x-1); //tilesize - (tilesize*x - dbuf->sizex);
+			else newtile->sizex = dbuf->tsizex;
+
+			if (y == dbuf->tiley-1) newtile->sizey = dbuf->sizey - dbuf->tsizey*y;//tilesize - (tilesize*y - dbuf->sizey);
+			else newtile->sizey = dbuf->tsizey;
+
+			newtile->x = x;
+			newtile->y = y;
+
+			newtile->arena = BLI_memarena_new(DSM_TILE_MEMARENASIZE); /*FIXMEGREP: tweak this to find optimal value.*/
+			BLI_memarena_use_mapalloc(newtile->arena);
+			newtile->r_rect = BLI_memarena_alloc(newtile->arena, sizeof(void*)*newtile->sizex*newtile->sizey);
+			newtile->g_rect = BLI_memarena_alloc(newtile->arena, sizeof(void*)*newtile->sizex*newtile->sizey);
+			newtile->b_rect = BLI_memarena_alloc(newtile->arena, sizeof(void*)*newtile->sizex*newtile->sizey);
+			
+			_DSM_maketile((TCS_TileBuffer*)dbuf, pool, (TCS_Tile*)newtile);
+		}
+	}
+
+	for (y=0; y<oldbuf->tiley; y++) {
+		for (x=0; x<oldbuf->tilex; x++) {
+			int bx1, bx2, by1, by2;
+
+			oldtile = oldbuf->vfunc_rect[y*oldbuf->tilex+x];
+
+			/*make sure oldtile is not cached*/
+			TCS_GetTile(oldbuf, oldtile->x, oldtile->y, 0);
+
+			/*calculate which boundbox range of new tiles intersects the current one*/
+			bx1 = oldtile->x*oldbuf->tsizex / tilesize;
+			by1 = oldtile->y*oldbuf->tsizey / tilesize;
+			bx2 = (oldtile->x*oldbuf->tsizex+oldtile->sizex) / tilesize;
+			by2 = (oldtile->y*oldbuf->tsizey+oldtile->sizey) / tilesize;
+
+			for (y2=by1; y2<by2; y2++) {
+				for (x2=bx1; x2<bx2; x2++) {
+					/*bounding box of intersecting pixels, relative to newtile*/
+					int nx1, nx2, ny1, ny2;
+					/*bounding box of intersecting pixels, relative to oldtile*/
+					int ox1, ox2, oy1, oy2;
+					/*iterators*/
+					int x3, y3;
+
+					newtile = &dbuf->vfunc_rect[y2*dbuf->tilex+x2];
+					
+					/*make sure newtile is not cached*/
+					TCS_GetTile(dbuf, newtile->x, newtile->y, 0);
+
+					/*first compute screen-space bounding box of newtile*/
+					nx1 = newtile->x*dbuf->tsizex;
+					ny1 = newtile->y*dbuf->tsizey;
+					nx2 = nx1 + newtile->sizex;
+					ny2 = ny1 + newtile->sizey;
+					
+					/*now compute screen-space bounding box of oldtile*/
+					ox1 = oldtile->x*oldbuf->tsizex;
+					oy1 = oldtile->y*oldbuf->tsizey;
+					ox2 = ox1 + oldtile->sizex;
+					oy2 = oy1 + oldtile->sizey;
+					
+					/*now intersect the two*/
+					if (nx1 < ox1) nx1 = ox1;
+					if (ny1 < oy1) ny1 = oy1;
+					if (nx2 > ox2) nx2 = ox2;
+					if (ny2 > oy2) ny2 = oy2;
+					
+					/*calculate local bounding box inside oldtile*/
+					ox1 = nx1 % oldbuf->tsizex;
+					oy1 = ny1 % oldbuf->tsizey;
+					ox2 = nx2 % oldbuf->tsizex;
+					oy2 = ny2 % oldbuf->tsizey;
+
+					/*calculate local bounding box inside newtile*/
+					nx1 = nx1 % dbuf->tsizex;
+					ny1 = ny1 % dbuf->tsizey;
+					nx2 = nx2 % dbuf->tsizex;
+					ny2 = ny2 % dbuf->tsizey;
+
+					/*now copy pixels*/
+					for (y3=ny1; y3<ny2; y3++) {
+						for (x3=nx1; x3<nx2; x3++) {
+							DSMFunction *func;
+							func = &oldtile->r_rect[y3*oldtile->sizex+x3];
+							newtile-> 
+						}
+					}
+				}
+			}
+		}
+	}
+}
+#endif /*#if 0*/
+
 void DSM_CreateBuffer(Render *re, ShadBuf *buf, int tilesize)
 {
 	DSMBuffer *dbuf = MEM_mapallocN(sizeof(DSMBuffer), "DSMBuffer");
 	DSMTile *tile;
 	float fac;
-	int x, y;
+	int x, y, rfac;
 
 	if (tilesize > buf->size) tilesize = buf->size;
+	
+	rfac = (int)(125.0f / (float)tilesize + 0.5f);
 
+	//if (rfac==0) rfac = 1;
+	//tilesize *= rfac;
+
 	TCS_InitBuffer(&TCS_DeepShadowBuffer, dbuf);
 
 	if (deepbuffer_pool == NULL) printf("oh EVVVIL!\n");
 
-	/*use 7500 max elements for the 2 preallocated
+	/*use 30,000 max elements per pixel for the 2 preallocated
 	  pixel arrays DSM_DoTile() allocates.  the *6
 	  iirc is because the visibilty function calculation
 	  kindof expands things (note this is usually more then
 	  compensated by the final visibility function compression).*/
-	dbuf->max_depth = 15500*6;
+	dbuf->max_depth = 30000*6;
 
 	dbuf->tsizex = dbuf->tsizey = tilesize;
 	dbuf->sizex = dbuf->sizey = buf->size;
@@ -249,7 +389,7 @@
 
 	dbuf->buckets = DSM_FillZbufferBuckets(re, dbuf->sizex, dbuf->sizey, 
 								    dbuf->tsizex, dbuf->tsizey, dbuf->tilex, 
-									dbuf->tiley, buf->soft, buf->soft);
+									dbuf->tiley, DSM_AAWIDTH*2.0, DSM_AAWIDTH*2.0);
 
 	dbuf->vfunc_rect = MEM_mapallocN(sizeof(DSMTile)*dbuf->tilex*dbuf->tiley, "dsm tiles");
 
@@ -332,8 +472,6 @@
 	double start, end, ostartpoint, oendpoint, startpoint = -1, endpoint = -1, err=error/2.0;
 	int totface=0, a=0, olda, count=0;
 	
-	//if (err==0) err = 0.001;
-
 	cursamp = func->samples;
 	
 	if (G.rt == 43) {
@@ -349,9 +487,11 @@
 		/*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;
-		}
+		//
+		//this is incremented further below now.
+		//if (a != 0) {
+		cursamp->orig_totsamples = 0;
+		//}
 
 		if (a == func->totsamples - 1) {
 			totface++;
@@ -389,11 +529,12 @@
 					if (samp[a].depth != cursamp->depth) {
 						end /= (double)(samp[a].depth - cursamp->depth);
 					}
-				}			
+				}	
 			} else {
 				a -= 1;
 				break;
 			}
+			cursamp->orig_totsamples++;
 			olda -= a;
 
 			a += 1;
@@ -744,12 +885,12 @@
 					  2 (since polygon samples are doubled) * 3 (since all samples are tripled for
 					   the different r, g, b visibility functions) 
 					 */
-					if(totface >= dbuf->max_depth/6 - buf->samp*buf->samp) break;
+					if(totface >= dbuf->max_depth/6 - DSM_AASAMPLES*DSM_AASAMPLES) break;
 					for(a=0; a<4; a++) {
 						/*we subtract the total number of subpixel samples because we
 						  need the space in the array to insert the starting-visibility-
 						  at-1 sample in each subpixel visibility function.*/
-						if(totface >= dbuf->max_depth/6 - buf->samp*buf->samp) break;
+						if(totface >= dbuf->max_depth/6 - DSM_AASAMPLES*DSM_AASAMPLES) break;
  
 						if(apn->p[a]) {
 							if (apn->z[a] < 0) {
@@ -768,7 +909,7 @@
 							row2[totface].value = 0.0f;
 							
 							totface++;
-							if(totface >= dbuf->max_depth/6 - buf->samp*buf->samp) break;
+							if(totface >= dbuf->max_depth/6 - DSM_AASAMPLES*DSM_AASAMPLES) break;
 						}
 						else break;
 					}
@@ -777,7 +918,7 @@
 
 				qsort(row2, totface, sizeof(_ClrEntry), dsmvergzvlak);
 
-				memset(lastsamples, 0, sizeof(void*)*buf->samp*buf->samp);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list