[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17238] branches/sim_physics/source/ blender: * Added a new turbulence type: Time.

Matt Ebb matt at mke3.net
Fri Oct 31 06:29:54 CET 2008


Revision: 17238
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17238
Author:   broken
Date:     2008-10-31 06:29:54 +0100 (Fri, 31 Oct 2008)

Log Message:
-----------
* Added a new turbulence type: Time. It's not entirely well tested, but so far working ok. It's smoother looking than 'velocity' but may need more in depth investigation.

Modified Paths:
--------------
    branches/sim_physics/source/blender/render/intern/source/pointdensity.c
    branches/sim_physics/source/blender/render/intern/source/texture.c
    branches/sim_physics/source/blender/src/buttons_shading.c

Modified: branches/sim_physics/source/blender/render/intern/source/pointdensity.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/pointdensity.c	2008-10-31 04:50:38 UTC (rev 17237)
+++ branches/sim_physics/source/blender/render/intern/source/pointdensity.c	2008-10-31 05:29:54 UTC (rev 17238)
@@ -35,6 +35,7 @@
 
 #include "BKE_DerivedMesh.h"
 #include "BKE_global.h"
+#include "BKE_lattice.h"
 #include "BKE_main.h"
 #include "BKE_object.h"
 #include "BKE_particle.h"
@@ -56,12 +57,12 @@
 	float partco[3];
 	float obview[4][4];
 	
-	/* init crap */
+	/* init everything */
 	if (!psys || !ob || !pd) return;
 	
 	Mat4MulMat4(obview, re->viewinv, ob->obmat);
 	
-	/* Just to create a valid rendering context */
+	/* Just to create a valid rendering context for particles */
 	psys_render_set(ob, psys, re->viewmat, re->winmat, re->winx, re->winy, 0);
 	
 	dm = mesh_create_derived_render(ob,CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL);
@@ -79,8 +80,10 @@
 	
 	pd->point_tree = BLI_bvhtree_new(total_particles, 0.0, 4, 6);
 	
-	if (pd->noise_influence != TEX_PD_NOISE_STATIC)
-		pd->point_data = MEM_mallocN(sizeof(float)*3*total_particles, "point_data");
+	if (pd->noise_influence == TEX_PD_NOISE_VEL)
+		pd->point_data = MEM_mallocN(sizeof(float)*3*total_particles, "velocity point data");
+	else if (pd->noise_influence == TEX_PD_NOISE_TIME)
+		pd->point_data = MEM_mallocN(sizeof(float)*total_particles, "time point data");
 	
 	if (psys->totchild > 0 && !(psys->part->draw & PART_DRAW_PARENT))
 		childexists = 1;
@@ -108,6 +111,8 @@
 				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_TIME) {
+				pd->point_data[i] = state.time;
 			}
 		}
 	}
@@ -256,7 +261,9 @@
     float *point_data;
 	float *vec;
 	float softness;
-    short falloff_type;   
+    short falloff_type;
+	short noise_influence;
+	float *time;
 } PointDensityRangeData;
 
 void accum_density(void *userdata, int index, float squared_dist)
@@ -277,10 +284,14 @@
 		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;
-	}
+		if (pdr->noise_influence == TEX_PD_NOISE_VEL) {
+			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;
+		} else if (pdr->noise_influence == TEX_PD_NOISE_TIME) {
+			*pdr->time += pdr->point_data[index]; // * density;
+		}
+	} 
 	
 	*pdr->density += density;
 }
@@ -288,12 +299,13 @@
 #define MAX_POINTS_NEAREST	25
 int pointdensitytex(Tex *tex, float *texvec, TexResult *texres)
 {
-	int rv = TEX_INT;
+	int retval = TEX_INT;
 	PointDensity *pd = tex->pd;
 	PointDensityRangeData pdr;
-	float density=0.0f;
+	float density=0.0f, time=0.0f;
 	float vec[3] = {0.0, 0.0, 0.0};
 	float tv[3];
+	float co[3];
 	float turb, noise_fac;
 	
 	if ((!pd) || (!pd->point_tree)) {
@@ -306,54 +318,53 @@
 	pdr.point_data = pd->point_data;
 	pdr.falloff_type = pd->falloff_type;
 	pdr.vec = vec;
+	pdr.time = &time;
 	pdr.softness = pd->falloff_softness;
+	pdr.noise_influence = pd->noise_influence;
 	noise_fac = pd->noise_fac * 0.5f;	/* better default */
 	
+	VECCOPY(co, texvec);
+	
 	if (pd->flag & TEX_PD_TURBULENCE) {
-		VECCOPY(tv, texvec);
+		retval |= TEX_RGB;
 		
-		/* find the average speed vectors, for perturbing final density lookup with */
-		BLI_bvhtree_range_query(pd->point_tree, texvec, pd->radius, accum_density, &pdr);
+		if (ELEM(pd->noise_influence, TEX_PD_NOISE_VEL, TEX_PD_NOISE_TIME)) {
+			/* find the average speed vectors or particle time,
+			 * for perturbing final density lookup with */
+			BLI_bvhtree_range_query(pd->point_tree, co, pd->radius, accum_density, &pdr);
+			density = 0.0f;
+			
+			if (pd->noise_influence == TEX_PD_NOISE_TIME)
+				vec[0] = vec[1] = vec[2] = time;
+			
+			Normalize(vec);
+		}
 		
-		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] + 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);
+		/* now we have an offset coordinate to use for the density lookup */
+		co[0] = texvec[0] + noise_fac * turb;
+		co[1] = texvec[1] + noise_fac * turb;
+		co[2] = texvec[2] + noise_fac * turb;
 	}
