- Timestamp:
- 04/14/06 13:04:11 (7 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgprecipitation/osgprecipitation.cpp
r5088 r5090 40 40 nearTransition(25.0), 41 41 farTransition(100.0), 42 fogDensity(0.1), 43 fogEnd(1000.0) 42 fogDensity(0.001), 43 fogExponent(1.0), 44 fogEnd(1000.0), 45 fogColour(0.5, 0.5, 0.5, 1.0) 44 46 {} 45 47 … … 49 51 particleSize = 0.01 + 0.02*intensity; 50 52 numberOfParticles = intensity * 100000000; 51 particleColour = osg::Vec4(0.6, 0.6, 0.6, 1.0); 52 fogDensity = intensity; 53 particleColour = osg::Vec4(0.6, 0.6, 0.6, 1.0) - osg::Vec4(0.1, 0.1, 0.1, 1.0)* intensity; 54 fogExponent = 1.0f; 55 fogDensity = 0.01f*intensity; 53 56 fogEnd = 250/(0.01 + intensity); 57 farTransition = 150.0f - 100.0f*intensity; 54 58 } 55 59 … … 59 63 particleSize = 0.02 + 0.03*intensity; 60 64 numberOfParticles = intensity * 100000000; 61 particleColour = osg::Vec4(0.8, 0.8, 0.8, 1.0); 62 fogDensity = intensity; 63 fogEnd = 150/(0.01 + intensity); 65 particleColour = osg::Vec4(0.85f, 0.85f, 0.85f, 1.0f) - osg::Vec4(0.1f, 0.1f, 0.1f, 1.0f)* intensity; 66 fogExponent = 1.0f; 67 fogDensity = 0.02f*intensity; 68 fogEnd = 150.0f/(0.01f + intensity); 69 farTransition = 150.0f - 100.0f*intensity; 64 70 } 65 71 … … 74 80 float nearTransition; 75 81 float farTransition; 82 float fogExponent; 76 83 float fogDensity; 77 84 float fogEnd; 85 osg::Vec4 fogColour; 78 86 }; 79 87 … … 89 97 virtual bool cull(osg::NodeVisitor* nodeVisitor, osg::Drawable* drawable, osg::State* state) const 90 98 { 91 osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nodeVisitor);92 if (cv)93 {94 float distance = nodeVisitor->getDistanceFromEyePoint(drawable->getBound().center(),true);95 96 // if (distance<-4.0) return true;97 98 #if 099 100 const osg::BoundingBox& bb = drawable->getBound();101 const osg::Polytope& frustum = cv->getCurrentCullingSet().getFrustum();102 int numPointsInside = 0;103 for(unsigned int i=0; i<8; ++i)104 {105 if (frustum.contains(bb.corner(i))) ++numPointsInside;106 }107 108 std::cout<<" "<<drawable->getName()<<" distance "<<distance<<"num Points inside = "<<numPointsInside<<std::endl;109 110 if (cv->isCulled(drawable->getBound()))111 {112 std::cout<<" isCulled "<<drawable->getName()<<std::endl;113 return true;114 }115 #endif116 117 }118 119 99 return false; 120 100 } … … 144 124 void setPosition(const osg::Vec3& position) { _position = position; } 145 125 const osg::Vec3& getPosition() const { return _position; } 146 147 126 127 void setStartTime(float time) { _startTime = time; } 128 float getStartTime() const { return _startTime; } 129 130 148 131 virtual void compileGLObjects(osg::State& state) const 149 132 { … … 162 145 if (!_internalGeometry) return; 163 146 147 const Extensions* extensions = getExtensions(state.getContextID(),true); 148 164 149 glNormal3fv(_position.ptr()); 150 extensions->glMultiTexCoord1f(GL_TEXTURE1, _startTime); 165 151 166 152 _internalGeometry->draw(state); … … 215 201 216 202 osg::Vec3 _position; 203 float _startTime; 217 204 osg::ref_ptr<osg::Geometry> _internalGeometry; 218 205 … … 508 495 osg::Vec3 dv_j( 0.0f, bb.yMax()-bb.yMin(), 0.0f ); 509 496 osg::Vec3 dv_k( velocity * period ); 497 498 float startTime = random(0, period); 510 499 511 500 // high res LOD. … … 519 508 geometry->setName("highres"); 520 509 geometry->setPosition(position); 510 geometry->setStartTime(startTime); 521 511 geometry->setInitialBound(bb); 522 512 geometry->setInternalGeometry(quad_geometry.get()); … … 537 527 geometry->setName("lowres"); 538 528 geometry->setPosition(position); 529 geometry->setStartTime(startTime); 539 530 geometry->setInitialBound(bb); 540 531 geometry->setInternalGeometry(point_geometry.get()); … … 606 597 607 598 osg::Uniform* inversePeriodUniform = new osg::Uniform("inversePeriod",1.0f/period); 608 osg::Uniform* startTime = new osg::Uniform("startTime",0.0f);599 //osg::Uniform* startTime = new osg::Uniform("startTime",0.0f); 609 600 610 601 //stateset->addUniform(position_Uniform); // vec3 … … 613 604 stateset->addUniform(dv_k_Uniform); // vec3 614 605 stateset->addUniform(inversePeriodUniform); // float 615 stateset->addUniform(startTime); // float606 //stateset->addUniform(startTime); // float 616 607 617 608 stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF); … … 657 648 658 649 osg::Fog* fog = new osg::Fog; 659 fog->setMode(osg::Fog::LINEAR); 650 651 if (parameters.fogExponent<1.0) 652 { 653 fog->setMode(osg::Fog::LINEAR); 654 } 655 else if (parameters.fogExponent<2.0) 656 { 657 fog->setMode(osg::Fog::EXP); 658 } 659 else 660 { 661 fog->setMode(osg::Fog::EXP2); 662 } 663 660 664 fog->setDensity(parameters.fogDensity); 661 665 fog->setStart(0.0f); 662 666 fog->setEnd(parameters.fogEnd); 663 fog->setColor( osg::Vec4(0.5f,0.5f,0.5f,1.0f));667 fog->setColor(parameters.fogColour); 664 668 stateset->setAttributeAndModes(fog, osg::StateAttribute::ON); 665 669 … … 693 697 arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); 694 698 arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); 695 arguments.getApplicationUsage()->addCommandLineOption("--shader","Use GLSL shaders."); 696 arguments.getApplicationUsage()->addCommandLineOption("--fixed","Use fixed function pipeline."); 699 arguments.getApplicationUsage()->addCommandLineOption("",""); 700 arguments.getApplicationUsage()->addCommandLineOption("",""); 701 arguments.getApplicationUsage()->addCommandLineOption("",""); 702 arguments.getApplicationUsage()->addCommandLineOption("",""); 703 arguments.getApplicationUsage()->addCommandLineOption("",""); 704 arguments.getApplicationUsage()->addCommandLineOption("",""); 705 arguments.getApplicationUsage()->addCommandLineOption("",""); 706 arguments.getApplicationUsage()->addCommandLineOption("",""); 707 arguments.getApplicationUsage()->addCommandLineOption("",""); 708 arguments.getApplicationUsage()->addCommandLineOption("",""); 697 709 698 710 … … 713 725 714 726 while (arguments.read("--particleSize", parameters.particleSize)) {} 727 while (arguments.read("--particleColor", parameters.particleColour.r(), parameters.particleColour.g(), parameters.particleColour.b(), parameters.particleColour.a())) {} 728 while (arguments.read("--particleColour", parameters.particleColour.r(), parameters.particleColour.g(), parameters.particleColour.b(), parameters.particleColour.a())) {} 715 729 716 730 osg::Vec3 particleVelocity; … … 734 748 735 749 while (arguments.read("--fogDensity", parameters.fogDensity )) {} 750 while (arguments.read("--fogExponent", parameters.fogExponent )) {} 736 751 while (arguments.read("--fogEnd", parameters.fogEnd )) {} 752 while (arguments.read("--fogColor", parameters.fogColour.r(), parameters.fogColour.g(), parameters.fogColour.b(), parameters.fogColour.a())) {} 753 while (arguments.read("--fogColour", parameters.fogColour.r(), parameters.fogColour.g(), parameters.fogColour.b(), parameters.fogColour.a())) {} 737 754 738 755 // if user request help write it out to cout.
