[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16734] branches/sim_physics/source/ blender: Wheee!

Matt Ebb matt at mke3.net
Fri Sep 26 03:54:32 CEST 2008


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

Log Message:
-----------
Wheee!

Initial commit for supporting rendering particles directly as 
volume density. It works by looking up how many particles are 
within a specified radius of the currently shaded point and using 
that to calculate density (which is used just as any other 
measure of density would be).

http://mke3.net/blender/devel/rendering/volumetrics/smoke_test01.mov
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test01.blend

Right now it's an early implementation, just to see that it can 
work - it may end up changing quite a bit. Currently, it's just a 
single switch on the volume material - it looks up all particles 
in the scene for density at the current shaded point in world 
space (so the volume region must enclose the particles in order 
to render them.

This will probably change - one idea I have is to make the 
particle density estimation a procedural texture with options for:
* the object and particle system to use
* the origin of the co-ordinate system, i.e. object center, world 
space, etc.

This would allow you in a sense, to instance particle systems for 
render - you only need to bake one particle system, but you can 
render it anywhere.

Anyway, plenty of work to do here, firstly on getting a nice
density evaluation with falloff etc...

Modified Paths:
--------------
    branches/sim_physics/source/blender/makesdna/DNA_material_types.h
    branches/sim_physics/source/blender/render/intern/include/render_types.h
    branches/sim_physics/source/blender/render/intern/include/renderdatabase.h
    branches/sim_physics/source/blender/render/intern/source/convertblender.c
    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/makesdna/DNA_material_types.h
===================================================================
--- branches/sim_physics/source/blender/makesdna/DNA_material_types.h	2008-09-25 21:04:41 UTC (rev 16733)
+++ branches/sim_physics/source/blender/makesdna/DNA_material_types.h	2008-09-26 01:54:31 UTC (rev 16734)
@@ -70,7 +70,7 @@
 	float vol_stepsize, vol_shade_stepsize;
 	float vol_absorption, vol_scattering;
 	float vol_absorption_col[3];
-	float vpad2;
+	float vol_part_searchradius;
 	short vol_raydepth;
 	short vol_shadeflag;
 	
@@ -351,6 +351,7 @@
 #define MA_VOL_SHADED		1
 #define MA_VOL_ATTENUATED	2
 #define MA_VOL_SHADOWED		4
+#define MA_VOL_PARTICLES	8
 
 #endif
 

Modified: branches/sim_physics/source/blender/render/intern/include/render_types.h
===================================================================
--- branches/sim_physics/source/blender/render/intern/include/render_types.h	2008-09-25 21:04:41 UTC (rev 16733)
+++ branches/sim_physics/source/blender/render/intern/include/render_types.h	2008-09-26 01:54:31 UTC (rev 16734)
@@ -198,6 +198,8 @@
 	ListBase *sss_points;
 	struct Material *sss_mat;
 
+	struct KDTree *particles_tree;
+
 	ListBase customdata_names;
 
 	struct Object *excludeob;
@@ -347,6 +349,16 @@
 
 /* ------------------------------------------------------------------------- */
 
+typedef struct ParticleRen
+{
+	struct ParticleRen *next, *prev;
+	float co[3];	// location
+	// float col[3]; // colour
+	// float vec[3]; // direction
+} ParticleRen;
+
+/* ------------------------------------------------------------------------- */
+
 typedef struct StrandVert {
 	float co[3];
 	float strandco;

Modified: branches/sim_physics/source/blender/render/intern/include/renderdatabase.h
===================================================================
--- branches/sim_physics/source/blender/render/intern/include/renderdatabase.h	2008-09-25 21:04:41 UTC (rev 16733)
+++ branches/sim_physics/source/blender/render/intern/include/renderdatabase.h	2008-09-26 01:54:31 UTC (rev 16734)
@@ -98,6 +98,8 @@
 struct HaloRen *RE_inithalo_particle(struct Render *re, struct ObjectRen *obr, struct DerivedMesh *dm, struct Material *ma,   float *vec,   float *vec1, float *orco, float *uvco, float hasize, float vectsize, int seed);
 struct StrandBuffer *RE_addStrandBuffer(struct ObjectRen *obr, int totvert);
 
+struct ParticleRen *RE_cache_particle(Render *re, float *co, int index, float *vec);
+
 struct ObjectRen *RE_addRenderObject(struct Render *re, struct Object *ob, struct Object *par, int index, int psysindex, int lay);
 struct ObjectInstanceRen *RE_addRenderInstance(struct Render *re, struct ObjectRen *obr, struct Object *ob, struct Object *par, int index, int psysindex, float mat[][4], int lay);
 void RE_makeRenderInstances(struct Render *re);

Modified: branches/sim_physics/source/blender/render/intern/source/convertblender.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/convertblender.c	2008-09-25 21:04:41 UTC (rev 16733)
+++ branches/sim_physics/source/blender/render/intern/source/convertblender.c	2008-09-26 01:54:31 UTC (rev 16734)
@@ -41,6 +41,7 @@
 #include "BLI_rand.h"
 #include "BLI_memarena.h"
 #include "BLI_ghash.h"
+#include "BLI_kdtree.h"
 
 #include "DNA_armature_types.h"
 #include "DNA_camera_types.h"
@@ -1475,8 +1476,9 @@
 			static_particle_strand(re, obr, ma, orco, surfnor, uvco, totuv, mcol, totcol, loc, loc1, time, first, line, adapt, adapt_angle, adapt_pix, override_uv);
 	}
 	else{
-		har= RE_inithalo_particle(re, obr, dm, ma, loc, NULL, orco, uvco, size, 0.0, seed);
-		if(har) har->lay= obr->ob->lay;
+		//har= RE_inithalo_particle(re, obr, dm, ma, loc, NULL, orco, uvco, size, 0.0, seed);
+		//if(har) har->lay= obr->ob->lay;
+		RE_cache_particle(re, loc, 0, loc1);
 	}
 }
 static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem *psys, int timeoffset)
