[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16947] branches/sim_physics/source/ blender: * New point density update: Turbulence

Matt Ebb matt at mke3.net
Mon Oct 6 14:25:22 CEST 2008


Revision: 16947
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16947
Author:   broken
Date:     2008-10-06 14:25:22 +0200 (Mon, 06 Oct 2008)

Log Message:
-----------
* New point density update: Turbulence

This addition allows you to perturb the point density with noise, to give 
the impression of more resolution. It's a quick way to add detail, without 
having to use large, complex, and slower to render particle systems.

Rather than just overlaying noise, like you might do by adding a secondary 
clouds texture, it uses noise to perturb the actual coordinate looked up 
in the density evaluation. This gives a much better looking result, as it 
actually alters the original density.

Comparison of the particle cloud render without, and with added turbulence 
(the render with turbulence only renders slightly more slowly):
http://mke3.net/blender/devel/rendering/volumetrics/pd_turbulence.jpg

Using the same constant noise function/spatial coordinates will give a 
static appearance. This is fine (and quicker) if the particles aren't 
moving, but on animated particle systems, it looks bad, as if the 
particles are moving through a static noise field. To overcome this, there 
are additional options for particle systems, to influence the turbulence 
with the particles' average velocity, or average angular velocity. This 
information is only available for particle systems at the present.

Here you can see the (dramatic) difference between no turbulence, static 
turbulence, and turbulence influenced by particle velocity:
http://mke3.net/blender/devel/rendering/volumetrics/turbu_compare.mov

Modified Paths:
--------------
    branches/sim_physics/source/blender/blenkernel/intern/texture.c
    branches/sim_physics/source/blender/blenloader/intern/readfile.c
    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/src/buttons_shading.c

Modified: branches/sim_physics/source/blender/blenkernel/intern/texture.c
===================================================================
--- branches/sim_physics/source/blender/blenkernel/intern/texture.c	2008-10-06 10:24:32 UTC (rev 16946)
+++ branches/sim_physics/source/blender/blenkernel/intern/texture.c	2008-10-06 12:25:22 UTC (rev 16947)
@@ -878,6 +878,10 @@
 	pd->source = TEX_PD_PSYS;
 	pd->point_tree = NULL;
 	pd->point_data = NULL;
+	pd->noise_size = 0.5f;
+	pd->noise_depth = 1;
+	pd->noise_fac = 1.0f;
+	pd->noise_influence = TEX_PD_NOISE_STATIC;
 	
 	return pd;
 } 

Modified: branches/sim_physics/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/sim_physics/source/blender/blenloader/intern/readfile.c	2008-10-06 10:24:32 UTC (rev 16946)
+++ branches/sim_physics/source/blender/blenloader/intern/readfile.c	2008-10-06 12:25:22 UTC (rev 16947)
@@ -7882,6 +7882,7 @@
 	
 	if (main->versionfile <= 247) {
 		Material *ma;
+		Tex *tex;
 		
 		for(ma=main->mat.first; ma; ma= ma->id.next) {
 			/* trigger for non-volumetric file */
@@ -7893,6 +7894,18 @@
 				ma->vol_absorption_col[0] = ma->vol_absorption_col[1] = ma->vol_absorption_col[2] = 0.0f;	
 			}
 		}
+		
+		for(tex=main->tex.first; tex; tex= tex->id.next) {
+			if (tex->pd == NULL) 
+				tex->pd = BKE_add_pointdensity();
+			else if (tex->pd->noise_size < 0.0001f) {
+				tex->pd->noise_size = 0.5f;
+				tex->pd->noise_depth = 1;
+				tex->pd->noise_fac = 1.0f;
+				tex->pd->noise_influence = TEX_PD_NOISE_STATIC;
+			}
+		}
+		
 	}
 	
 	/* set the curve radius interpolation to 2.47 default - easy */