-	else
-		BLI_bvhtree_range_query(pd->point_tree, texvec, pd->radius, accum_density, &pdr);
+	
+	BLI_bvhtree_range_query(pd->point_tree, co, pd->radius, accum_density, &pdr);
 
 	texres->tin = density;
-
-	
-	
 	BRICONT;
 	
-	return TEX_INT;
-	
-	/*
 	texres->tr = vec[0];
 	texres->tg = vec[1];
 	texres->tb = vec[2];
+	texres->ta = density;
 	BRICONTRGB;
 	
-	texres->ta = 1.0;
+	return retval;
 	
+	/*
 	if (texres->nor!=NULL) {
 		texres->nor[0] = texres->nor[1] = texres->nor[2] = 0.0f;
 	}
 	*/
-	
-	//BRICONT;
-	
-	//return rv;
 }

Modified: branches/sim_physics/source/blender/render/intern/source/texture.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/texture.c	2008-10-31 04:50:38 UTC (rev 17237)
+++ branches/sim_physics/source/blender/render/intern/source/texture.c	2008-10-31 05:29:54 UTC (rev 17238)
@@ -1565,17 +1565,15 @@
 				/* stencil maps on the texture control slider, not texture intensity value */
 				colfac= mtex->colfac*stencilTin;
 				
-				tcol[0]=texres.tr; tcol[1]=texres.tg; tcol[2]=texres.tb;
-				
 				if((rgbnor & TEX_RGB)==0) {
 					tcol[0]= mtex->r;
 					tcol[1]= mtex->g;
 					tcol[2]= mtex->b;
+				} else {
+					tcol[0]=texres.tr;
+					tcol[1]=texres.tg;
+					tcol[2]=texres.tb;
 				}
-				else if(mtex->mapto & MAP_ALPHA) {
-					texres.tin= stencilTin;
-				}
-				else texres.tin= texres.ta;
 				
 				if((mapto_flag & MAP_COL) && (mtex->mapto & MAP_COL)) {
 					texture_rgb_blend(col, tcol, col, texres.tin, colfac, mtex->blendtype);
@@ -1591,7 +1589,8 @@
 				/* stencil maps on the texture control slider, not texture intensity value */
 				float varfac= mtex->varfac*stencilTin;
 				
-				if(rgbnor & TEX_RGB) {
+				/* convert RGB to intensity if intensity info isn't provided */
+				if((rgbnor & TEX_RGB) && !(rgbnor & TEX_INT)) {
 					if(texres.talpha) texres.tin= texres.ta;
 					else texres.tin= (0.35*texres.tr+0.45*texres.tg+0.2*texres.tb);
 				}

Modified: branches/sim_physics/source/blender/src/buttons_shading.c
===================================================================
--- branches/sim_physics/source/blender/src/buttons_shading.c	2008-10-31 04:50:38 UTC (rev 17237)
+++ branches/sim_physics/source/blender/src/buttons_shading.c	2008-10-31 05:29:54 UTC (rev 17238)
@@ -788,7 +788,7 @@
 			yco -= YSPACE;
 
 			if (pd->source == TEX_PD_PSYS) {
-				uiDefButS(block, MENU, B_REDR, "Noise Influence %t|Static %x0|Velocity %x1",
+				uiDefButS(block, MENU, B_REDR, "Noise Influence %t|Static %x0|Velocity %x1|Time %x2",
 					X2CLM1, yco-=BUTH, BUTW2, BUTH, &(pd->noise_influence), 0.0, 0.0, 0, 0, "Noise Influence");
 			}
 		}





More information about the Bf-blender-cvs mailing list