@@ -1703,6 +1705,8 @@
 	if(path_nbr==0)
 		psys->lattice=psys_get_lattice(ob,psys);
 
+	re->particles_tree = BLI_kdtree_new(totpart+totchild);
+
 /* 3. start creating renderable things */
 	for(a=0,pa=pars; a<totpart+totchild; a++, pa++, seed++) {
 		random = rng_getFloat(rng);
@@ -2049,6 +2053,9 @@
 		strandbuf->surface= cache_strand_surface(re, obr, psmd->dm, mat, timeoffset);
 
 /* 4. clean up */
+	if (re->particles_tree)
+		BLI_kdtree_balance(re->particles_tree);
+
 	if(ma) do_mat_ipo(ma);
 
 	if(orco1)
@@ -4410,6 +4417,8 @@
 	
 	BLI_freelistN(&re->lampren);
 	BLI_freelistN(&re->lights);
+		
+	BLI_kdtree_free(re->particles_tree);
 
 	free_renderdata_tables(re);
 	

Modified: branches/sim_physics/source/blender/render/intern/source/renderdatabase.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/renderdatabase.c	2008-09-25 21:04:41 UTC (rev 16733)
+++ branches/sim_physics/source/blender/render/intern/source/renderdatabase.c	2008-09-26 01:54:31 UTC (rev 16734)
@@ -1041,6 +1041,21 @@
 	return har;
 }
 
+ParticleRen *RE_cache_particle(Render *re, float *co, int index, float *vec)
+{
+	/*
+	ParticleRen *pr;
+	
+	pr= (LampRen *)MEM_callocN(sizeof(ParticleRen),"particleren");
+	VECCOPY(pr->co, co);
+	BLI_addtail(&re->vol_particles, pr);
+	*/
+	
+	BLI_kdtree_insert(re->particles_tree, index, co, vec);
+	
+	
+}
+
 HaloRen *RE_inithalo_particle(Render *re, ObjectRen *obr, DerivedMesh *dm, Material *ma,   float *vec,   float *vec1, 
 				  float *orco, float *uvco, float hasize, float vectsize, int seed)
 {

Modified: branches/sim_physics/source/blender/render/intern/source/volumetric.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/volumetric.c	2008-09-25 21:04:41 UTC (rev 16733)
+++ branches/sim_physics/source/blender/render/intern/source/volumetric.c	2008-09-26 01:54:31 UTC (rev 16734)
@@ -34,6 +34,7 @@
 #include "BLI_blenlib.h"
 #include "BLI_arithb.h"
 #include "BLI_rand.h"
+#include "BLI_kdtree.h"
 
 #include "RE_shader_ext.h"
 #include "RE_raytrace.h"
@@ -127,14 +128,41 @@
 	}
 }
 
+/* need to figure out a good default here */ 
+#define MAX_PARTICLES_NEAREST	10
+float get_particle_density(float *co, float radius)
+{
+	KDTreeNearest nearest[MAX_PARTICLES_NEAREST];
+	float density=0.0f;
+	int n, neighbours=0;
+	
+	/* no particles in preview for now - 
+	 * 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);
+	
+	for(n=1; n<neighbours; n++) {
+		if ( nearest[n].dist < radius) {
+			/* TODO: proper falloff/filter */
+			density += 3.0f * (radius - nearest[n].dist);
+		}
+	}
+
+	return density;
+}
+
 float vol_get_density(struct ShadeInput *shi, float *co)
 {
 	float density = shi->mat->alpha;
 	float col[3] = {0.0, 0.0, 0.0};
-		
-	/* do any density gain stuff here */
-	if (shi->mat->flag & MA_IS_TEXTURED)
+	
+	if (shi->mat->vol_shadeflag & MA_VOL_PARTICLES) {
+		density += get_particle_density(co, shi->mat->vol_part_searchradius);
+	}
+	else if (shi->mat->flag & MA_IS_TEXTURED) {
 		do_volume_tex(shi, co, MAP_ALPHA, col, &density);
+	}
 	
 	return density;
 }
@@ -339,7 +367,6 @@
 	float tau[3], step_emit[3], step_scatter[3] = {0.0, 0.0, 0.0};
 	int s;
 	float step_sta[3], step_end[3], step_mid[3];
-	float col_behind[3];
 	float alpha;
 	float density = vol_get_density(shi, co);
 	

Modified: branches/sim_physics/source/blender/src/buttons_shading.c
===================================================================
--- branches/sim_physics/source/blender/src/buttons_shading.c	2008-09-25 21:04:41 UTC (rev 16733)
+++ branches/sim_physics/source/blender/src/buttons_shading.c	2008-09-26 01:54:31 UTC (rev 16734)
@@ -4281,6 +4281,15 @@
 	
 	uiDefButF(block, NUM, B_MATPRV, "Scattering: ",
 		X2CLM2, yco-=BUTH, BUTW2, BUTH, &(ma->vol_scattering), 0.0, 10.0, 10, 0, "Multiplier for scattering");
+		
+	yco -= YSPACE;
+	
+	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: ",
+		X2CLM1, yco-=BUTH, BUTW2, BUTH, &(ma->vol_part_searchradius), 0.001, 100.0, 10, 2, "Radius to look for nearby particles within");
+	uiBlockEndAlign(block);
 }
 
 static void material_panel_nodes(Material *ma)





More information about the Bf-blender-cvs mailing list