Modified: branches/sim_physics/source/blender/makesdna/DNA_texture_types.h
===================================================================
--- branches/sim_physics/source/blender/makesdna/DNA_texture_types.h	2008-10-06 10:24:32 UTC (rev 16946)
+++ branches/sim_physics/source/blender/makesdna/DNA_texture_types.h	2008-10-06 12:25:22 UTC (rev 16947)
@@ -144,9 +144,14 @@
 	short pdpad2;
 	
 	void *point_tree;		/* the acceleration tree containing points */
-	void *point_data;		/* dynamically allocated extra for extra information, like particle age */
-	int pdpad3[2];
+	float *point_data;		/* dynamically allocated extra for extra information, like particle age */
 	
+	float noise_size;
+	short noise_depth;
+	short noise_influence;
+	float noise_fac;
+	float pdpad4;
+	
 } PointDensity;
 
 typedef struct Tex {
@@ -429,6 +434,15 @@
 #define TEX_PD_OBJECTSPACE	1
 #define TEX_PD_WORLDSPACE	2
 
+/* flag */
+#define TEX_PD_TURBULENCE	1
 
+
+/* noise_influence */
+#define TEX_PD_NOISE_STATIC		0
+#define TEX_PD_NOISE_VEL		1
+#define TEX_PD_NOISE_ANGVEL		2
+#define TEX_PD_NOISE_TIME		3
+
 #endif
 

Modified: branches/sim_physics/source/blender/render/intern/source/pointdensity.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/pointdensity.c	2008-10-06 10:24:32 UTC (rev 16946)
+++ branches/sim_physics/source/blender/render/intern/source/pointdensity.c	2008-10-06 12:25:22 UTC (rev 16947)
@@ -30,6 +30,7 @@
 #include "MEM_guardedalloc.h"
 
 #include "BLI_arithb.h"
+#include "BLI_blenlib.h"
 #include "BLI_kdopbvh.h"
 
 #include "BKE_DerivedMesh.h"
@@ -45,13 +46,13 @@
 #include "renderdatabase.h"
 #include "texture.h"
 
-
 static void pointdensity_cache_psys(Render *re, PointDensity *pd, Object *ob, ParticleSystem *psys)
 {
 	DerivedMesh* dm;
 	ParticleKey state;
 	float cfra=bsystem_time(ob,(float)G.scene->r.cfra,0.0);
 	int i, childexists;
+	int total_particles;
 	float partco[3];
 	float obview[4][4];
 	
@@ -74,12 +75,16 @@
 	/* in case ob->imat isn't up-to-date */
 	Mat4Invert(ob->imat, ob->obmat);
 	
-	pd->point_tree = BLI_bvhtree_new(psys->totpart+psys->totchild, 0.0, 2, 6);
+	total_particles = psys->totpart+psys->totchild;
 	
+	pd->point_tree = BLI_bvhtree_new(total_particles, 0.0, 2, 6);
+	if (pd->noise_influence != TEX_PD_NOISE_STATIC)
+		pd->point_data = MEM_mallocN(sizeof(float)*3*total_particles, "point_data");
+	
 	if (psys->totchild > 0 && !(psys->part->draw & PART_DRAW_PARENT))
 		childexists = 1;
 	
-	for (i = 0; i < psys->totpart + psys->totchild; i++) {
+	for (i = 0; i < total_particles; i++) {
 
 		state.time = cfra;
 		if(psys_get_particle_state(ob, psys, i, &state, 0)) {
@@ -97,6 +102,16 @@
 			}
 			
 			BLI_bvhtree_insert(pd->point_tree, i, partco, 1);
+			
+			if (pd->noise_influence == TEX_PD_NOISE_VEL) {
+				pd->point_data[i*3 + 0] = state.vel[0];
+				pd->point_data[i*3 + 1] = state.vel[1];
+				pd->point_data[i*3 + 2] = state.vel[2];
+			} else if (pd->noise_influence == TEX_PD_NOISE_ANGVEL) {
+				pd->point_data[i*3 + 0] = state.ave[0];
+				pd->point_data[i*3 + 1] = state.ave[1];
+				pd->point_data[i*3 + 2] = state.ave[2];
+			}
 		}
 	}
 	
@@ -131,7 +146,6 @@
 			VecSubf(ver_co, ver_co, obr->ob->loc);
 		} else {
 			/* TEX_PD_WORLDSPACE */
-
 		}
 		
 		BLI_bvhtree_insert(pd->point_tree, i, ver_co, 1);
@@ -232,6 +246,7 @@
     float *density;
     float squared_radius;
     float *point_data;
+	float *vec;
     short falloff_type;   
 } PointDensityRangeData;
 
