Changeset 13041 for OpenSceneGraph/trunk/src/osgParticle/ParticleSystem.cpp
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgParticle/ParticleSystem.cpp
r11755 r13041 31 31 32 32 osgParticle::ParticleSystem::ParticleSystem() 33 : osg::Drawable(), 33 : osg::Drawable(), 34 34 _def_bbox(osg::Vec3(-10, -10, -10), osg::Vec3(10, 10, 10)), 35 35 _alignment(BILLBOARD), … … 42 42 _doublepass(false), 43 43 _frozen(false), 44 _bmin(0, 0, 0), 45 _bmax(0, 0, 0), 44 _bmin(0, 0, 0), 45 _bmax(0, 0, 0), 46 46 _reset_bounds_flag(false), 47 47 _bounds_computed(false), … … 63 63 64 64 osgParticle::ParticleSystem::ParticleSystem(const ParticleSystem& copy, const osg::CopyOp& copyop) 65 : osg::Drawable(copy, copyop), 65 : osg::Drawable(copy, copyop), 66 66 _def_bbox(copy._def_bbox), 67 67 _alignment(copy._alignment), … … 74 74 _doublepass(copy._doublepass), 75 75 _frozen(copy._frozen), 76 _bmin(copy._bmin), 77 _bmax(copy._bmax), 76 _bmin(copy._bmin), 77 _bmax(copy._bmax), 78 78 _reset_bounds_flag(copy._reset_bounds_flag), 79 79 _bounds_computed(copy._bounds_computed), … … 108 108 // _cur_tile, _s_coord, _t_coord, _prev_pos, _prev_angle and _angle 109 109 osg::StateSet* stateset = getOrCreateStateSet(); 110 110 111 111 if (_dirty_uniforms) 112 112 { … … 116 116 } 117 117 } 118 118 119 119 for(unsigned int i=0; i<_particles.size(); ++i) 120 120 { … … 132 132 } 133 133 } 134 134 135 135 if (_sortMode != NO_SORT) 136 136 { … … 152 152 } 153 153 } 154 154 155 155 // force recomputing of bounding box on next frame 156 156 dirtyBound(); … … 166 166 // this particle system is culled 167 167 _last_frame = state.getFrameStamp()->getFrameNumber(); 168 168 169 169 // update the dirty flag of delta time, so next time a new request for delta time 170 170 // will automatically cause recomputing 171 171 _dirty_dt = true; 172 172 173 173 // get the current modelview matrix 174 174 osg::Matrix modelview = state.getModelViewMatrix(); … … 176 176 // set up depth mask for first rendering pass 177 177 #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GL3_AVAILABLE) 178 glPushAttrib(GL_DEPTH_BUFFER_BIT); 178 glPushAttrib(GL_DEPTH_BUFFER_BIT); 179 179 #endif 180 180 181 181 glDepthMask(GL_FALSE); 182 182 … … 193 193 194 194 // render, second pass 195 if (_doublepass) { 195 if (_doublepass) { 196 196 // set up color mask for second rendering pass 197 197 #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GL3_AVAILABLE) … … 237 237 texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR); 238 238 texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::MIRROR); 239 texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::MIRROR); 239 texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::MIRROR); 240 240 stateset->setTextureAttributeAndModes(texture_unit, texture, osg::StateAttribute::ON); 241 241 … … 246 246 247 247 osg::BlendFunc *blend = new osg::BlendFunc; 248 if (emissive_particles) { 248 if (emissive_particles) { 249 249 blend->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE); 250 250 } else { … … 263 263 osg::StateSet *stateset = new osg::StateSet; 264 264 stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); 265 265 266 266 osg::PointSprite *sprite = new osg::PointSprite; 267 267 stateset->setTextureAttributeAndModes(texture_unit, sprite, osg::StateAttribute::ON); 268 268 269 269 #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) 270 270 stateset->setMode(GL_VERTEX_PROGRAM_POINT_SIZE, osg::StateAttribute::ON); … … 272 272 OSG_NOTICE<<"Warning: ParticleSystem::setDefaultAttributesUsingShaders(..) not fully implemented."<<std::endl; 273 273 #endif 274 274 275 275 if (!texturefile.empty()) 276 276 { … … 280 280 texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR); 281 281 texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::MIRROR); 282 texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::MIRROR); 282 texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::MIRROR); 283 283 stateset->setTextureAttributeAndModes(texture_unit, texture, osg::StateAttribute::ON); 284 284 } 285 285 286 286 osg::BlendFunc *blend = new osg::BlendFunc; 287 287 if (emissive_particles) 288 { 288 { 289 289 blend->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE); 290 290 } … … 294 294 } 295 295 stateset->setAttributeAndModes(blend, osg::StateAttribute::ON); 296 296 297 297 osg::Program *program = new osg::Program; 298 298 #ifdef USE_LOCAL_SHADERS … … 338 338 #endif 339 339 stateset->setAttributeAndModes(program, osg::StateAttribute::ON); 340 340 341 341 stateset->addUniform(new osg::Uniform("visibilityDistance", (float)_visibilityDistance)); 342 342 stateset->addUniform(new osg::Uniform("baseTexture", texture_unit)); 343 343 setStateSet(stateset); 344 344 345 345 setUseVertexArray(true); 346 346 setUseShaders(true); … … 384 384 yScale = 1.0f/lengthY2; 385 385 } 386 386 387 387 scaled_aligned_xAxis *= xScale; 388 388 scaled_aligned_yAxis *= yScale; 389 389 390 390 xAxis *= xScale; 391 391 yAxis *= yScale; … … 404 404 glDepthMask(GL_TRUE); 405 405 } 406 406 407 407 for(unsigned int i=0; i<_particles.size(); i+=_detail) 408 408 { 409 409 const Particle* currentParticle = &_particles[i]; 410 410 411 411 bool insideDistance = true; 412 412 if (_sortMode != NO_SORT && _visibilityDistance>0.0) 413 413 insideDistance = (currentParticle->getDepth()>=0.0 && currentParticle->getDepth()<=_visibilityDistance); 414 414 415 415 if (currentParticle->isAlive() && insideDistance) 416 416 { … … 429 429 } 430 430 ++_draw_count; 431 431 432 432 if (currentParticle->getShape() == Particle::USER) 433 433 { … … 440 440 continue; 441 441 } 442 442 443 443 const osg::Vec3& angle = currentParticle->getAngle(); 444 444 bool requiresRotation = (angle.x()!=0.0f || angle.y()!=0.0f || angle.z()!=0.0f); … … 447 447 osg::Matrix R; 448 448 R.makeRotate( 449 angle.x(), osg::Vec3(1, 0, 0), 450 angle.y(), osg::Vec3(0, 1, 0), 449 angle.x(), osg::Vec3(1, 0, 0), 450 angle.y(), osg::Vec3(0, 1, 0), 451 451 angle.z(), osg::Vec3(0, 0, 1)); 452 452 … … 455 455 xAxis = osg::Matrix::transform3x3(R,scaled_aligned_xAxis); 456 456 xAxis = osg::Matrix::transform3x3(modelview,xAxis); 457 457 458 458 yAxis = osg::Matrix::transform3x3(R,scaled_aligned_yAxis); 459 459 yAxis = osg::Matrix::transform3x3(modelview,yAxis); … … 473 473 currentParticle->render(gl,currentParticle->getPosition(), xAxis, yAxis, scale); 474 474 } 475 } 475 } 476 476 } 477 477 … … 483 483 { 484 484 if (_particles.size() <= 0) return; 485 485 486 486 // Compute the pointer and offsets 487 487 Particle_vector::const_iterator itr = _particles.begin(); … … 497 497 GLsizei velOffset = (float*)(&(itr->_velocity)) - ptr; // Velocity 498 498 GLsizei propOffset = (float*)(&(itr->_alive)) - ptr; // Alive, size & alpha 499 499 500 500 // Draw particles as arrays 501 501 osg::State& state = *renderInfo.getState(); … … 513 513 514 514 osg::BoundingBox osgParticle::ParticleSystem::computeBound() const 515 { 515 { 516 516 if (!_bounds_computed) 517 517 {
