[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15655] branches/soc-2007-joeedh/source/ blender: bilinear interpolation of dsm shadows now works.

Joseph Eagar joeedh at gmail.com
Sun Jul 20 18:35:21 CEST 2008


Revision: 15655
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15655
Author:   joeedh
Date:     2008-07-20 18:35:21 +0200 (Sun, 20 Jul 2008)

Log Message:
-----------
bilinear interpolation of dsm shadows now works.
also, linear z is on by default (produces less biasing
issues, though it's acting a little oddly at the moment).

also limited the soft button in the UI to 3.0, since
in DSM context soft is just the anti-aliasing filter
width, not the shadow softness (once the soft shadow
code works, it'll use the same area light settings
that ray shadows use for controlling the soft size).

also did some minor code cleanups.

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/src/buttons_shading.c

Modified: branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h	2008-07-20 16:21:21 UTC (rev 15654)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h	2008-07-20 16:35:21 UTC (rev 15655)
@@ -92,14 +92,11 @@
 	void *s3[BLENDER_MAX_THREADS], *s4[BLENDER_MAX_THREADS];
 } DSMBuffer;
 
-//32 16 8 4 2 1
 #define MAX_SAMPLELAYERS		32
 
 #define DSM_FINAL_TILESIZE		32
-//#define DSM_FINAL_MAXSAMPLES	2000
-
 #define DSM_TILE_MEMARENASIZE	(1<<16)
-#define DSM_AASAMPLES		(shb->samp > 5? 5: shb->samp) //(G.rt>8 ? 1 : (G.rt==0 ? 1 : G.rt))
+#define DSM_AASAMPLES		(shb->samp > 5? 5: shb->samp)
 #define DSM_AAWIDTH			(shb->soft > 3? 3: shb->soft)
 #define DSM_MAXSAMPLES		25
 
@@ -111,7 +108,7 @@
 
 /*little bit smaller memarena buffer size for the final diced
   32x32 tiles*/
-#define DSM_TILE_FINALMEMARENASIZE (1<<16)
+#define DSM_TILE_FINALMEMARENASIZE (1<<15)
 
 void _DSM_maketile(TCS_TileBuffer *self, TCS_TilePool *pool, TCS_Tile *vtile);
 void DSM_MakeTilePool(int maxbytes);

Modified: branches/soc-2007-joeedh/source/blender/render/intern/include/shadbuf.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/include/shadbuf.h	2008-07-20 16:21:21 UTC (rev 15654)
+++ branches/soc-2007-joeedh/source/blender/render/intern/include/shadbuf.h	2008-07-20 16:35:21 UTC (rev 15655)
@@ -73,8 +73,10 @@
 
 void DSM_getSoftShadow(ShadBuf *shb, struct ShadeInput *shi, LampRen *lar, 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_FreeBuffer(DSMBuffer *dbuf);
+float DSM_getBilinearShadow(ShadBuf *shb, float *rco, float *dxco, float *dyco, float inp, int component);
+float DSM_sampleMap(ShadBuf *shb, int xs, int ys, int zs, int bias, float inp, int component);
 
+
 /**
  * Irregular shadowbuffer
  */

Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c	2008-07-20 16:21:21 UTC (rev 15654)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c	2008-07-20 16:35:21 UTC (rev 15655)
@@ -229,94 +229,8 @@
 	}
 }
 
