[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17052] branches/sim_physics/source/ blender: * A few volume rendering tweaks:

Matt Ebb matt at mke3.net
Mon Oct 13 01:39:52 CEST 2008


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

Log Message:
-----------
* A few volume rendering tweaks:

- modified point density so that it returns a more consistent 
density with regards to search radius. Previously larger radii 
would give much higher density but this is equalised out now.

- Added a new volume material option 'density scale'. This is an 
overall scale multiplier for density, allowing you to (for 
example) crank down the density to a more desirable range if 
you're working at a large physical scale. Volume rendering is 
fundamentally scale dependant so this lets you correct to get the 
right visual result.

- Also tweaked a few constants, old files won't render exactly 
the same, just minor things though.

Modified Paths:
--------------
    branches/sim_physics/source/blender/blenkernel/intern/material.c
    branches/sim_physics/source/blender/blenloader/intern/readfile.c
    branches/sim_physics/source/blender/makesdna/DNA_material_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/blenkernel/intern/material.c
===================================================================
--- branches/sim_physics/source/blender/blenkernel/intern/material.c	2008-10-12 18:32:26 UTC (rev 17051)
+++ branches/sim_physics/source/blender/blenkernel/intern/material.c	2008-10-12 23:39:52 UTC (rev 17052)
@@ -167,6 +167,7 @@
 	ma->sss_front= 1.0f;
 	ma->sss_back= 1.0f;
 	
+	ma->vol_density_scale = 1.0f;
 	ma->vol_stepsize = 0.2f;
 	ma->vol_shade_stepsize = 0.2f;
 	ma->vol_absorption = 1.0f;

Modified: branches/sim_physics/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/sim_physics/source/blender/blenloader/intern/readfile.c	2008-10-12 18:32:26 UTC (rev 17051)
+++ branches/sim_physics/source/blender/blenloader/intern/readfile.c	2008-10-12 23:39:52 UTC (rev 17052)
@@ -7893,6 +7893,8 @@
 				ma->vol_scattering = 1.0f;
 				ma->vol_absorption_col[0] = ma->vol_absorption_col[1] = ma->vol_absorption_col[2] = 0.0f;	
 			}
