Show
Ignore:
Timestamp:
04/12/06 13:59:07 (8 years ago)
Author:
robert
Message:

Implement positioning of cells via vertex attribute.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgprecipitation/osgprecipitation.cpp

    r5085 r5086  
    4545         
    4646        osg::Geometry* getInternalGeometry() { return _internalGeometry.get(); } 
     47         
     48        void setPosition(const osg::Vec3& position) { _position = position; } 
     49        const osg::Vec3& getPosition() const { return _position; } 
    4750 
    4851         
     
    6366            if (!_internalGeometry) return; 
    6467             
     68            glNormal3fv(_position.ptr()); 
     69 
    6570            _internalGeometry->draw(state); 
    6671        } 
     
    7378protected:         
    7479 
     80        osg::Vec3                   _position; 
    7581        osg::ref_ptr<osg::Geometry> _internalGeometry; 
    7682 
     
    296302        osg::Program* program = new osg::Program; 
    297303        quad_stateset->setAttribute(program); 
     304        quad_stateset->setRenderBinDetails(13,"DepthSortedBin"); 
    298305 
    299306        // get shaders from source 
     
    311318        osg::Program* program = new osg::Program; 
    312319        line_stateset->setAttribute(program); 
     320        line_stateset->setRenderBinDetails(12,"DepthSortedBin"); 
    313321 
    314322        // get shaders from source 
     
    336344 
    337345        point_stateset->setMode(GL_VERTEX_PROGRAM_POINT_SIZE, osg::StateAttribute::ON); 
     346        point_stateset->setRenderBinDetails(11,"DepthSortedBin"); 
    338347 
    339348    } 
     
    348357    osg::LOD* lod = new osg::LOD; 
    349358     
    350     float nearDistance = 50.0; 
    351     float farDistance = 200.0; 
     359    // time taken to get from start to the end of cycle 
     360    float period = fabs((bb.zMax()-bb.zMin()) / velocity.z()); 
     361 
     362    // distance between start point and end of cyclce 
     363    osg::Vec3 position(bb.xMin(), bb.yMin(), bb.zMax()); 
     364    osg::Vec3 dv_i( bb.xMax()-bb.xMin(), 0.0f, 0.0f ); 
     365    osg::Vec3 dv_j( 0.0f, bb.yMax()-bb.yMin(), 0.0f ); 
     366    osg::Vec3 dv_k( velocity * period ); 
     367 
     368    float nearDistance = 25.0; 
     369    float farDistance = 100.0; 
    352370     
    353371    // high res LOD. 
     
    359377        highres_geode->addDrawable(geometry); 
    360378 
     379        geometry->setPosition(position); 
    361380        geometry->setInitialBound(bb); 
    362381        geometry->setInternalGeometry(quad_geometry.get()); 
     
    374393        lowres_geode->addDrawable(geometry); 
    375394 
     395        geometry->setPosition(position); 
    376396        geometry->setInitialBound(bb); 
    377397        geometry->setInternalGeometry(point_geometry.get()); 
     
    382402 
    383403 
    384     // set up state. 
    385     osg::StateSet* stateset = lod->getOrCreateStateSet(); 
    386     { 
    387         // time taken to get from start to the end of cycle 
    388         float period = fabs((bb.zMax()-bb.zMin()) / velocity.z()); 
    389  
    390         // distance between start point and end of cyclce 
    391         osg::Vec3 position(bb.xMin(), bb.yMin(), bb.zMax()); 
    392         osg::Vec3 dv_i( bb.xMax()-bb.xMin(), 0.0f, 0.0f ); 
    393         osg::Vec3 dv_j( 0.0f, bb.yMax()-bb.yMin(), 0.0f ); 
    394         osg::Vec3 dv_k( velocity * period ); 
    395  
    396         // set up uniforms 
    397         osg::Uniform* position_Uniform = new osg::Uniform("position",position); 
    398         static osg::Uniform* dv_i_Uniform = new osg::Uniform("dv_i",dv_i); 
    399         static osg::Uniform* dv_j_Uniform = new osg::Uniform("dv_j",dv_j); 
    400         static osg::Uniform* dv_k_Uniform = new osg::Uniform("dv_k",dv_k); 
    401          
    402         static osg::Uniform* inversePeriodUniform = new osg::Uniform("inversePeriod",1.0f/period); 
    403         static osg::Uniform* startTime = new osg::Uniform("startTime",0.0f); 
    404  
    405  
    406          
    407         stateset->addUniform(position_Uniform); // vec3 
    408         stateset->addUniform(dv_i_Uniform); // vec3 could be float  
    409         stateset->addUniform(dv_j_Uniform); // vec3 could be float 
    410         stateset->addUniform(dv_k_Uniform); // vec3 
    411         stateset->addUniform(inversePeriodUniform); // float 
    412         stateset->addUniform(startTime); // float 
    413          
    414  
    415         // make it render after the normal transparent bin 
    416         stateset->setRenderBinDetails(11,"DepthSortedBin"); 
    417          
    418 #if 0 
    419         stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF); 
    420         stateset->setMode(GL_BLEND, osg::StateAttribute::ON); 
    421          
    422         static osg::Uniform* baseTextureSampler = new osg::Uniform("baseTexture",0); 
    423         stateset->addUniform(baseTextureSampler); 
    424          
    425         static osg::Texture2D* texture = new osg::Texture2D(createSpotLightImage(osg::Vec4(1.0f,1.0f,1.0f,1.0f),osg::Vec4(1.0f,1.0f,1.0f,0.0f),32,1.0)); 
    426         stateset->setTextureAttribute(0, texture); 
    427          
    428         stateset->addUniform(new osg::Uniform("particleColour", osg::Vec4(0.6,0.6,0.6,1.0))); 
    429         stateset->addUniform(new osg::Uniform("particleSize", 0.01f)); 
    430          
    431         osg::Uniform* previousModelViewUniform = new osg::Uniform("previousModelViewMatrix",osg::Matrix()); 
    432         stateset->addUniform(previousModelViewUniform); 
    433         lod->setCullCallback(new CullCallback(previousModelViewUniform)); 
    434 #endif 
    435     } 
    436  
    437  
    438404    return lod; 
    439405} 
     
    442408{ 
    443409     
    444     unsigned int numX = 80; 
    445     unsigned int numY = 80; 
     410    unsigned int numX = 100; 
     411    unsigned int numY = 100; 
    446412    unsigned int numCells = numX*numY; 
    447413    unsigned int numParticlesPerCell = numParticles/numCells; 
     
    481447    osg::StateSet* stateset = group->getOrCreateStateSet(); 
    482448 
     449    // time taken to get from start to the end of cycle 
     450    float period = fabs((bb.zMax()-bb.zMin()) / velocity.z()); 
     451 
     452    // distance between start point and end of cyclce 
     453    osg::Vec3 dv_i( (bb.xMax()-bb.xMin())/(float)(numX), 0.0f, 0.0f ); 
     454    osg::Vec3 dv_j( 0.0f, (bb.yMax()-bb.yMin())/(float)(numY), 0.0f ); 
     455    osg::Vec3 dv_k( velocity * period ); 
     456 
     457    // set up uniforms 
     458    // osg::Uniform* position_Uniform = new osg::Uniform("position",position); 
     459    osg::Uniform* dv_i_Uniform = new osg::Uniform("dv_i",dv_i); 
     460    osg::Uniform* dv_j_Uniform = new osg::Uniform("dv_j",dv_j); 
     461    osg::Uniform* dv_k_Uniform = new osg::Uniform("dv_k",dv_k); 
     462 
     463    osg::Uniform* inversePeriodUniform = new osg::Uniform("inversePeriod",1.0f/period); 
     464    osg::Uniform* startTime = new osg::Uniform("startTime",0.0f); 
     465 
     466    //stateset->addUniform(position_Uniform); // vec3 
     467    stateset->addUniform(dv_i_Uniform); // vec3 could be float  
     468    stateset->addUniform(dv_j_Uniform); // vec3 could be float 
     469    stateset->addUniform(dv_k_Uniform); // vec3 
     470    stateset->addUniform(inversePeriodUniform); // float 
     471    stateset->addUniform(startTime); // float 
     472 
    483473    stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF); 
    484474    stateset->setMode(GL_BLEND, osg::StateAttribute::ON); 
     
    491481 
    492482    stateset->addUniform(new osg::Uniform("particleColour", osg::Vec4(0.6,0.6,0.6,1.0))); 
    493     stateset->addUniform(new osg::Uniform("particleSize", 0.01f)); 
     483    stateset->addUniform(new osg::Uniform("particleSize", 0.02f)); 
    494484   
    495485    osg::Uniform* previousModelViewUniform = new osg::Uniform("previousModelViewMatrix",osg::Matrix()); 
     
    507497 
    508498    osg::BoundingBox bb(0.0, 0.0, 0.0, 100.0, 100.0, 100.0); 
    509     osg::Vec3 velocity(0.0,2.0,-5.0); 
    510     unsigned int numParticles = 10000000; 
     499    osg::Vec3 velocity(0.0,2.0,-8.0); 
     500    unsigned int numParticles = 50000000; 
    511501     
    512502    if (loadedModel) 
     
    541531    } 
    542532     
    543 #if 0 
    544     setUpGeometries(numParticles); 
    545     group->addChild(createRainEffect(bb, velocity)); 
    546 #else 
    547533    group->addChild(createCellRainEffect(bb, velocity, numParticles)); 
    548 #endif 
     534 
    549535    return group;     
    550536}