-/*original cameraspace-to-lampspace function the envmap code uses,
-  for some reason simply does not work for DSM.*/
-#if 0
-static void _retransform_renderscene(Render *re, float mat[4][4], float oldview[4][4], ShadBuf *shb, int mode)
-{
-//static void env_rotate_scene(Render *re, float mat[][4], int mode)
-	GroupObject *go;
-	ObjectRen *obr;
-	ObjectInstanceRen *obi;
-	LampRen *lar = NULL;
-	HaloRen *har = NULL;
-	float imat[3][3], pmat[4][4], smat[4][4], tmat[4][4], cmat[3][3], oldviewinv[4][4];
-	int a;
-
-	MTC_Mat4Invert(oldviewinv, oldview);
-	MTC_Mat4MulMat4(mat, oldviewinv, mat);
-
-	if(mode==0) {
-		MTC_Mat4Invert(tmat, mat);
-		MTC_Mat3CpyMat4(imat, tmat);
-	}
-	else {
-		MTC_Mat4CpyMat4(tmat, mat);
-		MTC_Mat3CpyMat4(imat, mat);
-	}
-
-	for(obi=re->instancetable.first; obi; obi=obi->next) {
-		/* append or set matrix depending on dupli */
-		if(obi->flag & R_DUPLI_TRANSFORMED)
-			Mat4MulMat4(obi->mat, tmat, obi->mat);
-		else if(mode==1)
-			Mat4CpyMat4(obi->mat, tmat);
-		else
-			Mat4One(obi->mat);
-
-		Mat3CpyMat4(cmat, obi->mat);
-		Mat3Inv(obi->imat, cmat);
-
-		/* indicate the renderer has to use transform matrices */
-		if(mode==0)
-			obi->flag &= ~R_ENV_TRANSFORMED;
-		else
-			obi->flag |= R_ENV_TRANSFORMED;
-	}
-	
-
-	for(obr=re->objecttable.first; obr; obr=obr->next) {
-		for(a=0; a<obr->tothalo; a++) {
-			if((a & 255)==0) har= obr->bloha[a>>8];
-			else har++;
-		
-			MTC_Mat4MulVecfl(tmat, har->co);
-		}
-	}
-	
-#if 0
-	for(go=re->lights.first; go; go= go->next) {
-		lar= go->lampren;
-		
-		/* removed here some horrible code of someone in NaN who tried to fix
-		   prototypes... just solved by introducing a correct cmat[3][3] instead
-		   of using smat. this works, check square spots in reflections  (ton) */
-		Mat3CpyMat3(cmat, lar->imat); 
-		Mat3MulMat3(lar->imat, cmat, imat); 
-
-		MTC_Mat3MulVecfl(imat, lar->vec);
-		MTC_Mat4MulVecfl(tmat, lar->co);
-
-		lar->sh_invcampos[0]= -lar->co[0];
-		lar->sh_invcampos[1]= -lar->co[1];
-		lar->sh_invcampos[2]= -lar->co[2];
-		MTC_Mat3MulVecfl(lar->imat, lar->sh_invcampos);
-		lar->sh_invcampos[2]*= lar->sh_zfac;
-		
-		if(lar->shb && lar->shb != shb) {
-			if(mode==1) {
-				MTC_Mat4Invert(pmat, mat);
-				MTC_Mat4MulMat4(smat, pmat, lar->shb->viewmat);
-				MTC_Mat4MulMat4(lar->shb->persmat, smat, lar->shb->winmat);
-			}
-			else MTC_Mat4MulMat4(lar->shb->persmat, lar->shb->viewmat, lar->shb->winmat);
-		}
-	}
-#endif
-
-}	
-#endif
-
+/*this function not based off the envmap equavilent env_rotate_scene, 
+  which turned out not to work at all for the purpose, for some reason*/
 static void retransform_renderscene(Render *re, float newview[4][4], float oldview[4][4], ShadBuf *buf, int mode)
 {
 	VlakRen *vlak;
@@ -1305,117 +1219,6 @@
 	return totface;
 }
 
