Show
Ignore:
Timestamp:
11/30/06 11:29:03 (8 years ago)
Author:
robert
Message:

Added movement of the light source to test performance of update the shadow volumes

Files:
1 modified

Legend:

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

    r5750 r5779  
    133133    } 
    134134 
     135    bool postionalLight = false; 
     136    while (arguments.read("--positionalLight")) postionalLight = true; 
     137    while (arguments.read("--directionalLight")) postionalLight = false; 
     138 
     139    bool addOccluderToScene = false; 
     140    while (arguments.read("addOccluderToScene")) addOccluderToScene = true; 
     141 
     142    bool updateLightPosition = true; 
     143 
    135144    // any option left unread are converted into errors to write out later. 
    136145    arguments.reportRemainingOptionsAsUnrecognized(); 
     
    150159        return 1; 
    151160    } 
    152      
    153      
    154     osg::ref_ptr<osg::Geode> geode = new osg::Geode; 
    155  
     161 
     162    // get the bounds of the model.     
     163    ComputeBoundingBoxVisitor cbbv; 
     164    model->accept(cbbv); 
     165    osg::BoundingBox bb = cbbv.getBoundingBox(); 
     166     
     167    osg::ref_ptr<osg::Group> group = new osg::Group; 
     168    group->addChild(model.get()); 
     169 
     170    // set up the occluder 
    156171    osg::ref_ptr<osgShadow::OccluderGeometry> occluder = new osgShadow::OccluderGeometry; 
    157172    occluder->computeOccluderGeometry(model.get()); 
    158  
    159     ComputeBoundingBoxVisitor cbbv; 
    160     model->accept(cbbv); 
    161173    cbbv.getPolytope(occluder->getBoundingPolytope(),0.001); 
    162     osg::BoundingBox bb = cbbv.getBoundingBox(); 
    163  
    164     //geode->addDrawable(occluder.get()); 
     174 
     175    if (addOccluderToScene) 
     176    { 
     177        osg::ref_ptr<osg::Geode> geode = new osg::Geode; 
     178        geode->addDrawable(occluder.get()); 
     179        group->addChild(geode.get()); 
     180    } 
    165181     
    166182    osg::ref_ptr<osgShadow::ShadowVolumeGeometry> shadowVolume = new osgShadow::ShadowVolumeGeometry; 
    167183 
    168 #if 1 
    169 //    occluder->comptueShadowVolumeGeometry(osg::Vec4(bb.xMin()+ bb.radius(), bb.yMin()+ bb.radius(), bb.zMax() + bb.radius()  ,1.0f), *shadowVolume); 
    170     occluder->comptueShadowVolumeGeometry(osg::Vec4(bb.center().x(), bb.center().y(), bb.zMax() + bb.radius()  ,1.0f), *shadowVolume); 
    171 #else 
    172     occluder->comptueShadowVolumeGeometry(osg::Vec4(0.5f,.25f,0.2f,0.0f), *shadowVolume); 
    173 #endif 
    174     geode->addDrawable(shadowVolume.get()); 
    175  
    176  
    177     osg::ref_ptr<osg::Group> group = new osg::Group; 
    178     group->addChild(model.get()); 
    179     group->addChild(geode.get()); 
     184    shadowVolume->setUseDisplayList(!updateLightPosition); 
     185 
     186    osg::Vec4 lightpos; 
     187     
     188    if (postionalLight) 
     189    { 
     190        lightpos.set(bb.center().x(), bb.center().y(), bb.zMax() + bb.radius()  ,1.0f); 
     191    } 
     192    else 
     193    { 
     194        lightpos.set(0.5f,0.25f,-0.8f,0.0f); 
     195    } 
     196 
     197    { 
     198        osg::ref_ptr<osg::Geode> geode = new osg::Geode; 
     199        occluder->comptueShadowVolumeGeometry(lightpos, *shadowVolume); 
     200        geode->addDrawable(shadowVolume.get()); 
     201        group->addChild(geode.get()); 
     202    } 
     203 
    180204 
    181205 
     
    189213      // wait for all cull and draw threads to complete. 
    190214      viewer.sync(); 
     215 
     216        if (updateLightPosition) 
     217        { 
     218            float t = viewer.getFrameStamp()->getReferenceTime(); 
     219            if (postionalLight) 
     220            { 
     221                lightpos.set(bb.center().x()+sinf(t)*bb.radius(), bb.center().y() + cosf(t)*bb.radius(), bb.zMax() + bb.radius()  ,1.0f); 
     222            } 
     223            else 
     224            { 
     225                lightpos.set(sinf(t),cosf(t),-0.8f,0.0f); 
     226            } 
     227            occluder->comptueShadowVolumeGeometry(lightpos, *shadowVolume); 
     228       } 
    191229 
    192230      // update the scene by traversing it with the the update visitor which will