@@ -239,17 +254,26 @@
 {
 	PointDensityRangeData *pdr = (PointDensityRangeData *)userdata;
 	const float dist = pdr->squared_radius - squared_dist;
+	float density;
 	
 	if (pdr->falloff_type == TEX_PD_FALLOFF_STD)
-		*pdr->density += dist;
+		density = dist;
 	else if (pdr->falloff_type == TEX_PD_FALLOFF_SMOOTH)
-		*pdr->density+= 3.0f*dist*dist - 2.0f*dist*dist*dist;
+		density = 3.0f*dist*dist - 2.0f*dist*dist*dist;
 	else if (pdr->falloff_type == TEX_PD_FALLOFF_SHARP)
-		*pdr->density+= dist*dist;
+		density = dist*dist;
 	else if (pdr->falloff_type == TEX_PD_FALLOFF_CONSTANT)
-		*pdr->density+= pdr->squared_radius;
+		density = pdr->squared_radius;
 	else if (pdr->falloff_type == TEX_PD_FALLOFF_ROOT)
-		*pdr->density+= sqrt(dist);
+		density = sqrt(dist);
+	
+	if (pdr->point_data) {
+		pdr->vec[0] += pdr->point_data[index*3 + 0];// * density;
+		pdr->vec[1] += pdr->point_data[index*3 + 1];// * density;
+		pdr->vec[2] += pdr->point_data[index*3 + 2];// * density;
+	}
+	
+	*pdr->density += density;
 }
 
 #define MAX_POINTS_NEAREST	25
@@ -259,6 +283,9 @@
 	PointDensity *pd = tex->pd;
 	PointDensityRangeData pdr;
 	float density=0.0f;
+	float vec[3] = {0.0, 0.0, 0.0};
+	float tv[3];
+	float turb;
 	
 	if ((!pd) || (!pd->point_tree)) {
 		texres->tin = 0.0f;
@@ -269,16 +296,40 @@
 	pdr.density = &density;
 	pdr.point_data = pd->point_data;
 	pdr.falloff_type = pd->falloff_type;
+	pdr.vec = vec;
 	
-	BLI_bvhtree_range_query(pd->point_tree, texvec, pd->radius, accum_density, &pdr);
+	if (pd->flag & TEX_PD_TURBULENCE) {
+		VECCOPY(tv, texvec);
+		
+		/* find the average speed vectors, for perturbing final density lookup with */
+		BLI_bvhtree_range_query(pd->point_tree, texvec, pd->radius, accum_density, &pdr);
+		
+		density = 0.0f;
+		Normalize(vec);
 	
+		turb = BLI_turbulence(pd->noise_size, texvec[0]+vec[0], texvec[1]+vec[1], texvec[2]+vec[2], pd->noise_depth);
+		
+		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;
+		
+		/* do density lookup with altered coordinates */
+		BLI_bvhtree_range_query(pd->point_tree, tv, pd->radius, accum_density, &pdr);
+	}
+	else
+		BLI_bvhtree_range_query(pd->point_tree, texvec, pd->radius, accum_density, &pdr);
+
 	texres->tin = density;
 
+	//texres->tr = vec[0];
+	//texres->tg = vec[1];
+	//texres->tb = vec[2];
+	
+	return TEX_INT;
+	
 	/*
-	texres->tr = 1.0f;
-	texres->tg = 1.0f;
-	texres->tb = 0.0f;
-	
 	BRICONTRGB;
 	
 	texres->ta = 1.0;
@@ -288,7 +339,7 @@
 	}
 	*/
 	
-	BRICONT;
+	//BRICONT;
 	
-	return rv;
+	//return rv;
 }