-/* color 'shadfac' passes through 'col' with alpha and filter */
-/* filter is only applied on alpha defined transparent part */
-static void addAlphaLight(float *shadfac, float *col, float alpha, float filter)
-{
-	float fr, fg, fb;
-	
-	fr= 1.0f+ filter*(col[0]-1.0f);
-	fg= 1.0f+ filter*(col[1]-1.0f);
-	fb= 1.0f+ filter*(col[2]-1.0f);
-	
-	shadfac[0]= alpha*col[0] + fr*(1.0f-alpha)*shadfac[0];
-	shadfac[1]= alpha*col[1] + fg*(1.0f-alpha)*shadfac[1];
-	shadfac[2]= alpha*col[2] + fb*(1.0f-alpha)*shadfac[2];
-	
-	shadfac[3]= (1.0f-alpha)*shadfac[3];
-}
-
-/*cindex is component index, since all transmittance functions for r, g, and b
-  are squased into only one input stream.*/
-DSMFunction *DSM_MergeLayerListNoWeight(MemArena *arena, _ClrEntry *row, ListBase (*transfuncs)[3], 
-								int totface,char *scratchmem, int scratchlen, float *weight, 
-								int samplewid,float error, int cindex)
-{
-	DSMFunction *func;
-	DSMLayerSample *samp;
-	_ClrEntry *csamp, *lastcsamp=NULL;
-	double slope, accum, s1, s2;
-	int i;
-
-	func = BLI_memarena_alloc(arena, sizeof(DSMFunction));
-	func->samples = samp = (DSMLayerSample*) scratchmem;
-	func->totsamples = 0;
-	func->zmin = 0x7FFFFFFF;
-	func->zmax = -0x7FFFFFFF;
-
-	accum = 1.0;
-	slope = 0.0;
-	samp=func->samples;
-	for (i=0, csamp=row; i<totface; i++, csamp++, samp++) {
-		/*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->index != cindex || !csamp->srclist) {
-			samp--;
-			continue;
-		}
-		
-		samp->orig_totsamples = 0;
-		samp->depth = csamp->depth;
-		if (samp->depth > func->zmax) func->zmax = samp->depth;
-		if (samp->depth < func->zmin) func->zmin = samp->depth;
-
-		if (lastcsamp) accum = accum + (double)(csamp->depth-lastcsamp->depth)*slope;
-		samp->value = (float) accum;
-		
-		if (csamp->next && csamp->next->depth == csamp->depth) {
-			accum += (csamp->next->value-csamp->value); //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 += (s2 - s1); //weight[csamp->samplenr]*(s2 - s1);
-					} else {
-						slope += s2; //weight[csamp->samplenr]*s2;
-					}
-				} else {
-					slope += s2; //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 -= s1; //weight[csamp->samplenr]*s1;
-				}
-			}
-		} else {
-			if (csamp->prev) {
-				if (csamp->prev->depth == csamp->depth) {
-					//accum += weight[csamp->samplenr]*(csamp->value-csamp->prev->value);
-				} else {
-					s1 = ((double)(csamp->value - csamp->prev->value)) / (double)(csamp->depth - csamp->prev->depth);
-					slope -= s1; //weight[csamp->samplenr]*s1;
-				}
-			}			
-		}
-
-		if (accum < -0.001f) {
-			//printf("EVIL! accum: %f\n", accum);
-			accum = 0.0f;
-		}
-		else if (accum > 1.001f) {
-			//printf("EVIL 2! accum: %f\n", accum);
-			accum = 1.0f;
-		}
-
-		lastcsamp = csamp;
-		func->totsamples++;
-	}
-	
-	BASSERT(accum < 1.0001);
-	
-	/*note:  this function is where samples move to their final place,
-	  allocated in the tile's memarena.*/
-	DSM_CompressFunction(arena, func, error);
-
-	return func;
-}
-
 /* returns a mask, only if a) transp rendered and b) solid was rendered */
 void DSM_DoTile(Render *re, float projmat[4][4], ShadBuf *shb, DSMTile *tile, 
 				DSMBuffer *dbuf, RE_BucketTile *btile, int threadnr, float viewinv[4][4])
@@ -1714,22 +1517,10 @@
 									accum[row[a].samplenr][b] *= (1.0f - mat->shad_alpha);
 								} else {
 									fac= 1.0f + mat->filter*(clr[b]-1.0f);
-									//fac = clr[3]*clr[b] + fac*(1.0f-clr[3])*accum[row[a].samplenr][b];
 									fac = clr[3]*clr[b] + fac*(1.0f-clr[3]);
 									accum[row[a].samplenr][b] *= (1.0f-clr[3])*fac;
-									//
-									//accum[row[a].samplenr][b] *= 1.0f - clr[3];
-									//accum[row[a].samplenr][b] *= 1.0 - (1.0 - clr[3])*clr[b];
-									//accum[row[a].samplenr][b] *= 1.0 - clr[3]*(1.0 - clr[b]);
-
-									//addAlphaLight(accum[row[a].samplenr][b], clr, clr[3], mat->filter);
 								}
-							}/* not needed I think, since accum should already
-							    have the previous value it needs.
-							 else {
-								accum[row[a].samplenr][b] = row[a].prev->value;
-							}*/
-
+							}
 							row[a].value = accum[row[a].samplenr][b];
 
 							samp_totfaces[row[a].samplenr]++;
@@ -2569,14 +2360,98 @@
 
 //float *dsm_bsearch(DSMSample *sample, int zs, int bias);
 
+float DSM_getBilinearShadow(ShadBuf *shb, float *rco, float *dxco, float *dyco, float inp, int component)
+{
+	DSMBuffer *buf = shb->dsmbuffer;
+	float fac, co[4], d, siz, alpha; //, *clr; //*jit, *weight, *rz,  note: these three might be needed, look into it
+	float xs, ys, a, b, res;
+	int zs, bias, newbias, tilex, tiley, i;
+	float corners[4];
+
+	BASSERT(shb->dsmbuffer);
+
+	if(inp <= 0.0f) return 0.0f;
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list