[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16211] branches/soc-2007-joeedh/source/ blender/render/intern/source: fix for somewhat embarresing threading bug introduced

Joseph Eagar joeedh at gmail.com
Thu Aug 21 21:10:32 CEST 2008


Revision: 16211
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16211
Author:   joeedh
Date:     2008-08-21 21:10:32 +0200 (Thu, 21 Aug 2008)

Log Message:
-----------
fix for somewhat embarresing threading bug introduced
when I added the option to only use the main thread
for rendering if threads is set to 1 (it's a #define'd
option the code for debugging purposes, as it doesn't work
quite as well).

Modified Paths:
--------------
    branches/soc-2007-joeedh/source/blender/render/intern/source/convertblender.c
    branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c
    branches/soc-2007-joeedh/source/blender/render/intern/source/dsm_soft.c
    branches/soc-2007-joeedh/source/blender/render/intern/source/pipeline.c
    branches/soc-2007-joeedh/source/blender/render/intern/source/rayshade.c

Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/convertblender.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/convertblender.c	2008-08-21 19:00:24 UTC (rev 16210)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/convertblender.c	2008-08-21 19:10:32 UTC (rev 16211)
@@ -3587,7 +3587,7 @@
 	
 	/* Annoying, lamp UI does this, but the UI might not have been used? - add here too.
 	 * make sure this matches buttons_shading.c's logic */
-	if(ELEM4(la->type, LA_AREA, LA_SPOT, LA_SUN, LA_LOCAL) && (la->mode & LA_SHAD_RAY))
+	if(ELEM4(la->type, LA_AREA, LA_SPOT, LA_SUN, LA_LOCAL))
 		if (ELEM3(la->type, LA_SPOT, LA_SUN, LA_LOCAL))
 			if (la->ray_samp_method == LA_SAMP_CONSTANT) la->ray_samp_method = LA_SAMP_HALTON;
 	

Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c	2008-08-21 19:00:24 UTC (rev 16210)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c	2008-08-21 19:10:32 UTC (rev 16211)
@@ -749,6 +749,7 @@
 							zco= ((float)apn->z[a])/2147483647.0f;
 							zco = (shb->winmat[3][2])/(shb->winmat[2][2] - shb->winmat[2][3]*zco);
 							zco = (zco - shb->clipsta) / (shb->clipend - shb->clipsta);
+
 							row2[totface].depth = 2147483647.0f*zco;
 							//if (zco < -0.001 || zco > 1.001) printf("linear z: %f\n", zco);
 						} else row2[totface].depth = apn->z[a];

Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/dsm_soft.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/dsm_soft.c	2008-08-21 19:00:24 UTC (rev 16210)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/dsm_soft.c	2008-08-21 19:10:32 UTC (rev 16211)
@@ -79,7 +79,125 @@
 extern Render R;
 static TCS_TilePool *deepbuffer_pool = NULL;
 