Modified: branches/sim_physics/source/blender/src/buttons_shading.c
===================================================================
--- branches/sim_physics/source/blender/src/buttons_shading.c	2008-10-06 10:24:32 UTC (rev 16946)
+++ branches/sim_physics/source/blender/src/buttons_shading.c	2008-10-06 12:25:22 UTC (rev 16947)
@@ -759,15 +759,42 @@
 		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|Constant %x3|Root %x4",
-				X2CLM1, yco-=BUTH, BUTW2, BUTH, &pd->falloff_type, 0.0, 0.0, 0, 0, "Falloff type");
+			X2CLM1, yco-=BUTH, BUTW2, BUTH, &pd->falloff_type, 0.0, 0.0, 0, 0, "Falloff type");
 		
+		yco -= YSPACE;
+		
+		
+		uiBlockBeginAlign(block);
+		uiDefButBitS(block, TOG, TEX_PD_TURBULENCE, B_REDR, "Turbulence",
+			X2CLM1, yco-=BUTH, BUTW2, BUTH, &(pd->flag), 0, 0, 0, 0, "Add directed turbulence to the density estimation");
+			
+		if (pd->flag & TEX_PD_TURBULENCE) {
+			
+			uiDefButF(block, NUM, B_REDR, "Size: ",
+				X2CLM1, yco-=BUTH, BUTW2, BUTH, &(pd->noise_size), 0.001, 100.0, 10, 2, "Turbulence size");
+			uiDefButS(block, NUM, B_REDR, "Depth: ",
+				X2CLM1, yco-=BUTH, BUTW2, BUTH, &(pd->noise_depth), 0.0, 100.0, 10, 2, "Turbulence depth");
+			uiDefButF(block, NUM, B_REDR, "Strength: ",
+				X2CLM1, yco-=BUTH, BUTW2, BUTH, &(pd->noise_fac), 0.001, 100.0, 10, 2, "");
+			
+			uiBlockEndAlign(block);
+			
+			yco -= YSPACE;
+
+			if (pd->source == TEX_PD_PSYS) {
+				uiDefButS(block, MENU, B_REDR, "Noise Influence %t|Static %x0|Velocity %x1|Angular Velocity %x2",
+					X2CLM1, yco-=BUTH, BUTW2, BUTH, &(pd->noise_influence), 0.0, 0.0, 0, 0, "Noise Influence");
+			}
+		}
+		uiBlockEndAlign(block);
+
 		yco = PANEL_YMAX;
 		
 		uiDefBut(block, LABEL, B_NOP, "Point data source:",
-				X2CLM2, yco-=BUTH, BUTW2, BUTH, 0, 0, 0, 0, 0, "");
+			X2CLM2, yco-=BUTH, BUTW2, BUTH, 0, 0, 0, 0, 0, "");
 		
 		uiDefButS(block, MENU, B_TEXREDR_PRV, "Particle System %x0|Object Vertices %x1",
-				X2CLM2, yco-=BUTH, BUTW2, BUTH, &pd->source, 0.0, 0.0, 0, 0, "Source");
+			X2CLM2, yco-=BUTH, BUTW2, BUTH, &pd->source, 0.0, 0.0, 0, 0, "Source");
 		
 		yco -= YSPACE;
 		
@@ -788,6 +815,7 @@
 				X2CLM2, yco-=BUTH, BUTW2, BUTH, 0, 0, 0, 0, 0, "");
 			uiDefButS(block, MENU, B_TEXREDR_PRV, "Emit Object Location %x0|Emit Object Space %x1|Global Space %x2",
 				X2CLM2, yco-=BUTH, BUTW2, BUTH, &pd->psys_cache_space, 0.0, 0.0, 0, 0, "Co-ordinate system to cache particles in");
+				
 		}
 		else if (pd->source == TEX_PD_OBJECT) {
 			uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_REDR, "Ob:",





More information about the Bf-blender-cvs mailing list