[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22795] branches/blender2.5/blender/source /blender/render/intern: * Fix for yesterday's valgrind fix

Matt Ebb matt at mke3.net
Wed Aug 26 08:17:39 CEST 2009


Revision: 22795
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22795
Author:   broken
Date:     2009-08-26 08:17:39 +0200 (Wed, 26 Aug 2009)

Log Message:
-----------
* Fix for yesterday's valgrind fix

* Fix for plane material preview render. Now, light cache aborts if there isn't enough volume, and falls back on non-cached single scattering. It still doesn't make much sense to render a plane as a volume, but for now in the preview it will shade the region in between the plane and the checker background.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/render/intern/include/volume_precache.h
    branches/blender2.5/blender/source/blender/render/intern/source/volume_precache.c
    branches/blender2.5/blender/source/blender/render/intern/source/volumetric.c

Modified: branches/blender2.5/blender/source/blender/render/intern/include/volume_precache.h
===================================================================
--- branches/blender2.5/blender/source/blender/render/intern/include/volume_precache.h	2009-08-26 06:15:43 UTC (rev 22794)
+++ branches/blender2.5/blender/source/blender/render/intern/include/volume_precache.h	2009-08-26 06:17:39 UTC (rev 22795)
@@ -1,3 +1,4 @@
+<<<<<<< .mine
 /**
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
@@ -29,6 +30,40 @@
 void volume_precache(Render *re);
 void free_volume_precache(Render *re);
 int point_inside_volume_objectinstance(ObjectInstanceRen *obi, float *co);
+
+#define VOL_MS_TIMESTEP	0.1f=======
+/**
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Matt Ebb.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+ 
+void volume_precache(Render *re);
+void free_volume_precache(Render *re);
+int point_inside_volume_objectinstance(ObjectInstanceRen *obi, float *co);
 int using_lightcache(Material *ma);
 
 #define VOL_MS_TIMESTEP	0.1f
+>>>>>>> .r22793

Modified: branches/blender2.5/blender/source/blender/render/intern/source/volume_precache.c
===================================================================
--- branches/blender2.5/blender/source/blender/render/intern/source/volume_precache.c	2009-08-26 06:15:43 UTC (rev 22794)
+++ branches/blender2.5/blender/source/blender/render/intern/source/volume_precache.c	2009-08-26 06:17:39 UTC (rev 22795)
@@ -499,8 +499,7 @@
 	res = vp->res;
 	
 	VecSubf(voxel, bbmax, bbmin);
-	if ((voxel[0] < FLT_EPSILON) || (voxel[1] < FLT_EPSILON) || (voxel[2] < FLT_EPSILON))
-		return;
+	
 	voxel[0] /= res[0];
 	voxel[1] /= res[1];
 	voxel[2] /= res[2];
@@ -564,7 +563,7 @@
 	return nextpa;
 }
 
-static void precache_resolution(VolumePrecache *vp, float *bbmin, float *bbmax, int res)
+static int precache_resolution(VolumePrecache *vp, float *bbmin, float *bbmax, int res)
 {
 	float dim[3], div;
 	
@@ -574,10 +573,15 @@
 	dim[0] /= div;
 	dim[1] /= div;
 	dim[2] /= div;
-			   
+	
 	vp->res[0] = dim[0] * (float)res;
 	vp->res[1] = dim[1] * (float)res;
 	vp->res[2] = dim[2] * (float)res;
+	
+	if ((vp->res[0] < 1) || (vp->res[1] < 1) || (vp->res[2] < 1))
+		return 0;
+	
+	return 1;
 }
 
 /* Precache a volume into a 3D voxel grid.
@@ -608,7 +612,12 @@
 	if (!tree) return;
 
 	vp = MEM_callocN(sizeof(VolumePrecache), "volume light cache");
-	precache_resolution(vp, bbmin, bbmax, ma->vol.precache_resolution);
+	
+	if (!precache_resolution(vp, bbmin, bbmax, ma->vol.precache_resolution)) {
+		MEM_freeN(vp);
+		vp = NULL;
+		return;
+	}
 
 	vp->data_r = MEM_callocN(sizeof(float)*vp->res[0]*vp->res[1]*vp->res[2], "volume light cache data red channel");
 	vp->data_g = MEM_callocN(sizeof(float)*vp->res[0]*vp->res[1]*vp->res[2], "volume light cache data green channel");
@@ -675,7 +684,7 @@
 	}
 }
 
-int using_lightcache(Material *ma)
+static int using_lightcache(Material *ma)
 {
 	return (((ma->vol.shadeflag & MA_VOL_PRECACHESHADING) && (ma->vol.shade_type == MA_VOL_SHADE_SINGLE))
 		|| (ELEM(ma->vol.shade_type, MA_VOL_SHADE_MULTIPLE, MA_VOL_SHADE_SINGLEPLUSMULTIPLE)));
@@ -708,10 +717,10 @@
 	
 	for(obi= re->instancetable.first; obi; obi= obi->next) {
 		if (obi->volume_precache != NULL) {
-			MEM_freeN(obi->volume_precache);
 			MEM_freeN(obi->volume_precache->data_r);
 			MEM_freeN(obi->volume_precache->data_g);
 			MEM_freeN(obi->volume_precache->data_b);
+			MEM_freeN(obi->volume_precache);
 			obi->volume_precache = NULL;
 		}
 	}

Modified: branches/blender2.5/blender/source/blender/render/intern/source/volumetric.c
===================================================================
--- branches/blender2.5/blender/source/blender/render/intern/source/volumetric.c	2009-08-26 06:15:43 UTC (rev 22794)
+++ branches/blender2.5/blender/source/blender/render/intern/source/volumetric.c	2009-08-26 06:17:39 UTC (rev 22795)
@@ -1,3 +1,4 @@
+<<<<<<< .mine
 /**
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
@@ -499,6 +500,694 @@
 			/* incoming light via emission or scattering (additive) */
 			vol_get_emission(shi, emit_col, step_mid, density);
 			
