Fix T43515: Initial velocity for fire bug
authorMiika Hamalainen <blender@miikah.org>
Fri, 6 Feb 2015 20:05:09 +0000 (22:05 +0200)
committerMiika Hamalainen <blender@miikah.org>
Fri, 6 Feb 2015 20:05:09 +0000 (22:05 +0200)
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.

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

index a43d94a..4faec89 100644 (file)
@@ -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
index d98a399..cd2147b 100644 (file)
@@ -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);
index e25dff0..d79aaf7 100644 (file)
@@ -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,