+#if 0
+/*backprojection based method*/
+float DSM_getBPSoftShadow(Render *re, ShadBuf *shb, ShadeInput *shi, LampRen *lar,
+						 float *rco, float *dxco, float *dyco, float inp, int channel)
+{
+	DSMBuffer *buf = shb->dsmbuffer;
+	DSMTile *tile;
+	DSMFunction *func;
+	DSMSampleLayer *samp, *startsamp=NULL;
+	float fac, co[4], co2[4], d, siz;
+	float xs, ys, a, b, res, worldz, startz;
+	int zs, bias, i;
+	float corners[4];
 
+	BASSERT(shb->dsmbuffer);
+
+	if(inp <= 0.0f) return 0.0f;
+
+	/* rotate renderco en osaco */
+	siz= 0.5f*(float)shb->size;
+
+	VECCOPY(co, rco);
+	VECCOPY(co4, rco;
+
+	co4[3] = 1.0f;
+	co[3]= 1.0f;
+	MTC_Mat4MulVec4fl(shb->persmat, co); /* rational hom co */
+	MTC_Mat4MulVec4fl(shb->viewmat, co4); /* used for getting world-space depth */
+	
+	worldz = co4[2];
+
+	xs= siz*(1.0f+co[0]/co[3]);
+	ys= siz*(1.0f+co[1]/co[3]);
+
+	/* Clip for z: clipsta and clipend clip values of the shadow buffer. We
+		* can test for -1.0/1.0 because of the properties of the
+		* coordinate transformations. */
+
+	if (G.rt == 20) d = -0.0f;
+	else d = -1.0f;
+
+	if (G.rt == 30) {
+		if (co[2] - shb->clipsta < -0.00001f) return 1.0;
+		else if (co[2] > shb->clipend) co[2] = shb->clipend - 0.001;
+
+		fac= (double)(co[2] - shb->clipsta) / (double)(shb->clipend - shb->clipsta);
+	} else {
+
+		/* Clip for z: clipsta and clipend clip values of the shadow buffer. We
+			* can test for -1.0/1.0 because of the properties of the
+			* coordinate transformations. */
+		fac= (co[2]/co[3]);
+
+		if(fac>=1.0f) {
+			return 0.0f;
+		} else if(fac<= -1.0f) {
+			return 1.0f;
+		}
+
+		if (G.rt == 31 || DSM_LINEAR) {
+			fac = (shb->winmat[3][2])/(shb->winmat[2][2] - shb->winmat[2][3]*fac);
+			fac	= (fac - shb->clipsta) / (shb->clipend - shb->clipsta);
+		}
+	}
+
+	zs= ((float)0x7FFFFFFF)*fac;
+
+	/* with inp==1.0, bias is half the size. correction value was 1.1, giving errors
+	   on cube edges, with one side being almost frontal lighted (ton)  */
+	bias= (1.5f-inp*inp)*shb->bias;
+
+	if (xs >= buf->sizex || xs < 0) {
+		return 1.0;
+	}
+
+	if (ys >= buf->sizey || ys < 0) {
+		return 1.0;
+	}
+
+	tile = TCS_GetAndLockTile(dbuf, xs, ys, 0);
+	xs %= buf->tsizex;
+	ys %= buf->tsizey;
+
+	switch (channel) {
+		case 0:
+			func = &tile->r_rect[ys*tile->sizex+xs];
+			break;
+		case 1:
+			func = &tile->g_rect[ys*tile->sizex+xs];
+			break;
+		case 2:
+			func = &tile->b_rect[ys*tile->sizex+xs];
+			break;
+	}
+
+	samp = func->samples;
+	for (i=0; i<func->totsamples; i++, samp++) {
+		if (zs > samp->depth) {
+			startsamp = samp;
+			break;
+		}
+	}
+	
+	BASSERT(startsamp);
+	if (startsamp == NULL) {
+		TCS_UnlockTile(tile);
+		return 1.0f;
+	}
+
+	//compute the world-space depth
+	startz = (float) startsamp->depth / 2147483647.0f;
+	startz = startz*(shb->clipend - shb->clipsta) + shb->clipsta;
+	
+
+
+	TCS_UnlockTile(tile);
+}
+#endif
+
 /*-------------non-working soft shadow code-----------*/
 #if 1
 static void DSM_ProcessPixel(DSMFunction *func, int index, int zenter, int zexit, float *shadclr, int bias, int zthresh)
@@ -110,7 +228,7 @@
 
 			//check if layer-zthresh to layer+zthresh overlaps zenter, zexit
 			if ((max >= zenter && max <= zexit) || (min >= zenter && min <= zexit)
-				 || (min <= zenter && max >= zexit)) {
+				 || (min <= zenter && max >= zexit) || (min < zenter && max > zexit)) {
 				if (i != 0) shadclr[index] *= 1.0 - ((samp-1)->value - (samp)->value);
 				else shadclr[index] *= samp->value;
 
@@ -240,8 +358,14 @@
 		start= floor(v1[1]);
 		end= start+floor(dy);
 
-		if(start>=recty || end<0) return;
+		if(start>=recty || end<0) {
+			shadclr[0] += shadclr2[0];
+			shadclr[1] += shadclr2[1];
+			shadclr[2] += shadclr2[2];
 
+			return;
+		}
+
 		if(end>=recty) end= recty-1;
 
 		oldx= floor(v1[0]);
@@ -311,7 +435,7 @@
 	float adapt_thresh = lar->adapt_thresh;
 	int max_samples = lar->ray_totsamp;
 	float pos[3], zco;
-	int do_soft=1, full_osa=0;
+	int do_soft=1, full_osa=0, first=1;
 
 	shadowclr[0] = shadowclr[1] = shadowclr[2] = 1.0f;
 
@@ -324,7 +448,6 @@
 	}
 
 	if(inp <= 0.0f) return;
-	
 
 	/* rotate renderco en osaco */
 	siz= 0.5f*(float)shb->size;
@@ -388,23 +511,23 @@
 
 	colsq[0] = colsq[1] = colsq[2] = 0.0;
 	if (lar->ray_totsamp < 2) do_soft = 0;
-	if ((R.r.mode & R_OSA) && (R.osa > 0) && (shi->vlr->flag & R_FULL_OSA)) full_osa = 1;
+	if ((re->r.mode & R_OSA) && (re->osa > 0) && (shi->vlr->flag & R_FULL_OSA)) full_osa = 1;
 	
 	if (full_osa) {
-		if (do_soft) max_samples  = max_samples/R.osa + 1;
+		if (do_soft) max_samples  = max_samples/re->osa + 1;
 		else max_samples = 1;
 	} else {
 		if (do_soft) max_samples = lar->ray_totsamp;
-		else max_samples = (R.osa > 4)?R.osa:5;
+		else max_samples = (re->osa > 4)?re->osa:5;
 	}
 
 	/* sampling init */
 	if (lar->ray_samp_method==LA_SAMP_HALTON) {
-		qsa = get_thread_qmcsampler(&R, shi->thread, SAMP_TYPE_HALTON, max_samples);
-		qsa_jit = get_thread_qmcsampler(&R, shi->thread, SAMP_TYPE_HALTON, max_samples);
+		qsa = get_thread_qmcsampler(re, shi->thread, SAMP_TYPE_HALTON, max_samples);
+		qsa_jit = get_thread_qmcsampler(re, shi->thread, SAMP_TYPE_HALTON, max_samples);
 	} else if (lar->ray_samp_method==LA_SAMP_HAMMERSLEY) {
-		qsa = get_thread_qmcsampler(&R, shi->thread, SAMP_TYPE_HAMMERSLEY, max_samples);
-		qsa_jit = get_thread_qmcsampler(&R, shi->thread, SAMP_TYPE_HAMMERSLEY, max_samples);
+		qsa = get_thread_qmcsampler(re, shi->thread, SAMP_TYPE_HAMMERSLEY, max_samples);
+		qsa_jit = get_thread_qmcsampler(re, shi->thread, SAMP_TYPE_HAMMERSLEY, max_samples);
 	}
 
 	QMC_initPixel(qsa, shi->thread);
@@ -431,7 +554,7 @@
 		
 		/*
 		if (shi->vlr && !full_osa) {
-			QMC_sampleRect(jit, qsa_jit, shi->thread, samples, 1.0, 1.0);
+			QMC_sampleRect(jit, qsa_jit, shi->thread, samples+1, 1.0, 1.0);
 			
 			pos[0] += shi->dxco[0]*jit[0] + shi->dyco[0]*jit[1];
 			pos[1] += shi->dxco[1]*jit[0] + shi->dyco[1]*jit[1];
@@ -452,7 +575,7 @@
 				VecOrthoBasisf(v, ru, rv);
 				
 				/* sampling, returns quasi-random vector in area_size disc */
-				QMC_sampleDisc(samp3d, qsa, shi->thread, samples,lar->area_size);
+				QMC_sampleDisc(samp3d, qsa, shi->thread, samples, lar->area_size);
 
 				/* distribute disc samples across the tangent plane */
 				s[0] = samp3d[0]*ru[0] + samp3d[1]*rv[0];
@@ -468,22 +591,28 @@
 				///* align samples to lamp vector */
 				//Mat3MulVecfl(lar->mat, samp3d);
 			}
