[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16739] branches/sim_physics/source/ blender: * Some more tweaks to particle density rendering.

Matt Ebb matt at mke3.net
Fri Sep 26 09:12:36 CEST 2008


Revision: 16739
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16739
Author:   broken
Date:     2008-09-26 09:12:36 +0200 (Fri, 26 Sep 2008)

Log Message:
-----------
* Some more tweaks to particle density rendering. I'm not 100% 
sure if this is 'correct' but so far in testing it's been working 
pretty well.

This also exposes a new 'Nearest' value, to determine how many
nearby particles are taken into account when determining density. 
A greater number is more accurate, but slower.

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/renderdatabase.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-09-26 06:25:35 UTC (rev 16738)
+++ branches/sim_physics/source/blender/blenkernel/intern/material.c	2008-09-26 07:12:36 UTC (rev 16739)
@@ -173,7 +173,9 @@
 	ma->vol_scattering = 1.0f;
 	ma->vol_absorption_col[0] = ma->vol_absorption_col[1] = ma->vol_absorption_col[2] = 0.0f;
 	ma->vol_raydepth = 15;
-
+	ma->vol_part_maxnearest = 5;
+	ma->vol_part_searchradius = 0.2f;
+	
 	ma->mode= MA_TRACEBLE|MA_SHADBUF|MA_SHADOW|MA_RADIO|MA_RAYBIAS|MA_TANGENT_STR;
 
 	ma->preview = NULL;

Modified: branches/sim_physics/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/sim_physics/source/blender/blenloader/intern/readfile.c	2008-09-26 06:25:35 UTC (rev 16738)
+++ branches/sim_physics/source/blender/blenloader/intern/readfile.c	2008-09-26 07:12:36 UTC (rev 16739)
@@ -7872,6 +7872,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_raydepth == 0) ma->vol_raydepth = 15;
+				if (ma->vol_part_maxnearest == 0) ma->vol_part_maxnearest = 5;
+				if (ma->vol_part_searchradius < 0.001f) ma->vol_part_searchradius = 0.20;
 			}
 		}
 	}

Modified: branches/sim_physics/source/blender/makesdna/DNA_material_types.h
===================================================================
--- branches/sim_physics/source/blender/makesdna/DNA_material_types.h	2008-09-26 06:25:35 UTC (rev 16738)
+++ branches/sim_physics/source/blender/makesdna/DNA_material_types.h	2008-09-26 07:12:36 UTC (rev 16739)
@@ -72,8 +72,11 @@
 	float vol_absorption_col[3];
 	float vol_part_searchradius;
 	short vol_raydepth;
+	short vol_part_maxnearest;
 	short vol_shadeflag;
+	short vol_pad[3];
 	
+	
 	float fresnel_mir, fresnel_mir_i;
 	float fresnel_tra, fresnel_tra_i;
 	float filter;		/* filter added, for raytrace transparency and transmissivity */

Modified: branches/sim_physics/source/blender/render/intern/source/renderdatabase.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/renderdatabase.c	2008-09-26 06:25:35 UTC (rev 16738)
+++ branches/sim_physics/source/blender/render/intern/source/renderdatabase.c	2008-09-26 07:12:36 UTC (rev 16739)
@@ -1051,7 +1051,7 @@
 	BLI_addtail(&re->vol_particles, pr);
 	*/
 	
-	BLI_kdtree_insert(re->particles_tree, index, co, vec);
+	BLI_kdtree_insert(re->particles_tree, index, co, NULL);
 	
 	
 }

Modified: branches/sim_physics/source/blender/render/intern/source/volumetric.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/volumetric.c	2008-09-26 06:25:35 UTC (rev 16738)
+++ branches/sim_physics/source/blender/render/intern/source/volumetric.c	2008-09-26 07:12:36 UTC (rev 16739)
@@ -129,8 +129,8 @@
 }
 
 /* need to figure out a good default here */ 
-#define MAX_PARTICLES_NEAREST	10
-float get_particle_density(float *co, float radius)
+#define MAX_PARTICLES_NEAREST	50
+float get_particle_density(float *co, float radius, int max_nearest)
 {
 	KDTreeNearest nearest[MAX_PARTICLES_NEAREST];
 	float density=0.0f;
@@ -140,14 +140,20 @@
 	 * can check for existence of particle kdtree better later on */
 	if(R.r.scemode & R_PREVIEWBUTS)	return;
 	
-	neighbours = BLI_kdtree_find_n_nearest(R.particles_tree, MAX_PARTICLES_NEAREST, co, NULL, nearest);
+	neighbours = BLI_kdtree_find_n_nearest(R.particles_tree, max_nearest, co, NULL, nearest);
 	
 	for(n=1; n<neighbours; n++) {
 		if ( nearest[n].dist < radius) {
-			/* TODO: proper falloff/filter */
-			density += 3.0f * (radius - nearest[n].dist);
+			float dist = 1.0 - (nearest[n].dist / radius);
+			
+			density += 3.0f*dist*dist - 2.0f*dist*dist*dist;
+
+			
 		}
 	}
+	
+	density /= neighbours;
+	density *= 1.0 / radius;
 
 	return density;
 }
@@ -158,7 +164,7 @@
 	float col[3] = {0.0, 0.0, 0.0};
 	
 	if (shi->mat->vol_shadeflag & MA_VOL_PARTICLES) {
-		density += get_particle_density(co, shi->mat->vol_part_searchradius);
+		density += get_particle_density(co, shi->mat->vol_part_searchradius, shi->mat->vol_part_maxnearest);
 	}
 	else if (shi->mat->flag & MA_IS_TEXTURED) {
 		do_volume_tex(shi, co, MAP_ALPHA, col, &density);

Modified: branches/sim_physics/source/blender/src/buttons_shading.c
===================================================================
--- branches/sim_physics/source/blender/src/buttons_shading.c	2008-09-26 06:25:35 UTC (rev 16738)
+++ branches/sim_physics/source/blender/src/buttons_shading.c	2008-09-26 07:12:36 UTC (rev 16739)
@@ -4287,8 +4287,10 @@
 	uiBlockBeginAlign(block);
 	uiDefButBitS(block, TOG, MA_VOL_PARTICLES, B_MATPRV, "Particles",
 		X2CLM1, yco-=BUTH, BUTW2, BUTH, &(ma->vol_shadeflag), 0, 0, 0, 0, "Render global particle cache");
-	uiDefButF(block, NUM, B_MATPRV, "Search Radius: ",
+	uiDefButF(block, NUM, B_MATPRV, "Radius: ",
 		X2CLM1, yco-=BUTH, BUTW2, BUTH, &(ma->vol_part_searchradius), 0.001, 100.0, 10, 2, "Radius to look for nearby particles within");
+	uiDefButS(block, NUM, B_MATPRV, "Nearby: ",
+		X2CLM1, yco-=BUTH, BUTW2, BUTH, &(ma->vol_part_maxnearest), 2.0, 30.0, 10, 2, "The number of nearby particles to check for density");
 	uiBlockEndAlign(block);
 }
 





More information about the Bf-blender-cvs mailing list