+			if (shi->obi->volume_precache)
+				vol_get_precached_scattering(shi, scatter_col, step_mid);
+			else
+				vol_get_scattering(shi, scatter_col, step_mid, stepsize, density);
+			
+			VecMulf(scatter_col, density);
+			VecAddf(d_radiance, emit_col, scatter_col);
+			
+			/*   Lv += Tr * (Lve() + Ld) */
+			VecMulVecf(d_radiance, tr, d_radiance);
+			VecMulf(d_radiance, stepsize);
+			
+			VecAddf(radiance, radiance, d_radiance);	
+		}
+
+		VecCopyf(step_sta, step_end);
+		VecAddf(step_end, step_end, stepvec);
+		
+		/* luminance rec. 709 */
+		if ((0.2126*tr[0] + 0.7152*tr[1] + 0.0722*tr[2]) < depth_cutoff) break;	
+	}
+	
+	/* multiply original color (behind volume) with beam transmittance over entire distance */
+	VecMulVecf(col, tr, col);	
+	VecAddf(col, col, radiance);
+	
+	/* alpha <-- transmission luminance */
+	col[3] = 1.0f -(0.2126*tr[0] + 0.7152*tr[1] + 0.0722*tr[2]);
+}
+
+/* the main entry point for volume shading */
+static void volume_trace(struct ShadeInput *shi, struct ShadeResult *shr, int inside_volume)
+{
+	float hitco[3], col[4] = {0.f,0.f,0.f,0.f};
+	float *startco, *endco;
+	int trace_behind = 1;
+	const int ztransp= ((shi->depth==0) && (shi->mat->mode & MA_TRANSP) && (shi->mat->mode & MA_ZTRANSP));
+	Isect is;
+
+	/* check for shading an internal face a volume object directly */
+	if (inside_volume == VOL_SHADE_INSIDE)
+		trace_behind = 0;
+	else if (inside_volume == VOL_SHADE_OUTSIDE) {
+		if (shi->flippednor)
+			inside_volume = VOL_SHADE_INSIDE;
+	}
+	
+	if (ztransp && inside_volume == VOL_SHADE_INSIDE) {
+		MatInside *mi;
+		int render_this=0;
+		
+		/* don't render the backfaces of ztransp volume materials.
+		 
+		 * volume shading renders the internal volume from between the
+		 * near view intersection of the solid volume to the
+		 * intersection on the other side, as part of the shading of
+		 * the front face.
+		 
+		 * Because ztransp renders both front and back faces independently
+		 * this will double up, so here we prevent rendering the backface as well, 
+		 * which would otherwise render the volume in between the camera and the backface
+		 * --matt */
+		
+		for (mi=R.render_volumes_inside.first; mi; mi=mi->next) {
+			/* weak... */
+			if (mi->ma == shi->mat) render_this=1;
+		}
+		if (!render_this) return;
+	}
+	
+
+	if (inside_volume == VOL_SHADE_INSIDE)
+	{
+		startco = shi->camera_co;
+		endco = shi->co;
+		
+		if (trace_behind) {
+			if (!ztransp)
+				/* trace behind the volume object */
+				vol_trace_behind(shi, shi->vlr, endco, col);
+		} else {
+			/* we're tracing through the volume between the camera 
+			 * and a solid surface, so use that pre-shaded radiance */
+			QUATCOPY(col, shr->combined);
+		}
+		
+		/* shade volume from 'camera' to 1st hit point */
+		volumeintegrate(shi, col, startco, endco);
+	}
+	/* 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))
+	{
+		VlakRen *vlr = (VlakRen *)is.face;
+		
+		startco = shi->co;
+		endco = hitco;
+		
+		if (!ztransp) {
+			/* if it's another face in the same material */
+			if (vlr->mat == shi->mat) {
+				/* trace behind the 2nd (raytrace) hit point */
+				vol_trace_behind(shi, (VlakRen *)is.face, endco, col);
+			} else {
+				shade_intersection(shi, col, &is);
+			}
+		}
+		
+		/* shade volume from 1st hit point to 2nd hit point */
+		volumeintegrate(shi, col, startco, endco);
+	}
+	
+	if (ztransp)
+		col[3] = col[3]>1.f?1.f:col[3];
+	else
+		col[3] = 1.f;
+	
+	VecCopyf(shr->combined, col);
+	shr->alpha = col[3];
+	
+	VECCOPY(shr->diff, shr->combined);
+}
+
+/* Traces a shadow through the object, 
+ * pretty much gets the transmission over a ray path */
+void shade_volume_shadow(struct ShadeInput *shi, struct ShadeResult *shr, struct Isect *last_is)
+{
+	float hitco[3];
+	float tr[3] = {1.0,1.0,1.0};
+	Isect is;
+	float shade_stepsize = vol_get_stepsize(shi, STEPSIZE_SHADE);
+	float *startco, *endco;
+	float density=0.f;
+
+	memset(shr, 0, sizeof(ShadeResult));
+	
+	/* if 1st hit normal is facing away from the camera, 
+	 * then we're inside the volume already. */
+	if (shi->flippednor) {
+		startco = last_is->start;
+		endco = shi->co;
+	}
+	/* 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)) {
+		startco = shi->co;
+		endco = hitco;
+	}
+	else {
+		shr->combined[0] = shr->combined[1] = shr->combined[2] = 0.f;
+		shr->alpha = shr->combined[3] = 1.f;
+		return;
+	}
+	
+	density = vol_get_density(shi, startco);
+	vol_get_attenuation(shi, tr, startco, endco, density, shade_stepsize);
+	
+	VecCopyf(shr->combined, tr);
+	shr->combined[3] = 1.0f -(0.2126*tr[0] + 0.7152*tr[1] + 0.0722*tr[2]);
+	shr->alpha = shr->combined[3];
+}
+
+
+/* delivers a fully filled in ShadeResult, for all passes */
+void shade_volume_outside(ShadeInput *shi, ShadeResult *shr)
+{
+	memset(shr, 0, sizeof(ShadeResult));
+	volume_trace(shi, shr, VOL_SHADE_OUTSIDE);
+}
+
+
+void shade_volume_inside(ShadeInput *shi, ShadeResult *shr)
+{
+	MatInside *m;
+	Material *mat_backup;
+	
+	//if (BLI_countlist(&R.render_volumes_inside) == 0) return;
+	
+	/* XXX: extend to multiple volumes perhaps later */
+	mat_backup = shi->mat;
+	m = R.render_volumes_inside.first;
+	shi->mat = m->ma;
+	
+	volume_trace(shi, shr, VOL_SHADE_INSIDE);
+
+	shi->mat = mat_backup;
+}=======
+/**
+ *

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list