-			sco[0]= samp3d[0];
-			sco[1]= samp3d[1];
-			sco[2]= samp3d[2];
 		} else {
 			VECCOPY(sco, vec);
 		}
-		
+
+		BASSERT(samp3d[0] != 0.0);
+		BASSERT(samp3d[1] != 0.0);
+		BASSERT(samp3d[0] >= -lar->area_size/2 && samp3d[0] <= lar->area_size/2);
+		BASSERT(samp3d[1] >= -lar->area_sizey/2 && samp3d[1] <= lar->area_sizey/2);
+
+		sco[0]= samp3d[0];
+		sco[1]= samp3d[1];
+		sco[2]= samp3d[2];
+
 		sco[2] = 0.0f;
 		
 		VECCOPY(raystart, pos);		
 		
 		/* trace the ray */
 		MTC_Mat4MulVecfl(re->viewinv, raystart);
-		MTC_Mat4MulVecfl(shb->viewmat, raystart);
+		MTC_Mat4MulVecfl(shb->viewmat_uncorrected, raystart);
 		
-		VecClipLine3f(raystart, sco, 2, -shb->clipsta-0.06f);
+		VecClipLine3f(raystart, sco, 2, -shb->clipsta-0.006f);
 		
 		//BSE_Add3DVisPoint(raystart, BSE_Yellow, 0);
 		//BSE_Add3DVisPoint(sco, BSE_Yellow, 1);
