[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16860] branches/sim_physics/source/ blender: * Fix for volumetric rendering.

Matt Ebb matt at mke3.net
Wed Oct 1 09:13:28 CEST 2008


Revision: 16860
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16860
Author:   broken
Date:     2008-10-01 09:13:28 +0200 (Wed, 01 Oct 2008)

Log Message:
-----------
* Fix for volumetric rendering. It previously wasn't multiplying 
the emission component by the density at the current point, which 
made the volume too bright in less dense areas. This made it look 
too rough, as opposed to smooth as it should be. This makes the 
particle rendering look *much* better, thanks a bunch to ZanQdo for 
complaining and kicking my butt to make me realise the error.

Here's an example of how smooth it looks now:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test03.mov
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test03.blend

Settings in existing files will have to be tweaked a bit, since 
what they were set up for before, was incorrect.

* Added two new interpolation types to Point Density: Constant and 
Root. These work similarly to in proportional edit for example, 
just gives a bit more choice over how hard-edged the particles 
should look.

Modified Paths:
--------------
    branches/sim_physics/source/blender/makesdna/DNA_texture_types.h
    branches/sim_physics/source/blender/render/intern/source/pointdensity.c
    branches/sim_physics/source/blender/render/intern/source/volumetric.c
    branches/sim_physics/source/blender/src/buttons_shading.c

Modified: branches/sim_physics/source/blender/makesdna/DNA_texture_types.h
===================================================================
--- branches/sim_physics/source/blender/makesdna/DNA_texture_types.h	2008-10-01 07:04:10 UTC (rev 16859)
+++ branches/sim_physics/source/blender/makesdna/DNA_texture_types.h	2008-10-01 07:13:28 UTC (rev 16860)
@@ -132,7 +132,6 @@
 
 	short falloff_type;
 	float radius;
-
 	short source;
 	short pdpad[3];
 
@@ -422,6 +421,8 @@
 #define TEX_PD_FALLOFF_STD		0
 #define TEX_PD_FALLOFF_SMOOTH	1
 #define TEX_PD_FALLOFF_SHARP	2
+#define TEX_PD_FALLOFF_CONSTANT	3
+#define TEX_PD_FALLOFF_ROOT		4
 
 /* psys_cache_space */
 #define TEX_PD_OBJECTLOC	0

Modified: branches/sim_physics/source/blender/render/intern/source/pointdensity.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/pointdensity.c	2008-10-01 07:04:10 UTC (rev 16859)
+++ branches/sim_physics/source/blender/render/intern/source/pointdensity.c	2008-10-01 07:13:28 UTC (rev 16860)
@@ -224,7 +224,6 @@
 	}
 }
 
-
 void accum_density_std(void *userdata, int index, float squared_dist, float squared_radius)
 {
 	float *density = userdata;
@@ -249,6 +248,22 @@
 	*density+= dist*dist;
 }
 
