[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12134] trunk/blender/source/blender/ render/intern/source/rayshade.c: * Adaptive QMC ray shadow sampling wasn' t working with transparent shadows - fixed.

Matt Ebb matt at mke3.net
Mon Sep 24 15:17:42 CEST 2007


Revision: 12134
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12134
Author:   broken
Date:     2007-09-24 15:17:42 +0200 (Mon, 24 Sep 2007)

Log Message:
-----------
* Adaptive QMC ray shadow sampling wasn't working with transparent shadows - fixed.

Modified Paths:
--------------
    trunk/blender/source/blender/render/intern/source/rayshade.c

Modified: trunk/blender/source/blender/render/intern/source/rayshade.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/rayshade.c	2007-09-24 12:25:13 UTC (rev 12133)
+++ trunk/blender/source/blender/render/intern/source/rayshade.c	2007-09-24 13:17:42 UTC (rev 12134)
@@ -831,7 +831,7 @@
 static int adaptive_sample_variance(int samples, float *col, float *colsq, float thresh)
 {
 	float var[3], mean[3];
-	
+
 	/* scale threshold just to give a bit more precision in input rather than dealing with 
 	 * tiny tiny numbers in the UI */
 	thresh /= 2;
@@ -843,7 +843,7 @@
 	var[0] = (colsq[0] / (float)samples) - (mean[0]*mean[0]);
 	var[1] = (colsq[1] / (float)samples) - (mean[1]*mean[1]);
 	var[2] = (colsq[2] / (float)samples) - (mean[2]*mean[2]);
-
+	
 	if ((var[0] * 0.4 < thresh) && (var[1] * 0.3 < thresh) && (var[2] * 0.6 < thresh))
 		return 1;
 	else
@@ -1658,11 +1658,13 @@
 	float samp3d[3], jit[3];
 
 	float fac=0.0f, vec[3];
+	float colsq[4];
 	float adapt_thresh = lar->adapt_thresh;
 	int max_samples = lar->ray_totsamp;
 	float pos[3];
 	int do_soft=1;
 
+	colsq[0] = colsq[1] = colsq[2] = 0.0;
 	if(isec->mode==RE_RAY_SHADOW_TRA) {
 		shadfac[0]= shadfac[1]= shadfac[2]= shadfac[3]= 0.0f;
 	} else
@@ -1756,6 +1758,11 @@
 			shadfac[1] += isec->col[1];
 			shadfac[2] += isec->col[2];
 			shadfac[3] += isec->col[3];
+			
+			/* for variance calc */
+			colsq[0] += isec->col[0]*isec->col[0];
+			colsq[1] += isec->col[1]*isec->col[1];
+			colsq[2] += isec->col[2]*isec->col[2];
 		}
 		else {
 			if( RE_ray_tree_intersect(R.raytree, isec) ) fac+= 1.0f;
@@ -1764,9 +1771,18 @@
 		samples++;
 		
 		if ((lar->ray_samp_method == LA_SAMP_HALTON)) {
+		
 			/* adaptive sampling - consider samples below threshold as in shadow (or vice versa) and exit early */
-			if ((do_soft) && (adapt_thresh > 0.0)) {
-				if ( (samples > max_samples/3) && ((fac / samples > (1.0-adapt_thresh)) || (fac / samples < adapt_thresh)) ) break;
+			if ((max_samples > 4) && (adapt_thresh > 0.0) && (samples > max_samples / 3)) {
+				if (isec->mode==RE_RAY_SHADOW_TRA) {
+					if ((shadfac[3] / samples > (1.0-adapt_thresh)) || (shadfac[3] / samples < adapt_thresh))
+						break;
+					else if (adaptive_sample_variance(samples, shadfac, colsq, adapt_thresh))
+						break;
+				} else {
+					if ((fac / samples > (1.0-adapt_thresh)) || (fac / samples < adapt_thresh))
+						break;
+				}
 			}
 		}
 	}





More information about the Bf-blender-cvs mailing list