[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22637] branches/volume25/source/blender/ render/intern/source/volumetric.c: * volume rendering cleanups and optimisations

Matt Ebb matt at mke3.net
Wed Aug 19 23:48:09 CEST 2009


Revision: 22637
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22637
Author:   broken
Date:     2009-08-19 23:48:09 +0200 (Wed, 19 Aug 2009)

Log Message:
-----------
* volume rendering cleanups and optimisations

Modified Paths:
--------------
    branches/volume25/source/blender/render/intern/source/volumetric.c

Modified: branches/volume25/source/blender/render/intern/source/volumetric.c
===================================================================
--- branches/volume25/source/blender/render/intern/source/volumetric.c	2009-08-19 21:47:47 UTC (rev 22636)
+++ branches/volume25/source/blender/render/intern/source/volumetric.c	2009-08-19 21:48:09 UTC (rev 22637)
@@ -237,6 +237,23 @@
 /* Compute attenuation, otherwise known as 'optical thickness', extinction, or tau.
  * Used in the relationship Transmittance = e^(-attenuation)
  */
+void vol_get_attenuation_seg(ShadeInput *shi, float *tau, float *stepvec, float *co, float density)
+{
+	/* input density = density at co */
+	float absorb_col[3];
+	const float dist = VecLength(stepvec);
+	
+	vol_get_absorption(shi, absorb_col, co);
+	
+	/* homogenous volume within the sampled distance */
+	tau[0] = tau[1] = tau[2] = dist * density;
+		
+	VecMulVecf(tau, tau, absorb_col);
+}
+
+/* Compute attenuation, otherwise known as 'optical thickness', extinction, or tau.
+ * Used in the relationship Transmittance = e^(-attenuation)
+ */
 void vol_get_attenuation(ShadeInput *shi, float *tau, float *co, float *endco, float density, float stepsize)
 {
 	/* input density = density at co */
@@ -249,19 +266,8 @@
 
 	nsteps = (int)((dist / stepsize) + 0.5);
 	
-	/* trigger for recalculating density */
-	if (density < -0.001f) density = vol_get_density(shi, co);
+	tau[0] = tau[1] = tau[2] = 0.0;
 	
-	if (nsteps == 1) {
-		/* homogenous volume within the sampled distance */
-		tau[0] = tau[1] = tau[2] = dist * density;
-		
-		VecMulVecf(tau, tau, absorb_col);
-		return;
-	} else {
-		tau[0] = tau[1] = tau[2] = 0.0;
-	}
-	
 	VecSubf(step_vec, endco, co);
 	VecMulf(step_vec, 1.0f / nsteps);
 	
@@ -402,22 +408,14 @@
 static void volumeintegrate(struct ShadeInput *shi, float *col, float *co, float *endco)
 {
 	float tr[3] = {1.0f, 1.0f, 1.0f};
-	float radiance[3] = {0.f, 0.f, 0.f}, d_radiance[3] = {0.f, 0.f, 0.f};
+	float radiance[3] = {0.f, 0.f, 0.f}, d_radiance[3] = {0.f, 0.f, 0.f}, radiance_behind[3];
 	float stepsize = vol_get_stepsize(shi, STEPSIZE_VIEW);
 	int nsteps, s;
 	float tau[3], emit_col[3], scatter_col[3] = {0.0, 0.0, 0.0};
 	float stepvec[3], step_sta[3], step_end[3], step_mid[3];
-	float density = vol_get_density(shi, co);
+	float density;
 	const float depth_cutoff = shi->mat->vol.depth_cutoff;
-	
-	/* multiply col_behind with beam transmittance over entire distance */
-	vol_get_attenuation(shi, tau, co, endco, density, stepsize);
-	tr[0] *= exp(-tau[0]);
-	tr[1] *= exp(-tau[1]);
-	tr[2] *= exp(-tau[2]);
-	VecMulVecf(radiance, tr, col);	
-	tr[0] = tr[1] = tr[2] = 1.0f;
-	
+
 	/* ray marching */
 	nsteps = (int)((VecLenf(co, endco) / stepsize) + 0.5);
 	
@@ -429,13 +427,13 @@
 	/* get radiance from all points along the ray due to participating media */
 	for (s = 0; s < nsteps; s++) {
 
-		if (s > 0) density = vol_get_density(shi, step_sta);
+		density = vol_get_density(shi, step_sta);
 		
 		/* there's only any use in shading here if there's actually some density to shade! */
 		if (density > 0.01f) {
 		
 			/* transmittance component (alpha) */
-			vol_get_attenuation(shi, tau, step_sta, step_end, density, stepsize);
+			vol_get_attenuation_seg(shi, tau, stepvec, co, density);
 			tr[0] *= exp(-tau[0]);
 			tr[1] *= exp(-tau[1]);
 			tr[2] *= exp(-tau[2]);
@@ -469,6 +467,10 @@
 		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(radiance_behind, tr, col);	
+	VecAddf(radiance, radiance, radiance_behind);
+	
 	VecCopyf(col, radiance);
 	col[3] = 1.0f -(tr[0] + tr[1] + tr[2]) * 0.333f;
 }





More information about the Bf-blender-cvs mailing list