[319] | 1 | // Copyright (C) 2014 ChaosForge Ltd
|
---|
| 2 | // This file is part of NV Libraries.
|
---|
| 3 | // For conditions of distribution and use, see copyright notice in nv.hh
|
---|
| 4 |
|
---|
[320] | 5 | #include "nv/engine/particle_engine.hh"
|
---|
[306] | 6 |
|
---|
| 7 | #include <nv/interface/device.hh>
|
---|
[319] | 8 | #include <nv/core/random.hh>
|
---|
[306] | 9 | #include <nv/lua/lua_glm.hh>
|
---|
[319] | 10 | #include <nv/core/logging.hh>
|
---|
[309] | 11 | #include <cmath>
|
---|
[306] | 12 |
|
---|
| 13 | static const char *nv_particle_engine_vertex_shader_world =
|
---|
| 14 | "#version 120\n"
|
---|
| 15 | "attribute vec3 nv_position;\n"
|
---|
| 16 | "attribute vec2 nv_texcoord;\n"
|
---|
| 17 | "attribute vec4 nv_color;\n"
|
---|
| 18 | "varying vec4 v_color;\n"
|
---|
| 19 | "varying vec2 v_texcoord;\n"
|
---|
| 20 | "uniform mat4 nv_m_view;\n"
|
---|
| 21 | "uniform mat4 nv_m_projection;\n"
|
---|
| 22 | "void main(void)\n"
|
---|
| 23 | "{\n"
|
---|
| 24 | " gl_Position = nv_m_projection * nv_m_view * vec4 (nv_position, 1.0);\n"
|
---|
| 25 | " v_texcoord = nv_texcoord;\n"
|
---|
| 26 | " v_color = nv_color;\n"
|
---|
| 27 | "}\n";
|
---|
| 28 | static const char *nv_particle_engine_vertex_shader_local =
|
---|
| 29 | "#version 120\n"
|
---|
| 30 | "attribute vec3 nv_position;\n"
|
---|
| 31 | "attribute vec2 nv_texcoord;\n"
|
---|
| 32 | "attribute vec4 nv_color;\n"
|
---|
| 33 | "varying vec4 v_color;\n"
|
---|
| 34 | "varying vec2 v_texcoord;\n"
|
---|
| 35 | "uniform mat4 nv_m_mvp;\n"
|
---|
| 36 | "void main(void)\n"
|
---|
| 37 | "{\n"
|
---|
| 38 | " gl_Position = nv_m_mvp * vec4 (nv_position, 1.0);\n"
|
---|
| 39 | " v_texcoord = nv_texcoord;\n"
|
---|
| 40 | " v_color = nv_color;\n"
|
---|
| 41 | "}\n";
|
---|
| 42 | static const char *nv_particle_engine_fragment_shader =
|
---|
| 43 | "#version 120\n"
|
---|
| 44 | "uniform sampler2D nv_t_diffuse;\n"
|
---|
| 45 | "varying vec4 v_color;\n"
|
---|
| 46 | "varying vec2 v_texcoord;\n"
|
---|
| 47 | "void main(void)\n"
|
---|
| 48 | "{\n"
|
---|
| 49 | " vec4 tex_color = texture2D( nv_t_diffuse, v_texcoord );\n"
|
---|
| 50 | " gl_FragColor = v_color * tex_color;\n"
|
---|
| 51 | "}\n";
|
---|
| 52 |
|
---|
[312] | 53 | using namespace nv;
|
---|
| 54 |
|
---|
| 55 | static void nv_particle_emmiter_point( const particle_emmiter_data*, particle* p, uint32 count )
|
---|
| 56 | {
|
---|
| 57 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 58 | {
|
---|
| 59 | p[i].position = vec3();
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | static void nv_particle_emmiter_box( const particle_emmiter_data* pe, particle* p, uint32 count )
|
---|
| 65 | {
|
---|
| 66 | random& r = random::get();
|
---|
| 67 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 68 | {
|
---|
| 69 | p[i].position =
|
---|
| 70 | r.frange( -pe->hextents[0], pe->hextents[0] ) * pe->cdir +
|
---|
| 71 | r.frange( 0.0f, pe->extents[1] ) * pe->dir +
|
---|
| 72 | r.frange( -pe->hextents[2], pe->hextents[2] ) * pe->odir;
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | static void nv_particle_emmiter_cylinder( const particle_emmiter_data* pe, particle* p, uint32 count )
|
---|
| 77 | {
|
---|
| 78 | random& r = random::get();
|
---|
| 79 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 80 | {
|
---|
| 81 | vec2 rellipse( r.disk_point( pe->precise ) * pe->extents[0] );
|
---|
| 82 | p[i].position =
|
---|
| 83 | rellipse.x * pe->cdir +
|
---|
| 84 | r.frange( 0.0f, pe->extents[1] ) * pe->dir +
|
---|
| 85 | rellipse.y * pe->odir;
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | static void nv_particle_emmiter_sphere( const particle_emmiter_data* pe, particle* p, uint32 count )
|
---|
| 90 | {
|
---|
| 91 | random& r = random::get();
|
---|
| 92 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 93 | {
|
---|
| 94 | vec3 rsphere = r.sphere_point( pe->precise ) * pe->extents[0];
|
---|
| 95 | p[i].position =
|
---|
| 96 | rsphere.x * pe->cdir +
|
---|
| 97 | rsphere.y * pe->dir +
|
---|
| 98 | rsphere.z * pe->odir;
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | static void nv_particle_emmiter_cylindroid( const particle_emmiter_data* pe, particle* p, uint32 count )
|
---|
| 103 | {
|
---|
| 104 | random& r = random::get();
|
---|
| 105 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 106 | {
|
---|
| 107 | vec2 rellipse = r.ellipse_point( vec2( pe->hextents[0], pe->hextents[2] ), pe->precise );
|
---|
| 108 | p[i].position =
|
---|
| 109 | rellipse.x * pe->cdir +
|
---|
| 110 | r.frange( 0.0f, pe->extents[1] ) * pe->dir +
|
---|
| 111 | rellipse.y * pe->odir;
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | static void nv_particle_emmiter_ellipsoid( const particle_emmiter_data* pe, particle* p, uint32 count )
|
---|
| 116 | {
|
---|
| 117 | random& r = random::get();
|
---|
| 118 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 119 | {
|
---|
| 120 | vec3 rsphere = r.ellipsoid_point( pe->hextents, pe->precise );
|
---|
| 121 | p[i].position =
|
---|
| 122 | rsphere.x * pe->cdir +
|
---|
| 123 | rsphere.y * pe->dir +
|
---|
| 124 | rsphere.z * pe->odir;
|
---|
| 125 | }
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | static void nv_particle_emmiter_hollow_cylinder( const particle_emmiter_data* pe, particle* p, uint32 count )
|
---|
| 129 | {
|
---|
| 130 | random& r = random::get();
|
---|
| 131 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 132 | {
|
---|
| 133 | vec2 rellipse = r.hollow_disk_point(
|
---|
| 134 | pe->ihextents[0],
|
---|
| 135 | pe->hextents[0],
|
---|
| 136 | pe->precise );
|
---|
| 137 | p[i].position =
|
---|
| 138 | rellipse.x * pe->cdir +
|
---|
| 139 | r.frange( 0.0f, pe->extents[1] ) * pe->dir +
|
---|
| 140 | rellipse.y * pe->odir;
|
---|
| 141 | }
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | static void nv_particle_emmiter_hollow_sphere( const particle_emmiter_data* pe, particle* p, uint32 count )
|
---|
| 145 | {
|
---|
| 146 | random& r = random::get();
|
---|
| 147 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 148 | {
|
---|
| 149 | vec3 rellipse = r.hollow_sphere_point( pe->ihextents[0], pe->hextents[0], pe->precise );
|
---|
| 150 | p[i].position =
|
---|
| 151 | rellipse.x * pe->cdir +
|
---|
| 152 | rellipse.y * pe->dir +
|
---|
| 153 | rellipse.z * pe->odir;
|
---|
| 154 | }
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | static void nv_particle_emmiter_hollow_cylindroid( const particle_emmiter_data* pe, particle* p, uint32 count )
|
---|
| 158 | {
|
---|
| 159 | random& r = random::get();
|
---|
| 160 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 161 | {
|
---|
| 162 | vec2 rellipse = r.hollow_ellipse_point(
|
---|
| 163 | vec2( pe->ihextents[0], pe->ihextents[2] ),
|
---|
| 164 | vec2( pe->hextents[0], pe->hextents[2] ),
|
---|
| 165 | pe->precise );
|
---|
| 166 | p[i].position =
|
---|
| 167 | rellipse.x * pe->cdir +
|
---|
| 168 | r.frange( 0.0f, pe->extents[1] ) * pe->dir +
|
---|
| 169 | rellipse.y * pe->odir;
|
---|
| 170 | }
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | static void nv_particle_emmiter_hollow_ellipsoid( const particle_emmiter_data* pe, particle* p, uint32 count )
|
---|
| 174 | {
|
---|
| 175 | random& r = random::get();
|
---|
| 176 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 177 | {
|
---|
| 178 | vec3 rellipse = r.hollow_ellipsoid_point( pe->ihextents, pe->hextents, pe->precise );
|
---|
| 179 | p[i].position =
|
---|
| 180 | rellipse.x * pe->cdir +
|
---|
| 181 | rellipse.y * pe->dir +
|
---|
| 182 | rellipse.z * pe->odir;
|
---|
| 183 | }
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | struct nvpe_linear_force_data
|
---|
| 187 | {
|
---|
| 188 | nv::vec3 force_vector;
|
---|
| 189 | bool average;
|
---|
| 190 | };
|
---|
| 191 |
|
---|
| 192 | static bool nv_particle_affector_linear_force_init( lua::table_guard* table, particle_affector_data* data )
|
---|
| 193 | {
|
---|
| 194 | nvpe_linear_force_data* datap = ((nvpe_linear_force_data*)data->paramters);
|
---|
| 195 | datap->force_vector = table->get<vec3>("force_vector", vec3() );
|
---|
| 196 | datap->average = table->get<bool>("average", false );
|
---|
| 197 | return true;
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | static void nv_particle_affector_linear_force( const particle_affector_data* data, particle* p, float factor, uint32 count )
|
---|
| 201 | {
|
---|
| 202 | nvpe_linear_force_data* datap = ((nvpe_linear_force_data*)data->paramters);
|
---|
| 203 | if ( datap->average )
|
---|
| 204 | {
|
---|
| 205 | float norm_factor = glm::min( factor, 1.0f );
|
---|
| 206 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 207 | p[i].velocity = datap->force_vector * norm_factor + p[i].velocity * ( 1.0f - norm_factor );
|
---|
| 208 | }
|
---|
| 209 | else
|
---|
| 210 | {
|
---|
| 211 | vec3 scvector = datap->force_vector * factor;
|
---|
| 212 | for ( uint32 i = 0; i < count; ++i ) p[i].velocity += scvector;
|
---|
| 213 | }
|
---|
| 214 | }
|
---|
| 215 |
|
---|
| 216 | struct nvpe_deflector_plane_data
|
---|
| 217 | {
|
---|
| 218 | nv::vec3 plane_point;
|
---|
| 219 | nv::vec3 plane_normal;
|
---|
| 220 | float bounce;
|
---|
| 221 | float distance;
|
---|
| 222 | };
|
---|
| 223 |
|
---|
| 224 | static bool nv_particle_affector_deflector_plane_init( lua::table_guard* table, particle_affector_data* data )
|
---|
| 225 | {
|
---|
| 226 | nvpe_deflector_plane_data* datap = ((nvpe_deflector_plane_data*)data->paramters);
|
---|
| 227 | datap->plane_point = table->get<vec3>("plane_point", vec3() );
|
---|
| 228 | datap->plane_normal = table->get<vec3>("plane_normal", vec3(0.0f,1.0f,0.0f) );
|
---|
| 229 | datap->plane_normal = normalize_safe( datap->plane_normal, vec3(0.0f,1.0f,0.0f) );
|
---|
| 230 | datap->bounce = table->get<float>("bounce", 0.0f );
|
---|
| 231 | datap->distance = -glm::dot( datap->plane_normal, datap->plane_point ) / glm::sqrt(glm::dot( datap->plane_normal, datap->plane_normal ) );
|
---|
| 232 | return true;
|
---|
| 233 | }
|
---|
| 234 |
|
---|
| 235 | static void nv_particle_affector_deflector_plane( const particle_affector_data* data, particle* p, float factor, uint32 count )
|
---|
| 236 | {
|
---|
| 237 | nvpe_deflector_plane_data* datap = ((nvpe_deflector_plane_data*)data->paramters);
|
---|
| 238 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 239 | {
|
---|
| 240 | particle& pt = p[i];
|
---|
| 241 | vec3 direction = pt.velocity * factor;
|
---|
| 242 | if ( glm::dot( datap->plane_normal, pt.position + direction ) + datap->distance <= 0.0f )
|
---|
| 243 | {
|
---|
| 244 | float val = glm::dot( datap->plane_normal, pt.position ) + datap->distance;
|
---|
| 245 | if ( val > 0.0f )
|
---|
| 246 | {
|
---|
| 247 | vec3 part_dir = direction * ( -val / glm::dot( datap->plane_normal, direction ) );
|
---|
| 248 | pt.position = pt.position + part_dir + ( part_dir - direction ) * datap->bounce;
|
---|
| 249 | pt.velocity = glm::reflect( pt.velocity, datap->plane_normal ) * datap->bounce;
|
---|
| 250 | }
|
---|
| 251 | }
|
---|
| 252 | }
|
---|
| 253 | }
|
---|
| 254 |
|
---|
| 255 | struct nvpe_color_fader_data
|
---|
| 256 | {
|
---|
| 257 | nv::vec4 adjustment;
|
---|
| 258 | };
|
---|
| 259 |
|
---|
| 260 | static bool nv_particle_affector_color_fader_init( lua::table_guard* table, particle_affector_data* data )
|
---|
| 261 | {
|
---|
| 262 | nvpe_color_fader_data* datap = ((nvpe_color_fader_data*)data->paramters);
|
---|
| 263 | datap->adjustment = table->get<vec4>("adjustment", vec4() );
|
---|
| 264 | return true;
|
---|
| 265 | }
|
---|
| 266 |
|
---|
| 267 | static void nv_particle_affector_color_fader( const particle_affector_data* data, particle* p, float factor, uint32 count )
|
---|
| 268 | {
|
---|
| 269 | nvpe_color_fader_data* datap = ((nvpe_color_fader_data*)data->paramters);
|
---|
| 270 | vec4 adjustment = datap->adjustment * factor;
|
---|
| 271 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 272 | {
|
---|
| 273 | p[i].color = glm::clamp( p[i].color + adjustment, 0.0f, 1.0f );
|
---|
| 274 | }
|
---|
| 275 | }
|
---|
| 276 |
|
---|
| 277 | struct nvpe_scaler_data
|
---|
| 278 | {
|
---|
| 279 | nv::vec2 adjustment;
|
---|
| 280 | };
|
---|
| 281 |
|
---|
| 282 | static bool nv_particle_affector_scaler_init( lua::table_guard* table, particle_affector_data* data )
|
---|
| 283 | {
|
---|
| 284 | nvpe_scaler_data* datap = ((nvpe_scaler_data*)data->paramters);
|
---|
| 285 | float rate = table->get<float>("rate", 0.0f );
|
---|
| 286 | datap->adjustment = table->get<vec2>("adjustment", vec2(rate,rate) );
|
---|
| 287 | return true;
|
---|
| 288 | }
|
---|
| 289 |
|
---|
| 290 | static void nv_particle_affector_scaler( const particle_affector_data* data, particle* p, float factor, uint32 count )
|
---|
| 291 | {
|
---|
| 292 | nvpe_scaler_data* datap = ((nvpe_scaler_data*)data->paramters);
|
---|
| 293 | vec2 adjustment = datap->adjustment * factor;
|
---|
| 294 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 295 | {
|
---|
| 296 | p[i].size = glm::max( p[i].size + adjustment, vec2() );
|
---|
| 297 | }
|
---|
| 298 | }
|
---|
| 299 |
|
---|
[306] | 300 | void nv::particle_engine::load( lua::table_guard& table )
|
---|
| 301 | {
|
---|
| 302 | std::string id = table.get_string( "id" );
|
---|
| 303 | if ( id == "" )
|
---|
| 304 | {
|
---|
| 305 | NV_LOG( LOG_ERROR, "Bad table passed to particle_engine!" )
|
---|
| 306 | }
|
---|
| 307 | // TODO : overwrite check
|
---|
| 308 | m_names[ id ] = m_data.size();
|
---|
| 309 |
|
---|
| 310 | m_data.emplace_back();
|
---|
| 311 | auto& data = m_data.back();
|
---|
| 312 |
|
---|
| 313 | data.quota = table.get<uint32>("quota", 1024 );
|
---|
[309] | 314 | data.local = table.get<bool>("local_space", false );
|
---|
[306] | 315 | data.accurate_facing = table.get<bool>("accurate_facing", false );
|
---|
| 316 | data.emmiter_count = 0;
|
---|
[312] | 317 | data.affector_count = 0;
|
---|
[306] | 318 |
|
---|
| 319 | std::string orientation = table.get_string( "orientation", "point" );
|
---|
| 320 | if ( orientation == "point" ) { data.orientation = particle_orientation::POINT; }
|
---|
| 321 | else if ( orientation == "oriented" ) { data.orientation = particle_orientation::ORIENTED; }
|
---|
| 322 | else if ( orientation == "oriented_common" ) { data.orientation = particle_orientation::ORIENTED_COMMON; }
|
---|
| 323 | else if ( orientation == "perpendicular" ) { data.orientation = particle_orientation::PERPENDICULAR; }
|
---|
| 324 | else if ( orientation == "perpendicular_common" ) { data.orientation = particle_orientation::PERPENDICULAR_COMMON; }
|
---|
| 325 | else
|
---|
| 326 | {
|
---|
[309] | 327 | NV_LOG( LOG_ERROR, "Unknown orientation type! (" << orientation << ")!" );
|
---|
[306] | 328 | data.orientation = particle_orientation::POINT;
|
---|
| 329 | }
|
---|
[309] | 330 |
|
---|
| 331 | std::string origin = table.get_string( "origin", "center" );
|
---|
| 332 | if ( origin == "center" ) { data.origin = particle_origin::CENTER; }
|
---|
| 333 | else if ( origin == "top_left" ) { data.origin = particle_origin::TOP_LEFT; }
|
---|
| 334 | else if ( origin == "top_center" ) { data.origin = particle_origin::TOP_CENTER; }
|
---|
| 335 | else if ( origin == "top_right" ) { data.origin = particle_origin::TOP_RIGHT; }
|
---|
| 336 | else if ( origin == "center_left" ) { data.origin = particle_origin::CENTER_LEFT; }
|
---|
| 337 | else if ( origin == "center_right" ) { data.origin = particle_origin::CENTER_RIGHT; }
|
---|
| 338 | else if ( origin == "bottom_left" ) { data.origin = particle_origin::BOTTOM_LEFT; }
|
---|
| 339 | else if ( origin == "bottom_center" ) { data.origin = particle_origin::BOTTOM_CENTER; }
|
---|
| 340 | else if ( origin == "bottom_right" ) { data.origin = particle_origin::BOTTOM_RIGHT; }
|
---|
| 341 | else
|
---|
| 342 | {
|
---|
| 343 | NV_LOG( LOG_ERROR, "Unknown particle origin! (" << origin << ")!" );
|
---|
| 344 | data.origin = particle_origin::CENTER;
|
---|
| 345 | }
|
---|
| 346 |
|
---|
[306] | 347 | data.common_up = glm::normalize( table.get<vec3>("common_up", vec3(1,0,0) ) );
|
---|
| 348 | data.common_dir = glm::normalize( table.get<vec3>("common_dir", vec3(0,1,0) ) );
|
---|
| 349 |
|
---|
[309] | 350 | vec2 def_size = table.get<vec2>("size", vec2(0.1,0.1) );
|
---|
[306] | 351 | uint32 elements = table.get_size();
|
---|
| 352 | for ( uint32 i = 0; i < elements; ++i )
|
---|
| 353 | {
|
---|
| 354 | lua::table_guard element( table, i+1 );
|
---|
[309] | 355 | std::string type = element.get_string("type");
|
---|
| 356 | std::string sub_type = element.get_string("sub_type");
|
---|
[306] | 357 | if ( type == "emmiter" )
|
---|
| 358 | {
|
---|
| 359 | if ( data.emmiter_count < MAX_PARTICLE_EMMITERS )
|
---|
| 360 | {
|
---|
| 361 | particle_emmiter_data& edata = data.emmiters[ data.emmiter_count ];
|
---|
[312] | 362 | auto emmiter_iter = m_emmiters.find( sub_type );
|
---|
| 363 | if ( emmiter_iter != m_emmiters.end() )
|
---|
| 364 | {
|
---|
| 365 | edata.emmiter_func = emmiter_iter->second;
|
---|
| 366 | }
|
---|
[309] | 367 | else
|
---|
| 368 | {
|
---|
[312] | 369 | edata.emmiter_func = nv_particle_emmiter_point;
|
---|
[309] | 370 | NV_LOG( LOG_WARNING, "Unknown emmiter type in particle system! (" << sub_type << ")" );
|
---|
| 371 | }
|
---|
| 372 |
|
---|
| 373 | edata.position = element.get<vec3>("position", vec3() );
|
---|
| 374 | edata.extents = element.get<vec3>("extents", vec3(1,1,1) );
|
---|
| 375 | edata.extents[0] = element.get<float>("width", edata.extents[0] );
|
---|
| 376 | edata.extents[1] = element.get<float>("depth", edata.extents[1] );
|
---|
| 377 | edata.extents[2] = element.get<float>("height", edata.extents[2] );
|
---|
| 378 | edata.extents[0] = element.get<float>("radius", edata.extents[0] );
|
---|
| 379 | edata.iextents = element.get<vec3>("inner_extents", vec3() );
|
---|
| 380 | edata.iextents[0] = element.get<float>("inner_width", edata.iextents[0] );
|
---|
| 381 | edata.iextents[1] = element.get<float>("inner_depth", edata.iextents[1] );
|
---|
| 382 | edata.iextents[2] = element.get<float>("inner_height", edata.iextents[2] );
|
---|
| 383 | edata.iextents[0] = element.get<float>("inner_radius", edata.iextents[0] );
|
---|
| 384 | edata.hextents = 0.5f * edata.extents;
|
---|
| 385 | edata.ihextents = 0.5f * edata.iextents;
|
---|
| 386 | edata.precise = element.get<bool>("precise", false );
|
---|
| 387 | edata.square = element.get<bool>("square", true );
|
---|
[306] | 388 | vec4 color = element.get<vec4>("color", vec4(1,1,1,1) );
|
---|
| 389 | edata.color_min = element.get<vec4>("color_min", color );
|
---|
| 390 | edata.color_max = element.get<vec4>("color_max", color );
|
---|
[309] | 391 | vec2 size = element.get<vec2>("size", def_size );
|
---|
[306] | 392 | edata.size_min = element.get<vec2>("size_min", size );
|
---|
| 393 | edata.size_max = element.get<vec2>("size_max", size );
|
---|
| 394 | edata.angle = element.get<float>("angle", 0.0f );
|
---|
| 395 | float velocity = element.get<float>("velocity", 0.0f );
|
---|
| 396 | edata.velocity_min = element.get<float>("velocity_min", velocity );
|
---|
| 397 | edata.velocity_max = element.get<float>("velocity_max", velocity );
|
---|
| 398 | float lifetime = element.get<float>("lifetime", 1.0f );
|
---|
| 399 | edata.lifetime_min = uint32( element.get<float>("lifetime_min", lifetime ) * 1000.f );
|
---|
| 400 | edata.lifetime_max = uint32( element.get<float>("lifetime_max", lifetime ) * 1000.f );
|
---|
[307] | 401 | float duration = element.get<float>("duration", 0.0f );
|
---|
| 402 | edata.duration_min = uint32( element.get<float>("duration_min", duration ) * 1000.f );
|
---|
| 403 | edata.duration_max = uint32( element.get<float>("duration_max", duration ) * 1000.f );
|
---|
| 404 | float repeat = element.get<float>("repeat_delay", 0.0f );
|
---|
| 405 | edata.repeat_min = uint32( element.get<float>("repeat_delay_min", repeat ) * 1000.f );
|
---|
| 406 | edata.repeat_max = uint32( element.get<float>("repeat_delay_max", repeat ) * 1000.f );
|
---|
| 407 |
|
---|
[306] | 408 | edata.rate = element.get<float>("rate", 1.0f );
|
---|
| 409 | edata.dir = glm::normalize( element.get<vec3>("direction", vec3(0,1,0) ) );
|
---|
| 410 |
|
---|
| 411 | edata.odir = glm::vec3( 0, 0, 1 );
|
---|
| 412 | if ( edata.dir != vec3( 0, 1, 0 ) && edata.dir != vec3( 0, -1, 0 ) )
|
---|
| 413 | edata.odir = glm::normalize( glm::cross( edata.dir, vec3( 0, 1, 0 ) ) ); edata.cdir = glm::cross( edata.dir, edata.odir );
|
---|
| 414 |
|
---|
| 415 | data.emmiter_count++;
|
---|
| 416 | }
|
---|
| 417 | else
|
---|
| 418 | {
|
---|
| 419 | NV_LOG( LOG_ERROR, "Too many emmiters (" << MAX_PARTICLE_EMMITERS << " is MAX)!" );
|
---|
| 420 | }
|
---|
| 421 | }
|
---|
| 422 | else if ( type == "affector" )
|
---|
| 423 | {
|
---|
[312] | 424 | if ( data.affector_count < MAX_PARTICLE_AFFECTORS )
|
---|
| 425 | {
|
---|
| 426 | particle_affector_data& adata = data.affectors[ data.affector_count ];
|
---|
| 427 | data.affector_count++;
|
---|
| 428 | auto affector_iter = m_affectors.find( sub_type );
|
---|
| 429 | if ( affector_iter != m_affectors.end() )
|
---|
| 430 | {
|
---|
| 431 | adata.process = affector_iter->second.process;
|
---|
| 432 | if ( !affector_iter->second.init( &element, &adata ) )
|
---|
| 433 | {
|
---|
| 434 | data.affector_count--;
|
---|
| 435 | NV_LOG( LOG_WARNING, "Bad data passed to " << sub_type << " affector in particle system!" );
|
---|
| 436 | }
|
---|
| 437 | }
|
---|
| 438 | else
|
---|
| 439 | {
|
---|
| 440 | data.affector_count--;
|
---|
| 441 | NV_LOG( LOG_WARNING, "Unknown affector type in particle system! (" << sub_type << ")" );
|
---|
| 442 | }
|
---|
| 443 | }
|
---|
| 444 | else
|
---|
| 445 | {
|
---|
| 446 | NV_LOG( LOG_ERROR, "Too many affectors (" << MAX_PARTICLE_AFFECTORS << " is MAX)!" );
|
---|
| 447 | }
|
---|
[306] | 448 | }
|
---|
| 449 | else
|
---|
| 450 | {
|
---|
| 451 | NV_LOG( LOG_WARNING, "Unknown element in particle system! (" << type << ")" );
|
---|
| 452 | }
|
---|
| 453 | }
|
---|
| 454 |
|
---|
| 455 | }
|
---|
| 456 |
|
---|
| 457 | nv::particle_engine::particle_engine( context* a_context )
|
---|
| 458 | {
|
---|
| 459 | m_context = a_context;
|
---|
| 460 | m_device = a_context->get_device();
|
---|
| 461 | m_program_local = m_device->create_program( nv_particle_engine_vertex_shader_local, nv_particle_engine_fragment_shader );
|
---|
| 462 | m_program_world = m_device->create_program( nv_particle_engine_vertex_shader_world, nv_particle_engine_fragment_shader );
|
---|
[312] | 463 |
|
---|
| 464 | register_standard_emmiters();
|
---|
| 465 | register_standard_affectors();
|
---|
[306] | 466 | }
|
---|
| 467 |
|
---|
| 468 | nv::particle_system nv::particle_engine::create_system( const std::string& id )
|
---|
| 469 | {
|
---|
| 470 | auto it = m_names.find( id );
|
---|
| 471 | if ( it == m_names.end() )
|
---|
| 472 | {
|
---|
| 473 | return particle_system();
|
---|
| 474 | }
|
---|
| 475 | const particle_system_data* data = &(m_data[it->second]);
|
---|
| 476 | particle_system result = m_systems.create();
|
---|
| 477 | particle_system_info* info = m_systems.get( result );
|
---|
| 478 |
|
---|
| 479 | info->data = data;
|
---|
| 480 | uint32 ecount = data->emmiter_count;
|
---|
| 481 | for ( uint32 i = 0; i < ecount; ++i )
|
---|
| 482 | {
|
---|
[307] | 483 | info->emmiters[i].active = true;
|
---|
[306] | 484 | info->emmiters[i].last_create = 0;
|
---|
[307] | 485 | info->emmiters[i].next_toggle = random::get().urange( data->emmiters[i].duration_min, data->emmiters[i].duration_max );
|
---|
[306] | 486 | }
|
---|
| 487 |
|
---|
| 488 | info->count = 0;
|
---|
| 489 | info->particles = new particle[ data->quota ];
|
---|
| 490 | info->quads = new particle_quad[ data->quota ];
|
---|
[313] | 491 | info->vtx_array = m_context->create_vertex_array<particle_vtx>(
|
---|
[306] | 492 | (particle_vtx*)info->quads, data->quota*6, STREAM_DRAW );
|
---|
[313] | 493 | info->vtx_buffer = m_context->find_buffer( info->vtx_array, slot::POSITION );
|
---|
[306] | 494 | info->last_update = 0;
|
---|
| 495 | info->test = false;
|
---|
| 496 | // result->m_own_va = true;
|
---|
| 497 | // result->m_offset = 0;
|
---|
| 498 |
|
---|
| 499 | return result;
|
---|
| 500 | }
|
---|
| 501 |
|
---|
| 502 | void nv::particle_engine::draw( particle_system system, const render_state& rs, const scene_state& ss )
|
---|
| 503 | {
|
---|
| 504 | particle_system_info* info = m_systems.get( system );
|
---|
| 505 | if ( info )
|
---|
| 506 | {
|
---|
| 507 | m_context->draw( nv::TRIANGLES, rs, ss, info->data->local ? m_program_local : m_program_world, info->vtx_array, info->count * 6 );
|
---|
| 508 | }
|
---|
| 509 | }
|
---|
| 510 |
|
---|
| 511 | nv::particle_engine::~particle_engine()
|
---|
| 512 | {
|
---|
| 513 | m_device->release( m_program_world );
|
---|
| 514 | m_device->release( m_program_local );
|
---|
| 515 | }
|
---|
| 516 |
|
---|
| 517 | void nv::particle_engine::release( particle_system system )
|
---|
| 518 | {
|
---|
| 519 | particle_system_info* info = m_systems.get( system );
|
---|
| 520 | if ( info )
|
---|
| 521 | {
|
---|
| 522 | delete[] info->particles;
|
---|
| 523 | delete[] info->quads;
|
---|
| 524 | //if ( system->own_va )
|
---|
[313] | 525 | m_context->release( info->vtx_array );
|
---|
[306] | 526 | m_systems.destroy( system );
|
---|
| 527 | }
|
---|
| 528 | }
|
---|
| 529 |
|
---|
| 530 | void nv::particle_engine::update( particle_system system, const scene_state& s, uint32 ms )
|
---|
| 531 | {
|
---|
| 532 | particle_system_info* info = m_systems.get( system );
|
---|
| 533 | if ( info )
|
---|
| 534 | {
|
---|
| 535 | m_view_matrix = s.get_view();
|
---|
| 536 | m_model_matrix = s.get_model();
|
---|
| 537 | m_camera_pos = s.get_camera().get_position();
|
---|
| 538 | m_inv_view_dir = glm::normalize(-s.get_camera().get_direction());
|
---|
| 539 |
|
---|
[307] | 540 | update_emmiters( info, ms );
|
---|
[306] | 541 | destroy_particles( info, ms );
|
---|
| 542 | create_particles( info, ms );
|
---|
| 543 | update_particles( info, ms );
|
---|
| 544 |
|
---|
| 545 | generate_data( info );
|
---|
| 546 | m_context->update( info->vtx_buffer, info->quads, /*system->m_offset*sizeof(particle_quad)*/ 0, info->count*sizeof(particle_quad) );
|
---|
| 547 | }
|
---|
| 548 | }
|
---|
| 549 |
|
---|
| 550 | void nv::particle_engine::set_texcoords( particle_system system, vec2 a, vec2 b )
|
---|
| 551 | {
|
---|
| 552 | particle_system_info* info = m_systems.get( system );
|
---|
| 553 | if ( info )
|
---|
| 554 | {
|
---|
| 555 | vec2 texcoords[4] = { a, vec2( b.x, a.y ), vec2( a.x, b.y ), b };
|
---|
| 556 |
|
---|
| 557 | for ( uint32 i = 0; i < info->data->quota; ++i )
|
---|
| 558 | {
|
---|
| 559 | particle_quad& rdata = info->quads[i];
|
---|
| 560 | rdata.data[0].texcoord = texcoords[0];
|
---|
| 561 | rdata.data[1].texcoord = texcoords[1];
|
---|
| 562 | rdata.data[2].texcoord = texcoords[2];
|
---|
| 563 | rdata.data[3].texcoord = texcoords[3];
|
---|
| 564 | rdata.data[4].texcoord = texcoords[2];
|
---|
| 565 | rdata.data[5].texcoord = texcoords[1];
|
---|
| 566 | }
|
---|
| 567 | }
|
---|
| 568 | }
|
---|
| 569 |
|
---|
| 570 | void nv::particle_engine::generate_data( particle_system_info* info )
|
---|
| 571 | {
|
---|
[309] | 572 | vec2 lb = vec2( -0.5f, -0.5f );
|
---|
| 573 | vec2 rt = vec2( 0.5f, 0.5f );
|
---|
[306] | 574 |
|
---|
[309] | 575 | switch ( info->data->origin )
|
---|
| 576 | {
|
---|
| 577 | case particle_origin::CENTER : break;
|
---|
| 578 | case particle_origin::TOP_LEFT : lb = vec2(0.f,-1.f); rt = vec2(1.f,0.f); break;
|
---|
[323] | 579 | case particle_origin::TOP_CENTER : lb.y = -1.f; rt.y = 0.f; break;
|
---|
[309] | 580 | case particle_origin::TOP_RIGHT : lb = vec2(-1.f,-1.f); rt = vec2(); break;
|
---|
| 581 | case particle_origin::CENTER_LEFT : lb.x = 0.f; rt.x = 1.f; break;
|
---|
| 582 | case particle_origin::CENTER_RIGHT : lb.x = -1.f; rt.x = 0.f; break;
|
---|
| 583 | case particle_origin::BOTTOM_LEFT : lb = vec2(); rt = vec2(1.f,1.f); break;
|
---|
| 584 | case particle_origin::BOTTOM_CENTER : lb.y = 0.f; rt.y = 1.f; break;
|
---|
| 585 | case particle_origin::BOTTOM_RIGHT : lb = vec2(-1.f,0.f); rt = vec2(.0f,1.f); break;
|
---|
| 586 | }
|
---|
| 587 |
|
---|
| 588 | const vec3 sm[4] =
|
---|
| 589 | {
|
---|
| 590 | vec3( lb.x, lb.y, 0.0f ),
|
---|
| 591 | vec3( rt.x, lb.y, 0.0f ),
|
---|
| 592 | vec3( lb.x, rt.y, 0.0f ),
|
---|
| 593 | vec3( rt.x, rt.y, 0.0f ),
|
---|
[306] | 594 | };
|
---|
[309] | 595 | vec3 z( 0.0f, 0.0f ,1.0f );
|
---|
[306] | 596 |
|
---|
| 597 | particle_orientation orientation = info->data->orientation;
|
---|
| 598 | vec3 common_up ( info->data->common_up );
|
---|
| 599 | vec3 common_dir( info->data->common_dir );
|
---|
| 600 | bool accurate_facing = info->data->accurate_facing;
|
---|
[312] | 601 | mat3 rot_mat;
|
---|
| 602 | vec3 right;
|
---|
| 603 | vec3 pdir( 0.0f, 1.0f, 0.0f );
|
---|
[306] | 604 |
|
---|
| 605 | for ( uint32 i = 0; i < info->count; ++i )
|
---|
| 606 | {
|
---|
| 607 | const particle& pdata = info->particles[i];
|
---|
| 608 | particle_quad& rdata = info->quads[i];
|
---|
| 609 |
|
---|
| 610 | vec3 view_dir( m_inv_view_dir );
|
---|
| 611 | if ( accurate_facing ) view_dir = glm::normalize( m_camera_pos - pdata.position );
|
---|
| 612 |
|
---|
| 613 | switch ( orientation )
|
---|
| 614 | {
|
---|
| 615 | case particle_orientation::POINT :
|
---|
| 616 | right = glm::normalize( glm::cross( view_dir, vec3( 0, 1, 0 ) ) );
|
---|
| 617 | rot_mat = mat3( right, glm::cross( right, -view_dir ), -view_dir );
|
---|
| 618 | break;
|
---|
| 619 | case particle_orientation::ORIENTED :
|
---|
[312] | 620 | pdir = normalize_safe( pdata.velocity, pdir );
|
---|
| 621 | right = glm::normalize( glm::cross( pdir, view_dir ) );
|
---|
| 622 | rot_mat = mat3( right, pdir, glm::cross( pdir, right ) );
|
---|
[306] | 623 | break;
|
---|
| 624 | case particle_orientation::ORIENTED_COMMON :
|
---|
| 625 | right = glm::normalize( glm::cross( common_dir, view_dir ) );
|
---|
| 626 | rot_mat = mat3( right, common_dir, glm::cross( common_dir, right ) );
|
---|
| 627 | break;
|
---|
| 628 | case particle_orientation::PERPENDICULAR :
|
---|
[312] | 629 | pdir = normalize_safe( pdata.velocity, pdir );
|
---|
| 630 | right = glm::normalize( glm::cross( common_up, pdir ) );
|
---|
[306] | 631 | rot_mat = mat3( right, common_up, glm::cross( common_up, right ) );
|
---|
| 632 | break;
|
---|
| 633 | case particle_orientation::PERPENDICULAR_COMMON :
|
---|
| 634 | right = glm::normalize( glm::cross( common_up, common_dir ) );
|
---|
| 635 | rot_mat = mat3( right, common_up, glm::cross( common_up, right ) );
|
---|
| 636 | break;
|
---|
| 637 | }
|
---|
| 638 |
|
---|
| 639 | vec3 size( pdata.size.x, pdata.size.y, 0.0f );
|
---|
| 640 | vec3 s0 = rot_mat * ( ( size * sm[0] ) );
|
---|
| 641 | vec3 s1 = rot_mat * ( ( size * sm[1] ) );
|
---|
| 642 | vec3 s2 = rot_mat * ( ( size * sm[2] ) );
|
---|
| 643 | vec3 s3 = rot_mat * ( ( size * sm[3] ) );
|
---|
| 644 |
|
---|
| 645 | rdata.data[0].position = pdata.position + s0;
|
---|
| 646 | rdata.data[0].color = pdata.color;
|
---|
| 647 |
|
---|
| 648 | rdata.data[1].position = pdata.position + s1;
|
---|
| 649 | rdata.data[1].color = pdata.color;
|
---|
| 650 |
|
---|
| 651 | rdata.data[2].position = pdata.position + s2;
|
---|
| 652 | rdata.data[2].color = pdata.color;
|
---|
| 653 |
|
---|
| 654 | rdata.data[3].position = pdata.position + s3;
|
---|
| 655 | rdata.data[3].color = pdata.color;
|
---|
| 656 |
|
---|
| 657 | rdata.data[4] = rdata.data[2];
|
---|
| 658 | rdata.data[5] = rdata.data[1];
|
---|
| 659 | }
|
---|
| 660 | }
|
---|
| 661 |
|
---|
| 662 | void nv::particle_engine::destroy_particles( particle_system_info* info, uint32 ms )
|
---|
| 663 | {
|
---|
| 664 | if ( info->count > 0 )
|
---|
[323] | 665 | for ( sint32 i = (sint32)info->count-1; i >= 0; --i )
|
---|
[306] | 666 | {
|
---|
| 667 | particle& pinfo = info->particles[i];
|
---|
| 668 | if ( //pdata.position.y < 0.0f ||
|
---|
| 669 | ms >= pinfo.death )
|
---|
| 670 | {
|
---|
| 671 | info->count--;
|
---|
| 672 | std::swap( info->particles[i], info->particles[info->count] );
|
---|
| 673 | }
|
---|
| 674 | }
|
---|
| 675 | }
|
---|
| 676 |
|
---|
| 677 | void nv::particle_engine::create_particles( particle_system_info* info, uint32 ms )
|
---|
| 678 | {
|
---|
| 679 | uint32 ecount = info->data->emmiter_count;
|
---|
| 680 | if ( ecount == 0 ) return;
|
---|
| 681 |
|
---|
| 682 | random& r = random::get();
|
---|
| 683 | vec3 source;
|
---|
| 684 | mat3 orient;
|
---|
[312] | 685 | bool local = info->data->local;
|
---|
| 686 | if ( !local )
|
---|
[306] | 687 | {
|
---|
| 688 | source = vec3( m_model_matrix[3] );
|
---|
| 689 | orient = mat3( m_model_matrix );
|
---|
| 690 | }
|
---|
[312] | 691 |
|
---|
[309] | 692 | float fms = float(ms);
|
---|
[306] | 693 |
|
---|
| 694 | for ( uint32 i = 0; i < ecount; ++i )
|
---|
| 695 | {
|
---|
| 696 | const auto& edata = info->data->emmiters[i];
|
---|
| 697 | auto& einfo = info->emmiters[i];
|
---|
[307] | 698 | if ( einfo.active )
|
---|
[306] | 699 | {
|
---|
[309] | 700 | float period = 1000.f / edata.rate;
|
---|
| 701 | while ( fms - einfo.last_create > period )
|
---|
[306] | 702 | {
|
---|
[307] | 703 | if ( info->count < info->data->quota-1 )
|
---|
| 704 | {
|
---|
| 705 | particle& pinfo = info->particles[info->count];
|
---|
[312] | 706 | edata.emmiter_func( &(info->data->emmiters[i]), &pinfo, 1 );
|
---|
| 707 |
|
---|
| 708 | if ( !local ) pinfo.position = orient * pinfo.position + source;
|
---|
[309] | 709 | pinfo.position += edata.position;
|
---|
| 710 | pinfo.color = edata.color_min == edata.color_max ?
|
---|
[307] | 711 | edata.color_min : r.range( edata.color_min, edata.color_max );
|
---|
[309] | 712 | pinfo.size = edata.size_min == edata.size_max ?
|
---|
[307] | 713 | edata.size_min : r.range( edata.size_min, edata.size_max );
|
---|
| 714 | if ( edata.square ) pinfo.size.y = pinfo.size.x;
|
---|
[312] | 715 | float velocity = edata.velocity_min == edata.velocity_max ?
|
---|
[307] | 716 | edata.velocity_min : r.frange( edata.velocity_min, edata.velocity_max );
|
---|
| 717 | pinfo.death = ms + ( edata.lifetime_min == edata.lifetime_max ?
|
---|
| 718 | edata.lifetime_min : r.urange( edata.lifetime_min, edata.lifetime_max ) );
|
---|
| 719 | //pinfo.rotation = r.frand( 360.0f );
|
---|
[306] | 720 |
|
---|
[312] | 721 | pinfo.velocity = edata.dir;
|
---|
[307] | 722 | if ( edata.angle > 0.0f )
|
---|
| 723 | {
|
---|
| 724 | float emission_angle = glm::radians( edata.angle );
|
---|
[323] | 725 | float cos_theta = r.frange( glm::cos( emission_angle ), 1.0f );
|
---|
[307] | 726 | float sin_theta = glm::sqrt(1.0f - cos_theta * cos_theta );
|
---|
| 727 | float phi = r.frange( 0.0f, 2*glm::pi<float>() );
|
---|
[312] | 728 | pinfo.velocity = orient *
|
---|
[307] | 729 | ( edata.odir * ( glm::cos(phi) * sin_theta ) +
|
---|
| 730 | edata.cdir * ( glm::sin(phi)*sin_theta ) +
|
---|
| 731 | edata.dir * cos_theta );
|
---|
| 732 | }
|
---|
| 733 |
|
---|
[312] | 734 | pinfo.velocity *= velocity;
|
---|
| 735 |
|
---|
[307] | 736 | info->count++;
|
---|
[306] | 737 | }
|
---|
[307] | 738 | einfo.last_create += period;
|
---|
[306] | 739 | }
|
---|
| 740 | }
|
---|
| 741 | }
|
---|
| 742 | }
|
---|
| 743 |
|
---|
[312] | 744 | void nv::particle_engine::update_particles( particle_system_info* info, uint32 ms )
|
---|
[306] | 745 | {
|
---|
[312] | 746 | uint32 ticks = ms - info->last_update;
|
---|
| 747 | if ( ticks == 0 ) return;
|
---|
| 748 | float factor = 0.001f * ticks;
|
---|
| 749 |
|
---|
| 750 | uint32 acount = info->data->affector_count;
|
---|
| 751 | for ( uint32 i = 0; i < acount; ++i )
|
---|
| 752 | {
|
---|
| 753 | const particle_affector_data* padata = &(info->data->affectors[i]);
|
---|
| 754 | padata->process( padata, info->particles, factor, info->count );
|
---|
| 755 | }
|
---|
| 756 |
|
---|
| 757 |
|
---|
| 758 | for ( uint32 i = 0; i < info->count; ++i )
|
---|
| 759 | {
|
---|
| 760 | particle& pdata = info->particles[i];
|
---|
| 761 | pdata.position += pdata.velocity * factor;
|
---|
| 762 | }
|
---|
| 763 | info->last_update = ms;
|
---|
[307] | 764 | }
|
---|
| 765 |
|
---|
| 766 | void nv::particle_engine::update_emmiters( particle_system_info* info, uint32 ms )
|
---|
| 767 | {
|
---|
| 768 | uint32 ecount = info->data->emmiter_count;
|
---|
| 769 | if ( ecount == 0 ) return;
|
---|
| 770 | random& r = random::get();
|
---|
| 771 |
|
---|
| 772 | for ( uint32 i = 0; i < ecount; ++i )
|
---|
| 773 | {
|
---|
| 774 | const auto& edata = info->data->emmiters[i];
|
---|
| 775 | auto& einfo = info->emmiters[i];
|
---|
| 776 |
|
---|
| 777 | if ( einfo.next_toggle != 0 && ms >= einfo.next_toggle )
|
---|
| 778 | {
|
---|
| 779 | if ( einfo.active )
|
---|
| 780 | {
|
---|
| 781 | einfo.active = false;
|
---|
| 782 | if ( edata.repeat_min > 0 )
|
---|
| 783 | einfo.next_toggle += r.urange( edata.repeat_min, edata.repeat_max );
|
---|
| 784 | else
|
---|
| 785 | einfo.next_toggle = 0;
|
---|
| 786 | }
|
---|
| 787 | else
|
---|
| 788 | {
|
---|
| 789 | einfo.active = true;
|
---|
[309] | 790 | einfo.last_create = float( einfo.next_toggle );
|
---|
[307] | 791 | einfo.next_toggle += r.urange( edata.duration_min, edata.duration_max );
|
---|
| 792 | }
|
---|
| 793 | }
|
---|
| 794 | }
|
---|
| 795 |
|
---|
| 796 | }
|
---|
[312] | 797 |
|
---|
| 798 | void nv::particle_engine::register_emmiter_type( const std::string& name, particle_emmiter_func func )
|
---|
| 799 | {
|
---|
| 800 | m_emmiters[ name ] = func;
|
---|
| 801 | }
|
---|
| 802 |
|
---|
| 803 | void nv::particle_engine::register_standard_emmiters()
|
---|
| 804 | {
|
---|
| 805 | register_emmiter_type( "point", nv_particle_emmiter_point );
|
---|
| 806 | register_emmiter_type( "box", nv_particle_emmiter_box );
|
---|
| 807 | register_emmiter_type( "cylinder", nv_particle_emmiter_cylinder );
|
---|
| 808 | register_emmiter_type( "sphere", nv_particle_emmiter_sphere );
|
---|
| 809 | register_emmiter_type( "cylindroid", nv_particle_emmiter_cylindroid );
|
---|
| 810 | register_emmiter_type( "ellipsoid", nv_particle_emmiter_ellipsoid );
|
---|
| 811 | register_emmiter_type( "hollow_cylinder", nv_particle_emmiter_hollow_cylinder );
|
---|
| 812 | register_emmiter_type( "hollow_sphere", nv_particle_emmiter_hollow_sphere );
|
---|
| 813 | register_emmiter_type( "hollow_cylindroid", nv_particle_emmiter_hollow_cylindroid );
|
---|
| 814 | register_emmiter_type( "hollow_ellipsoid", nv_particle_emmiter_hollow_ellipsoid );
|
---|
| 815 | }
|
---|
| 816 |
|
---|
| 817 | void nv::particle_engine::register_affector_type( const std::string& name, particle_affector_init_func init, particle_affector_func process )
|
---|
| 818 | {
|
---|
| 819 | m_affectors[ name ].init = init;
|
---|
| 820 | m_affectors[ name ].process = process;
|
---|
| 821 | }
|
---|
| 822 |
|
---|
| 823 | void nv::particle_engine::register_standard_affectors()
|
---|
| 824 | {
|
---|
| 825 | register_affector_type( "linear_force", nv_particle_affector_linear_force_init, nv_particle_affector_linear_force );
|
---|
| 826 | register_affector_type( "deflector_plane", nv_particle_affector_deflector_plane_init, nv_particle_affector_deflector_plane );
|
---|
| 827 | register_affector_type( "color_fader", nv_particle_affector_color_fader_init, nv_particle_affector_color_fader );
|
---|
| 828 | register_affector_type( "scaler", nv_particle_affector_scaler_init, nv_particle_affector_scaler );
|
---|
| 829 | }
|
---|
| 830 |
|
---|