[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33373] trunk/blender/source/blender/ render/intern/source: Fix [#20241] half-transparent objects in volume have no shadow.

Matt Ebb matt at mke3.net
Mon Nov 29 08:07:10 CET 2010


Revision: 33373
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33373
Author:   broken
Date:     2010-11-29 08:07:08 +0100 (Mon, 29 Nov 2010)

Log Message:
-----------
Fix [#20241] half-transparent objects in volume have no shadow.

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

Modified: trunk/blender/source/blender/render/intern/source/rayshade.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/rayshade.c	2010-11-29 04:35:56 UTC (rev 33372)
+++ trunk/blender/source/blender/render/intern/source/rayshade.c	2010-11-29 07:07:08 UTC (rev 33373)
@@ -1591,8 +1591,13 @@
 			/* mix colors based on shadfac (rgb + amount of light factor) */
 			addAlphaLight(is->col, shr.diff, shr.alpha, d*shi.mat->filter);
 		} else if (shi.mat->material_type == MA_TYPE_VOLUME) {
-			QUATCOPY(is->col, shr.combined);
-			is->col[3] = 1.f;
+			const float a = is->col[3];
+			
+			is->col[0] = a*is->col[0] + shr.alpha*shr.combined[0];
+			is->col[1] = a*is->col[1] + shr.alpha*shr.combined[1];
+			is->col[2] = a*is->col[2] + shr.alpha*shr.combined[2];
+			
+			is->col[3] = (1.0 - shr.alpha)*a;
 		}
 		
 		if(depth>0 && is->col[3]>0.0f) {

Modified: trunk/blender/source/blender/render/intern/source/volumetric.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/volumetric.c	2010-11-29 04:35:56 UTC (rev 33372)
+++ trunk/blender/source/blender/render/intern/source/volumetric.c	2010-11-29 07:07:08 UTC (rev 33373)
@@ -115,13 +115,6 @@
 
 static int vol_get_bounds(ShadeInput *shi, float *co, float *vec, float *hitco, Isect *isect, int intersect_type)
 {
-	/* XXX TODO - get raytrace max distance from object instance's bounding box */
-	/* need to account for scaling only, but keep coords in camera space...
-	 * below code is WIP and doesn't work!
-	sub_v3_v3v3(bb_dim, shi->obi->obr->boundbox[1], shi->obi->obr->boundbox[2]);
-	mul_m3_v3(shi->obi->nmat, bb_dim);
-	maxsize = len_v3(bb_dim);
-	*/
 	
 	VECCOPY(isect->start, co);
 	VECCOPY(isect->vec, vec );
@@ -743,6 +736,7 @@
 	float tr[3] = {1.0,1.0,1.0};
 	Isect is;
 	float *startco, *endco;
+	int intersect_type = VOL_BOUNDS_DEPTH;
 
 	memset(shr, 0, sizeof(ShadeResult));
 	
@@ -751,10 +745,12 @@
 	if (shi->flippednor) {
 		startco = last_is->start;
 		endco = shi->co;
+		intersect_type = VOL_BOUNDS_SS;
 	}
+	
 	/* trace to find a backface, the other side bounds of the volume */
 	/* (ray intersect ignores front faces here) */
-	else if (vol_get_bounds(shi, shi->co, shi->view, hitco, &is, VOL_BOUNDS_DEPTH)) {
+	else if (vol_get_bounds(shi, shi->co, shi->view, hitco, &is, intersect_type)) {
 		startco = shi->co;
 		endco = hitco;
 	}
@@ -765,9 +761,21 @@
 	}
 
 	vol_get_transmittance(shi, tr, startco, endco);
+
 	
+	/* if we hit another face in the same volume bounds */
+	/* shift raytrace coordinates to the hit point, to avoid shading volume twice */
+	/* due to idiosyncracy in ray_trace_shadow_tra() */
+	if (is.hit.ob == shi->obi) {
+		copy_v3_v3(shi->co, hitco);
+		last_is->labda -= is.labda;
+		shi->vlr = (VlakRen *)is.hit.face;
+	}
+
+	
 	copy_v3_v3(shr->combined, tr);
 	shr->combined[3] = 1.0f - luminance(tr);
+	shr->alpha = shr->combined[3];
 }
 
 





More information about the Bf-blender-cvs mailing list