+void accum_density_constant(void *userdata, int index, float squared_dist, float squared_radius)
+{
+	float *density = userdata;
+		
+	*density+= squared_radius;
+}
+
+void accum_density_root(void *userdata, int index, float squared_dist, float squared_radius)
+{
+	float *density = userdata;
+	const float dist = squared_radius - squared_dist;
+		
+	*density+= sqrt(dist);
+}
+
+
 #define MAX_POINTS_NEAREST	25
 int pointdensitytex(Tex *tex, float *texvec, TexResult *texres)
 {
@@ -267,7 +282,11 @@
 		BLI_bvhtree_range_query(pd->point_tree, texvec, pd->radius, accum_density_smooth, &density);
 	else if (pd->falloff_type == TEX_PD_FALLOFF_SHARP)
 		BLI_bvhtree_range_query(pd->point_tree, texvec, pd->radius, accum_density_sharp, &density);
-
+	else if (pd->falloff_type == TEX_PD_FALLOFF_CONSTANT)
+		BLI_bvhtree_range_query(pd->point_tree, texvec, pd->radius, accum_density_constant, &density);
+	else if (pd->falloff_type == TEX_PD_FALLOFF_ROOT)
+		BLI_bvhtree_range_query(pd->point_tree, texvec, pd->radius, accum_density_root, &density);
+	
 	texres->tin = density;
 
 	/*

Modified: branches/sim_physics/source/blender/render/intern/source/volumetric.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/volumetric.c	2008-10-01 07:04:10 UTC (rev 16859)
+++ branches/sim_physics/source/blender/render/intern/source/volumetric.c	2008-10-01 07:13:28 UTC (rev 16860)
@@ -152,7 +152,7 @@
 	
 	do_volume_tex(shi, co, MAP_EMIT+MAP_COL, col, &emission);
 	
-	em[0] = em[1] = em[2] = emission;
+	em[0] = em[1] = em[2] = emission * density;
 	VecMulVecf(em, em, col);
 }
 
@@ -365,13 +365,10 @@
 	/* 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);
-	
-		/* there's only any point shading here
+		
+		/* there's only any use in shading here
 		 * if there's actually some density to shade! */
 		if (density > 0.01f) {
-			step_mid[0] = step_sta[0] + (stepvec[0] * 0.5);
-			step_mid[1] = step_sta[1] + (stepvec[1] * 0.5);
-			step_mid[2] = step_sta[2] + (stepvec[2] * 0.5);
 		
 			/* transmittance component (alpha) */
 			vol_get_attenuation(shi, tau, step_sta, step_end, density, stepsize);
@@ -379,9 +376,10 @@
 			tr[1] *= exp(-tau[1]);
 			tr[2] *= exp(-tau[2]);
 			
-			/* Terminate raymarching if transmittance is small */
-			//if ((tr[0] + tr[1] + tr[2] * 0.333f) < 0.01f) continue;
-			
+			step_mid[0] = step_sta[0] + (stepvec[0] * 0.5);
+			step_mid[1] = step_sta[1] + (stepvec[1] * 0.5);
+			step_mid[2] = step_sta[2] + (stepvec[2] * 0.5);
+		
 			/* incoming light via emission or scattering (additive) */
 			vol_get_emission(shi, step_emit, step_mid, density);
 			vol_get_scattering(shi, step_scatter, step_mid, stepsize, density);

Modified: branches/sim_physics/source/blender/src/buttons_shading.c
===================================================================
--- branches/sim_physics/source/blender/src/buttons_shading.c	2008-10-01 07:04:10 UTC (rev 16859)
+++ branches/sim_physics/source/blender/src/buttons_shading.c	2008-10-01 07:13:28 UTC (rev 16860)
@@ -758,7 +758,7 @@
 		
 		uiDefBut(block, LABEL, B_NOP, "Falloff:",
 			X2CLM1, yco-=BUTH, BUTW2, BUTH, 0, 0, 0, 0, 0, "");	
-		uiDefButS(block, MENU, B_REDR, "Standard %x0|Smooth %x1|Sharp %x2",
+		uiDefButS(block, MENU, B_REDR, "Standard %x0|Smooth %x1|Sharp %x2|Constant %x3|Root %x4",
 				X2CLM1, yco-=BUTH, BUTW2, BUTH, &pd->falloff_type, 0.0, 0.0, 0, 0, "Falloff type");
 		
 		yco = PANEL_YMAX;
@@ -4334,7 +4334,7 @@
 	uiDefButF(block, NUM, B_MATPRV, "Step Size: ",
 		X2CLM1, yco-=BUTH, BUTW2, BUTH, &(ma->vol_shade_stepsize), 0.001, 100.0, 10, 2, "Step");
 	uiBlockEndAlign(block);
-	
+		
 	yco = PANEL_YMAX;
 	
 	uiDefButF(block, NUMSLI, B_MATPRV, "Density: ",





More information about the Bf-blender-cvs mailing list