[Bf-blender-cvs] [ca06c33] master: Fix T43515: Initial velocity for fire bug

Miika Hamalainen noreply at git.blender.org
Fri Feb 6 21:05:19 CET 2015


Commit: ca06c3343e4c295029a74ffdbafbed1b8a7911ec
Author: Miika Hamalainen
Date:   Fri Feb 6 22:05:09 2015 +0200
Branches: master
https://developer.blender.org/rBca06c3343e4c295029a74ffdbafbed1b8a7911ec

Fix T43515: Initial velocity for fire bug

Visual representation of fire was generated before simulation step took place. This caused fire to essentially lag one simulation step behind, even though all emission areas were up to date.

===================================================================

M	intern/smoke/intern/FLUID_3D.cpp
M	intern/smoke/intern/FLUID_3D.h
M	intern/smoke/intern/smoke_API.cpp

===================================================================

diff --git a/intern/smoke/intern/FLUID_3D.cpp b/intern/smoke/intern/FLUID_3D.cpp
index a43d94a..4faec89 100644
--- a/intern/smoke/intern/FLUID_3D.cpp
+++ b/intern/smoke/intern/FLUID_3D.cpp
@@ -1587,7 +1587,7 @@ void FLUID_3D::advectMacCormackEnd2(int zBegin, int zEnd)
 }
 
 
-void FLUID_3D::processBurn(float *fuel, float *smoke, float *react, float *flame, float *heat,
+void FLUID_3D::processBurn(float *fuel, float *smoke, float *react, float *heat,
 						   float *r, float *g, float *b, int total_cells, float dt)
 {
 	float burning_rate = *_burning_rate;
@@ -1600,7 +1600,7 @@ void FLUID_3D::processBurn(float *fuel, float *smoke, float *react, float *flame
 		float orig_fuel = fuel[index];
 		float orig_smoke = smoke[index];
 		float smoke_emit = 0.0f;
-		float react_coord = 0.0f;
+		float flame = 0.0f;
 
 		/* process fuel */
 		fuel[index] -= burning_rate * dt;
@@ -1608,7 +1608,7 @@ void FLUID_3D::processBurn(float *fuel, float *smoke, float *react, float *flame
 		/* process reaction coordinate */
 		if (orig_fuel > FLT_EPSILON) {
 			react[index] *= fuel[index]/orig_fuel;
-			react_coord = react[index];
+			flame = pow(react[index], 0.5f);
 		}
 		else {
 			react[index] = 0.0f;
@@ -1620,17 +1620,9 @@ void FLUID_3D::processBurn(float *fuel, float *smoke, float *react, float *flame
 		smoke[index] += smoke_emit;
 		CLAMP(smoke[index], 0.0f, 1.0f);
 
-		/* model flame temperature curve from the reaction coordinate (fuel) */
-		if (react_coord>0.0f) {
-			/* do a smooth falloff for rest of the values */
-			flame[index] = pow(react_coord, 0.5f);
-		}
-		else
-			flame[index] = 0.0f;
-
 		/* set fluid temperature from the flame temperature profile */
-		if (heat && flame[index])
-			heat[index] = (1.0f-flame[index])*ignition_point + flame[index]*temp_max;
+		if (heat && flame)
+			heat[index] = (1.0f - flame)*ignition_point + flame*temp_max;
 
 		/* mix new color */
 		if (r && smoke_emit > FLT_EPSILON) {
@@ -1641,3 +1633,21 @@ void FLUID_3D::processBurn(float *fuel, float *smoke, float *react, float *flame
 		}
 	}
 }
+
+void FLUID_3D::updateFlame(float *react, float *flame, int total_cells)
+{
+	for (int index = 0; index < total_cells; index++)
+	{
+		/* model flame temperature curve from the reaction coordinate (fuel)
+		 *	TODO: Would probably be best to get rid of whole "flame" data field.
+		 *		 Currently it's just sqrt mirror of reaction coordinate, and therefore
+		 *		 basically just waste of memory and disk space...
+		 */
+		if (react[index]>0.0f) {
+			/* do a smooth falloff for rest of the values */
+			flame[index] = pow(react[index], 0.5f);
+		}
+		else
+			flame[index] = 0.0f;
+	}
+}
\ No newline at end of file
diff --git a/intern/smoke/intern/FLUID_3D.h b/intern/smoke/intern/FLUID_3D.h
index d98a399..cd2147b 100644
--- a/intern/smoke/intern/FLUID_3D.h
+++ b/intern/smoke/intern/FLUID_3D.h
@@ -209,8 +209,9 @@ struct FLUID_3D
 		float *_flame_vorticity; // RNA pointer
 		float *_ignition_temp; // RNA pointer
 		float *_max_temp; // RNA pointer
-		void processBurn(float *fuel, float *smoke, float *react, float *flame, float *heat,
+		void processBurn(float *fuel, float *smoke, float *react, float *heat,
 						 float *r, float *g, float *b, int total_cells, float dt);
+		void updateFlame(float *react, float *flame, int total_cells);
 
 		// boundary setting functions
 		static void copyBorderX(float* field, Vec3Int res, int zBegin, int zEnd);
diff --git a/intern/smoke/intern/smoke_API.cpp b/intern/smoke/intern/smoke_API.cpp
index e25dff0..d79aaf7 100644
--- a/intern/smoke/intern/smoke_API.cpp
+++ b/intern/smoke/intern/smoke_API.cpp
@@ -77,19 +77,27 @@ extern "C" size_t smoke_get_index2d(int x, int max_x, int y /*, int max_y, int z
 extern "C" void smoke_step(FLUID_3D *fluid, float gravity[3], float dtSubdiv)
 {
 	if (fluid->_fuel) {
-		fluid->processBurn(fluid->_fuel, fluid->_density, fluid->_react, fluid->_flame, fluid->_heat,
+		fluid->processBurn(fluid->_fuel, fluid->_density, fluid->_react, fluid->_heat,
 						   fluid->_color_r, fluid->_color_g, fluid->_color_b, fluid->_totalCells, (*fluid->_dtFactor)*dtSubdiv);
 	}
 	fluid->step(dtSubdiv, gravity);
+
+	if (fluid->_fuel) {
+		fluid->updateFlame(fluid->_react, fluid->_flame, fluid->_totalCells);
+	}
 }
 
 extern "C" void smoke_turbulence_step(WTURBULENCE *wt, FLUID_3D *fluid)
 {
 	if (wt->_fuelBig) {
-		fluid->processBurn(wt->_fuelBig, wt->_densityBig, wt->_reactBig, wt->_flameBig, 0,
+		fluid->processBurn(wt->_fuelBig, wt->_densityBig, wt->_reactBig, 0,
 						   wt->_color_rBig, wt->_color_gBig, wt->_color_bBig, wt->_totalCellsBig, fluid->_dt);
 	}
-	wt->stepTurbulenceFull(fluid->_dt/fluid->_dx, fluid->_xVelocity, fluid->_yVelocity, fluid->_zVelocity, fluid->_obstacles); 
+	wt->stepTurbulenceFull(fluid->_dt/fluid->_dx, fluid->_xVelocity, fluid->_yVelocity, fluid->_zVelocity, fluid->_obstacles);
+
+	if (wt->_fuelBig) {
+		fluid->updateFlame(wt->_reactBig, wt->_flameBig, wt->_totalCellsBig);
+	}
 }
 
 extern "C" void smoke_initBlenderRNA(FLUID_3D *fluid, float *alpha, float *beta, float *dt_factor, float *vorticity, int *border_colli, float *burning_rate,




More information about the Bf-blender-cvs mailing list