+			if (ma->vol_density_scale < 0.0001f)
+				ma->vol_density_scale = 1.0f;
 		}
 		
 		for(tex=main->tex.first; tex; tex= tex->id.next) {

Modified: branches/sim_physics/source/blender/makesdna/DNA_material_types.h
===================================================================
--- branches/sim_physics/source/blender/makesdna/DNA_material_types.h	2008-10-12 18:32:26 UTC (rev 17051)
+++ branches/sim_physics/source/blender/makesdna/DNA_material_types.h	2008-10-12 23:39:52 UTC (rev 17052)
@@ -66,7 +66,7 @@
 	short pad5[3];
 	
 	/* volumetrics */
-	float vol_alphathresh;
+	float vol_density_scale;
 	float vol_stepsize, vol_shade_stepsize;
 	float vol_absorption, vol_scattering;
 	float vol_absorption_col[3];

Modified: branches/sim_physics/source/blender/render/intern/source/pointdensity.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/pointdensity.c	2008-10-12 18:32:26 UTC (rev 17051)
+++ branches/sim_physics/source/blender/render/intern/source/pointdensity.c	2008-10-12 23:39:52 UTC (rev 17052)
@@ -255,7 +255,7 @@
 void accum_density(void *userdata, int index, float squared_dist)
 {
 	PointDensityRangeData *pdr = (PointDensityRangeData *)userdata;
-	const float dist = pdr->squared_radius - squared_dist;
+	const float dist = (pdr->squared_radius - squared_dist) / pdr->squared_radius * 0.5f;
 	float density;
 	
 	if (pdr->falloff_type == TEX_PD_FALLOFF_STD)
@@ -287,7 +287,7 @@
 	float density=0.0f;
 	float vec[3] = {0.0, 0.0, 0.0};
 	float tv[3];
-	float turb;
+	float turb, noise_fac;
 	
 	if ((!pd) || (!pd->point_tree)) {
 		texres->tin = 0.0f;
@@ -299,6 +299,7 @@
 	pdr.point_data = pd->point_data;
 	pdr.falloff_type = pd->falloff_type;
 	pdr.vec = vec;
+	noise_fac = pd->noise_fac * 0.5f;	/* better default */
 	
 	if (pd->flag & TEX_PD_TURBULENCE) {
 		VECCOPY(tv, texvec);
@@ -313,9 +314,9 @@
 		
 		turb -= 0.5f;	/* re-center 0.0-1.0 range around 0 to prevent offsetting result */
 		
-		tv[0] = texvec[0] + pd->noise_fac * turb;
-		tv[1] = texvec[1] + pd->noise_fac * turb;
-		tv[2] = texvec[2] + pd->noise_fac * turb;
+		tv[0] = texvec[0] + noise_fac * turb;
+		tv[1] = texvec[1] + noise_fac * turb;
+		tv[2] = texvec[2] + noise_fac * turb;
 		
 		/* do density lookup with altered coordinates */
 		BLI_bvhtree_range_query(pd->point_tree, tv, pd->radius, accum_density, &pdr);

Modified: branches/sim_physics/source/blender/render/intern/source/volumetric.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/volumetric.c	2008-10-12 18:32:26 UTC (rev 17051)
+++ branches/sim_physics/source/blender/render/intern/source/volumetric.c	2008-10-12 23:39:52 UTC (rev 17052)
@@ -131,13 +131,14 @@
 float vol_get_density(struct ShadeInput *shi, float *co)
 {
 	float density = shi->mat->alpha;
+	float density_scale = shi->mat->vol_density_scale;
 	float col[3] = {0.0, 0.0, 0.0};
 	
 	if (shi->mat->flag & MA_IS_TEXTURED) {
 		do_volume_tex(shi, co, MAP_ALPHA, col, &density);
 	}
 	
-	return density;
+	return density * density_scale;
 }
 
 

Modified: branches/sim_physics/source/blender/src/buttons_shading.c
===================================================================
--- branches/sim_physics/source/blender/src/buttons_shading.c	2008-10-12 18:32:26 UTC (rev 17051)
+++ branches/sim_physics/source/blender/src/buttons_shading.c	2008-10-12 23:39:52 UTC (rev 17052)
@@ -4363,7 +4363,7 @@
 	
 	uiBlockBeginAlign(block);
 	uiDefButF(block, NUM, B_MATPRV, "Step Size: ",
-		X2CLM1, yco-=BUTH, BUTW2, BUTH, &(ma->vol_stepsize), 0.001, 100.0, 10, 2, "Ray marching step size");
+		X2CLM1, yco-=BUTH, BUTW2, BUTH, &(ma->vol_stepsize), 0.001, 100.0, 100, 2, "Ray marching step size");
 	uiBlockEndAlign(block);
 	
 	yco -= YSPACE;
@@ -4372,7 +4372,7 @@
 	uiDefButBitS(block, TOG, MA_VOL_ATTENUATED, B_MATPRV, "Shading",
 		X2CLM1, yco-=BUTH, BUTW2, BUTH, &(ma->vol_shadeflag), 0, 0, 0, 0, "Uses absorption for light attenuation");
 	uiDefButF(block, NUM, B_MATPRV, "Step Size: ",
-		X2CLM1, yco-=BUTH, BUTW2, BUTH, &(ma->vol_shade_stepsize), 0.001, 100.0, 10, 2, "Step");
+		X2CLM1, yco-=BUTH, BUTW2, BUTH, &(ma->vol_shade_stepsize), 0.001, 100.0, 100, 2, "Step");
 	uiBlockEndAlign(block);
 	
 	yco -= YSPACE;
@@ -4389,14 +4389,18 @@
 		
 	yco = PANEL_YMAX;
 	
+	uiBlockBeginAlign(block);
 	uiDefButF(block, NUMSLI, B_MATPRV, "Density: ",
-		X2CLM2, yco-=BUTH, BUTW2, BUTH, &(ma->alpha), 0.0, 1.0, 0, 0, "Base opacity value");
+		X2CLM2, yco-=BUTH, BUTW2, BUTH, &(ma->alpha), 0.0, 1.0, 0, 0, "Base density value - textured density is added on top");
+	uiDefButF(block, NUM, B_MATPRV, "Density Scale: ",
+		X2CLM2, yco-=BUTH, BUTW2, BUTH, &(ma->vol_density_scale), 0.000001, 100.0, 100, 2, "Global density multiplier");
+	uiBlockEndAlign(block);
 	
 	yco -= YSPACE;
 	
 	uiBlockBeginAlign(block);
 	uiDefButF(block, NUM, B_MATPRV, "Absorption: ",
-		X2CLM2, yco-=BUTH, BUTW2, BUTH, &(ma->vol_absorption), 0.0, 10.0, 10, 0, "Multiplier for absorption");
+		X2CLM2, yco-=BUTH, BUTW2, BUTH, &(ma->vol_absorption), 0.0, 100.0, 10, 0, "Multiplier for absorption");
 	uiDefButF(block, COL, B_MATPRV, "",
 		X2CLM2, yco-=BUTH, BUTW2, BUTH, ma->vol_absorption_col, 0, 0, 0, B_MATCOL, "");
 	uiBlockEndAlign(block);
@@ -4413,7 +4417,7 @@
 	yco -= YSPACE;
 	
 	uiDefButF(block, NUM, B_MATPRV, "Scattering: ",
-		X2CLM2, yco-=BUTH, BUTW2, BUTH, &(ma->vol_scattering), 0.0, 10.0, 10, 0, "Multiplier for scattering");
+		X2CLM2, yco-=BUTH, BUTW2, BUTH, &(ma->vol_scattering), 0.0, 100.0, 10, 0, "Multiplier for scattering");
 }
 
 static void material_panel_nodes(Material *ma)





More information about the Bf-blender-cvs mailing list