diff options
author | Miika Hamalainen <blender@miikah.org> | 2012-07-24 22:08:17 +0400 |
---|---|---|
committer | Miika Hamalainen <blender@miikah.org> | 2012-07-24 22:08:17 +0400 |
commit | 61111325f17537dc9c475678e63c11f1057852f0 (patch) | |
tree | 884ff5c90218a07d614648fb8f00bb9a75e154e8 /intern | |
parent | 5e29bd93c0daec60fa0970370528de8bd132fa02 (diff) |
* Active simulation fields are now set dynamically based on simulation content.
- For example fire related data/simulation is only processed when there is a fire type brush affecting the domain. Color data is enabled only when multiple colors are needed.
- This way most simulations require less disk space and are faster to calculate compared to previous branch versions.
* Tweaked smoke 3D-view shader to match previous non-colored version.
* Fixed memory leak with smoke colors.
Diffstat (limited to 'intern')
-rw-r--r-- | intern/smoke/extern/smoke_API.h | 6 | ||||
-rw-r--r-- | intern/smoke/intern/FLUID_3D.cpp | 138 | ||||
-rw-r--r-- | intern/smoke/intern/FLUID_3D.h | 6 | ||||
-rw-r--r-- | intern/smoke/intern/WTURBULENCE.cpp | 84 | ||||
-rw-r--r-- | intern/smoke/intern/WTURBULENCE.h | 5 | ||||
-rw-r--r-- | intern/smoke/intern/smoke_API.cpp | 65 |
6 files changed, 208 insertions, 96 deletions
diff --git a/intern/smoke/extern/smoke_API.h b/intern/smoke/extern/smoke_API.h index 8dead05f2a3..6dac980a353 100644 --- a/intern/smoke/extern/smoke_API.h +++ b/intern/smoke/extern/smoke_API.h @@ -52,6 +52,7 @@ float *smoke_get_color_r(struct FLUID_3D *fluid); float *smoke_get_color_g(struct FLUID_3D *fluid); float *smoke_get_color_b(struct FLUID_3D *fluid); void smoke_get_rgba(struct FLUID_3D *fluid, float *data, int sequential); +void smoke_get_rgba_from_density(struct FLUID_3D *fluid, float color[3], float *data, int sequential); float *smoke_get_heat(struct FLUID_3D *fluid); float *smoke_get_velocity_x(struct FLUID_3D *fluid); float *smoke_get_velocity_y(struct FLUID_3D *fluid); @@ -81,6 +82,7 @@ float *smoke_turbulence_get_color_r(struct WTURBULENCE *wt); float *smoke_turbulence_get_color_g(struct WTURBULENCE *wt); float *smoke_turbulence_get_color_b(struct WTURBULENCE *wt); void smoke_turbulence_get_rgba(struct WTURBULENCE *wt, float *data, int sequential); +void smoke_turbulence_get_rgba_from_density(struct WTURBULENCE *wt, float color[3], float *data, int sequential); float *smoke_turbulence_get_flame(struct WTURBULENCE *wt); float *smoke_turbulence_get_fuel(struct WTURBULENCE *wt); void smoke_turbulence_get_res(struct WTURBULENCE *wt, int *res); @@ -105,6 +107,10 @@ int smoke_has_colors(struct FLUID_3D *fluid); int smoke_turbulence_has_fuel(struct WTURBULENCE *wt); int smoke_turbulence_has_colors(struct WTURBULENCE *wt); +void smoke_ensure_heat(struct FLUID_3D *fluid); +void smoke_ensure_fire(struct FLUID_3D *fluid, struct WTURBULENCE *wt); +void smoke_ensure_colors(struct FLUID_3D *fluid, struct WTURBULENCE *wt, float init_r, float init_g, float init_b); + #ifdef __cplusplus } #endif diff --git a/intern/smoke/intern/FLUID_3D.cpp b/intern/smoke/intern/FLUID_3D.cpp index 3496d699f16..3e56f6a36e5 100644 --- a/intern/smoke/intern/FLUID_3D.cpp +++ b/intern/smoke/intern/FLUID_3D.cpp @@ -44,7 +44,7 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// -FLUID_3D::FLUID_3D(int *res, float dx, float dtdef, int use_heat, int use_fire, int use_colors) : +FLUID_3D::FLUID_3D(int *res, float dx, float dtdef, int init_heat, int init_fire, int init_colors) : _xRes(res[0]), _yRes(res[1]), _zRes(res[2]), _res(0.0f) { // set simulation consts @@ -92,14 +92,6 @@ FLUID_3D::FLUID_3D(int *res, float dx, float dtdef, int use_heat, int use_fire, _zForce = new float[_totalCells]; _density = new float[_totalCells]; _densityOld = new float[_totalCells]; - if (use_heat) { - _heat = new float[_totalCells]; - _heatOld = new float[_totalCells]; - _heatTemp = new float[_totalCells]; - } - else { - _heat = _heatOld = _heatTemp = NULL; - } _obstacles = new unsigned char[_totalCells]; // set 0 at end of step // For threaded version: @@ -108,35 +100,6 @@ FLUID_3D::FLUID_3D(int *res, float dx, float dtdef, int use_heat, int use_fire, _zVelocityTemp = new float[_totalCells]; _densityTemp = new float[_totalCells]; - // Fire simulation - if (use_fire) { - _flame = new float[_totalCells]; - _fuel = new float[_totalCells]; - _fuelTemp = new float[_totalCells]; - _fuelOld = new float[_totalCells]; - } - else { - _flame = _fuel = _fuelTemp = _fuelOld = NULL; - } - - // Smoke color - if (use_colors) { - _color_r = new float[_totalCells]; - _color_rOld = new float[_totalCells]; - _color_rTemp = new float[_totalCells]; - _color_g = new float[_totalCells]; - _color_gOld = new float[_totalCells]; - _color_gTemp = new float[_totalCells]; - _color_b = new float[_totalCells]; - _color_bOld = new float[_totalCells]; - _color_bTemp = new float[_totalCells]; - } - else { - _color_r = _color_rOld = _color_rTemp = NULL; - _color_g = _color_gOld = _color_gTemp = NULL; - _color_b = _color_bOld = _color_bTemp = NULL; - } - // DG TODO: check if alloc went fine for (int x = 0; x < _totalCells; x++) @@ -156,27 +119,24 @@ FLUID_3D::FLUID_3D(int *res, float dx, float dtdef, int use_heat, int use_fire, _yForce[x] = 0.0f; _zForce[x] = 0.0f; _obstacles[x] = false; + } - if (_heat) { - _heat[x] = 0.0f; - _heatOld[x] = 0.0f; - } - - if (_flame) { - _flame[x] = 0.0f; - _fuel[x] = 0.0f; - _fuelTemp[x] = 0.0f; - _fuelOld[x] = 0.0f; - } - - if (_color_r) { - _color_r[x] = 0.0f; - _color_rOld[x] = 0.0f; - _color_g[x] = 0.0f; - _color_gOld[x] = 0.0f; - _color_b[x] = 0.0f; - _color_bOld[x] = 0.0f; - } + /* heat */ + _heat = _heatOld = _heatTemp = NULL; + if (init_heat) { + initHeat(); + } + // Fire simulation + _flame = _fuel = _fuelTemp = _fuelOld = NULL; + if (init_fire) { + initFire(); + } + // Smoke color + _color_r = _color_rOld = _color_rTemp = NULL; + _color_g = _color_gOld = _color_gTemp = NULL; + _color_b = _color_bOld = _color_bTemp = NULL; + if (init_colors) { + initColors(0.0f, 0.0f, 0.0f); } // boundary conditions of the fluid domain @@ -194,6 +154,64 @@ FLUID_3D::FLUID_3D(int *res, float dx, float dtdef, int use_heat, int use_fire, } +void FLUID_3D::initHeat() +{ + if (!_heat) { + _heat = new float[_totalCells]; + _heatOld = new float[_totalCells]; + _heatTemp = new float[_totalCells]; + + for (int x = 0; x < _totalCells; x++) + { + _heat[x] = 0.0f; + _heatOld[x] = 0.0f; + } + } +} + +void FLUID_3D::initFire() +{ + if (!_flame) { + _flame = new float[_totalCells]; + _fuel = new float[_totalCells]; + _fuelTemp = new float[_totalCells]; + _fuelOld = new float[_totalCells]; + + for (int x = 0; x < _totalCells; x++) + { + _flame[x] = 0.0f; + _fuel[x] = 0.0f; + _fuelTemp[x] = 0.0f; + _fuelOld[x] = 0.0f; + } + } +} + +void FLUID_3D::initColors(float init_r, float init_g, float init_b) +{ + if (!_color_r) { + _color_r = new float[_totalCells]; + _color_rOld = new float[_totalCells]; + _color_rTemp = new float[_totalCells]; + _color_g = new float[_totalCells]; + _color_gOld = new float[_totalCells]; + _color_gTemp = new float[_totalCells]; + _color_b = new float[_totalCells]; + _color_bOld = new float[_totalCells]; + _color_bTemp = new float[_totalCells]; + + for (int x = 0; x < _totalCells; x++) + { + _color_r[x] = _density[x] * init_r; + _color_rOld[x] = 0.0f; + _color_g[x] = _density[x] * init_g; + _color_gOld[x] = 0.0f; + _color_b[x] = _density[x] * init_b; + _color_bOld[x] = 0.0f; + } + } +} + void FLUID_3D::setBorderObstacles() { @@ -255,7 +273,6 @@ FLUID_3D::~FLUID_3D() if (_heat) delete[] _heat; if (_heatOld) delete[] _heatOld; if (_obstacles) delete[] _obstacles; - // if (_wTurbulence) delete _wTurbulence; if (_xVelocityTemp) delete[] _xVelocityTemp; if (_yVelocityTemp) delete[] _yVelocityTemp; @@ -270,10 +287,13 @@ FLUID_3D::~FLUID_3D() if (_color_r) delete[] _color_r; if (_color_rOld) delete[] _color_rOld; + if (_color_rTemp) delete[] _color_rTemp; if (_color_g) delete[] _color_g; if (_color_gOld) delete[] _color_gOld; + if (_color_gTemp) delete[] _color_gTemp; if (_color_b) delete[] _color_b; if (_color_bOld) delete[] _color_bOld; + if (_color_bTemp) delete[] _color_bTemp; // printf("deleted fluid\n"); } diff --git a/intern/smoke/intern/FLUID_3D.h b/intern/smoke/intern/FLUID_3D.h index dab0fb89e16..134cec078cb 100644 --- a/intern/smoke/intern/FLUID_3D.h +++ b/intern/smoke/intern/FLUID_3D.h @@ -46,10 +46,14 @@ class WTURBULENCE; class FLUID_3D { public: - FLUID_3D(int *res, float dx, float dtdef, int use_heat, int use_fire, int use_colors); + FLUID_3D(int *res, float dx, float dtdef, int init_heat, int init_fire, int init_colors); FLUID_3D() {}; virtual ~FLUID_3D(); + void initHeat(); + void initFire(); + void initColors(float init_r, float init_g, float init_b); + void initBlenderRNA(float *alpha, float *beta, float *dt_factor, float *vorticity, int *border_colli, float *burning_rate, float *flame_smoke, float *flame_smoke_color, float *flame_vorticity, float *ignition_temp, float *max_temp); diff --git a/intern/smoke/intern/WTURBULENCE.cpp b/intern/smoke/intern/WTURBULENCE.cpp index 4571fcc8e9f..995ba663c5b 100644 --- a/intern/smoke/intern/WTURBULENCE.cpp +++ b/intern/smoke/intern/WTURBULENCE.cpp @@ -51,7 +51,7 @@ static const float persistence = 0.56123f; ////////////////////////////////////////////////////////////////////// // constructor ////////////////////////////////////////////////////////////////////// -WTURBULENCE::WTURBULENCE(int xResSm, int yResSm, int zResSm, int amplify, int noisetype, int use_fire, int use_colors) +WTURBULENCE::WTURBULENCE(int xResSm, int yResSm, int zResSm, int amplify, int noisetype, int init_fire, int init_colors) { // if noise magnitude is below this threshold, its contribution // is negilgible, so stop evaluating new octaves @@ -88,45 +88,23 @@ WTURBULENCE::WTURBULENCE(int xResSm, int yResSm, int zResSm, int amplify, int no _totalStepsBig = 0; _densityBig = new float[_totalCellsBig]; _densityBigOld = new float[_totalCellsBig]; - if (use_fire) { - _flameBig = new float[_totalCellsBig]; - _fuelBig = new float[_totalCellsBig]; - _fuelBigOld = new float[_totalCellsBig]; - } - else { - _flameBig = _fuelBig = _fuelBigOld = NULL; - } - if (use_colors) { - _color_rBig = new float[_totalCellsBig]; - _color_rBigOld = new float[_totalCellsBig]; - _color_gBig = new float[_totalCellsBig]; - _color_gBigOld = new float[_totalCellsBig]; - _color_bBig = new float[_totalCellsBig]; - _color_bBigOld = new float[_totalCellsBig]; - } - else { - _color_rBig = _color_rBigOld = NULL; - _color_gBig = _color_gBigOld = NULL; - _color_bBig = _color_bBigOld = NULL; - } for(int i = 0; i < _totalCellsBig; i++) { _densityBig[i] = _densityBigOld[i] = 0.; + } - if (_fuelBig) { - _flameBig[i] = - _fuelBig[i] = - _fuelBigOld[i] = 0.; - } - if (_color_rBig) { - _color_rBig[i] = - _color_rBigOld[i] = - _color_gBig[i] = - _color_gBigOld[i] = - _color_bBig[i] = - _color_bBigOld[i] = 0.; - } + /* fire */ + _flameBig = _fuelBig = _fuelBigOld = NULL; + if (init_fire) { + initFire(); + } + /* colors */ + _color_rBig = _color_rBigOld = NULL; + _color_gBig = _color_gBigOld = NULL; + _color_bBig = _color_bBigOld = NULL; + if (init_colors) { + initColors(0.0f, 0.0f, 0.0f); } // allocate & init texture coordinates @@ -163,6 +141,42 @@ WTURBULENCE::WTURBULENCE(int xResSm, int yResSm, int zResSm, int amplify, int no */ } +void WTURBULENCE::initFire() +{ + if (!_fuelBig) { + _flameBig = new float[_totalCellsBig]; + _fuelBig = new float[_totalCellsBig]; + _fuelBigOld = new float[_totalCellsBig]; + + for(int i = 0; i < _totalCellsBig; i++) { + _flameBig[i] = + _fuelBig[i] = + _fuelBigOld[i] = 0.; + } + } +} + +void WTURBULENCE::initColors(float init_r, float init_g, float init_b) +{ + if (!_color_rBig) { + _color_rBig = new float[_totalCellsBig]; + _color_rBigOld = new float[_totalCellsBig]; + _color_gBig = new float[_totalCellsBig]; + _color_gBigOld = new float[_totalCellsBig]; + _color_bBig = new float[_totalCellsBig]; + _color_bBigOld = new float[_totalCellsBig]; + + for(int i = 0; i < _totalCellsBig; i++) { + _color_rBig[i] = _densityBig[i] * init_r; + _color_rBigOld[i] = 0.0f; + _color_gBig[i] = _densityBig[i] * init_g; + _color_gBigOld[i] = 0.0f; + _color_bBig[i] = _densityBig[i] * init_b; + _color_bBigOld[i] = 0.0f; + } + } +} + ////////////////////////////////////////////////////////////////////// // destructor ////////////////////////////////////////////////////////////////////// diff --git a/intern/smoke/intern/WTURBULENCE.h b/intern/smoke/intern/WTURBULENCE.h index 705a06975a9..cb7b67d6f57 100644 --- a/intern/smoke/intern/WTURBULENCE.h +++ b/intern/smoke/intern/WTURBULENCE.h @@ -36,10 +36,13 @@ class WTURBULENCE { public: // both config files can be NULL, altCfg might override values from noiseCfg - WTURBULENCE(int xResSm, int yResSm, int zResSm, int amplify, int noisetype, int use_fire, int use_colors); + WTURBULENCE(int xResSm, int yResSm, int zResSm, int amplify, int noisetype, int init_fire, int init_colors); /// destructor virtual ~WTURBULENCE(); + + void initFire(); + void initColors(float init_r, float init_g, float init_b); void setNoise(int type); void initBlenderRNA(float *strength); diff --git a/intern/smoke/intern/smoke_API.cpp b/intern/smoke/intern/smoke_API.cpp index a97b361eee1..dffd59f88c2 100644 --- a/intern/smoke/intern/smoke_API.cpp +++ b/intern/smoke/intern/smoke_API.cpp @@ -305,6 +305,43 @@ extern "C" void smoke_turbulence_get_rgba(WTURBULENCE *wt, float *data, int sequ get_rgba(wt->_color_rBig, wt->_color_gBig, wt->_color_bBig, wt->_densityBig, wt->_totalCellsBig, data, sequential); } +/* get a single color premultiplied voxel grid */ +static void get_rgba_from_density(float color[3], float *a, int total_cells, float *data, int sequential) +{ + int i; + int m = 4, i_g = 1, i_b = 2, i_a = 3; + /* sequential data */ + if (sequential) { + m = 1; + i_g *= total_cells; + i_b *= total_cells; + i_a *= total_cells; + } + + for (i=0; i<total_cells; i++) { + float alpha = a[i]; + if (alpha) { + data[i*m ] = color[0] * alpha; + data[i*m+i_g] = color[1] * alpha; + data[i*m+i_b] = color[2] * alpha; + } + else { + data[i*m ] = data[i*m+i_g] = data[i*m+i_b] = 0.0f; + } + data[i*m+i_a] = alpha; + } +} + +extern "C" void smoke_get_rgba_from_density(FLUID_3D *fluid, float color[3], float *data, int sequential) +{ + get_rgba_from_density(color, fluid->_density, fluid->_totalCells, data, sequential); +} + +extern "C" void smoke_turbulence_get_rgba_from_density(WTURBULENCE *wt, float color[3], float *data, int sequential) +{ + get_rgba_from_density(color, wt->_densityBig, wt->_totalCellsBig, data, sequential); +} + extern "C" float *smoke_turbulence_get_density(WTURBULENCE *wt) { return wt ? wt->getDensityBig() : NULL; @@ -404,4 +441,32 @@ extern "C" int smoke_turbulence_has_fuel(WTURBULENCE *wt) extern "C" int smoke_turbulence_has_colors(WTURBULENCE *wt) { return (wt->_color_rBig && wt->_color_gBig && wt->_color_bBig) ? 1 : 0; +} + +/* additional field initialization */ +extern "C" void smoke_ensure_heat(FLUID_3D *fluid) +{ + if (fluid) { + fluid->initHeat(); + } +} + +extern "C" void smoke_ensure_fire(FLUID_3D *fluid, WTURBULENCE *wt) +{ + if (fluid) { + fluid->initFire(); + } + if (wt) { + wt->initFire(); + } +} + +extern "C" void smoke_ensure_colors(FLUID_3D *fluid, WTURBULENCE *wt, float init_r, float init_g, float init_b) +{ + if (fluid) { + fluid->initColors(init_r, init_g, init_b); + } + if (wt) { + wt->initColors(init_r, init_g, init_b); + } }
\ No newline at end of file |