@@ -503,7 +632,7 @@
 		MTC_Mat4MulVec4fl(shb->winmat, raystart);
 		MTC_Mat4MulVec4fl(shb->winmat, sco);
 
-		if (DSM_zbufclipwire(shb->clipsta, shb->clipend, shb->size, shb->size, raystart, sco)) {// int DSM_zbufclipwire(int rectx, int recty, float *v1, float *v2);
+		if (DSM_zbufclipwire(shb->clipsta, shb->clipend, shb->size, shb->size, sco, raystart)) {// int DSM_zbufclipwire(int rectx, int recty, float *v1, float *v2);
 			//printf("postray: [%f, %f, %f, %f]-[%f, %f, %f, %f]\n", raystart[0], raystart[1], raystart[2], raystart[3], sco[0], sco[1], sco[2], sco[3]);
 			#ifdef DOQMCDEBUG
 			{
@@ -518,17 +647,23 @@
 				zco = ((float)raystart[2])/2147483647.0f;
 				zco = (shb->winmat[3][2])/(shb->winmat[2][2] - shb->winmat[2][3]*zco);
 				zco	= (zco - shb->clipsta) / (shb->clipend - shb->clipsta);
-				raystart[2] = ((float)0x7FFFFFFF)*zco;
+				raystart[2] = 2147483647.0f*zco;
 
 				zco = ((float)sco[2])/2147483647.0f;
 				zco = (shb->winmat[3][2])/(shb->winmat[2][2] - shb->winmat[2][3]*zco);
 				zco	= (zco - shb->clipsta) / (shb->clipend - shb->clipsta);
-				sco[2] = ((float)0x7FFFFFFF)*zco;
+				sco[2] = 2147483647.0f*zco;
 
 			}
+
 			DSM_RasterRayPath(buf, bias, zthresh, shadclr, raystart, sco);
 
+		} else {
+			shadclr[0] += 1.0f;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list