Show
Ignore:
Timestamp:
08/07/11 17:54:21 (3 years ago)
Author:
robert
Message:

From Jean-Sebestien Guay and Robert Osfield, mixture of two sets of change - one from JS that adds more controls for specifying positional and spot lights, and from RO adding support for the new ViewDepedentShadowMap?

Files:
1 modified

Legend:

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

    r12529 r12743  
    4444#include <osgShadow/LightSpacePerspectiveShadowMap> 
    4545#include <osgShadow/StandardShadowMap> 
     46#include <osgShadow/ViewDependentShadowMap> 
    4647 
    4748#include <osgDB/ReadFile> 
     
    651652 
    652653    osg::Vec4 lightpos(0.0,0.0,1,0.0); 
     654    bool spotlight = false; 
    653655    while (arguments.read("--positionalLight")) { lightpos.set(0.5,0.5,1.5,1.0); } 
    654656    while (arguments.read("--directionalLight")) { lightpos.set(0.0,0.0,1,0.0); } 
    655  
    656     while ( arguments.read("--light-pos", lightpos.x(), lightpos.y(), lightpos.z(), lightpos.w())) {} 
    657     while ( arguments.read("--light-pos", lightpos.x(), lightpos.y(), lightpos.z())) { lightpos.w()=1.0; } 
    658     while ( arguments.read("--light-dir", lightpos.x(), lightpos.y(), lightpos.z())) { lightpos.w()=0.0; } 
     657    while (arguments.read("--spotLight")) { lightpos.set(0.5,0.5,1.5,1.0); spotlight = true; } 
     658 
     659    bool keepLightPos = false; 
     660    osg::Vec3 spotLookat(0.0,0.0,0.0); 
     661    while ( arguments.read("--light-pos", lightpos.x(), lightpos.y(), lightpos.z(), lightpos.w())) { keepLightPos = true; } 
     662    while ( arguments.read("--light-pos", lightpos.x(), lightpos.y(), lightpos.z())) { lightpos.w()=1.0; keepLightPos = true; } 
     663    while ( arguments.read("--light-dir", lightpos.x(), lightpos.y(), lightpos.z())) { lightpos.w()=0.0; keepLightPos = true; } 
     664    while ( arguments.read("--spot-lookat", spotLookat.x(), spotLookat.y(), spotLookat.z())) { } 
    659665 
    660666 
     
    806812            msm = new osgShadow::MinimalDrawBoundsShadowMap; 
    807813    } 
     814    else if( arguments.read("--vdsm") ) 
     815    { 
     816        osg::ref_ptr<osgShadow::ViewDependentShadowMap> vdsm = new osgShadow::ViewDependentShadowMap; 
     817        shadowedScene->setShadowTechnique(vdsm.get()); 
     818    } 
    808819    else /* if (arguments.read("--sm")) */ 
    809820    { 
     
    861872    osg::BoundingBox bb = cbbv.getBoundingBox(); 
    862873 
    863     if (lightpos.w()==1.0) 
     874    if (lightpos.w()==1.0 && !keepLightPos) 
    864875    { 
    865876        lightpos.x() = bb.xMin()+(bb.xMax()-bb.xMin())*lightpos.x(); 
     
    890901    ls->getLight()->setPosition(lightpos); 
    891902 
    892     bool spotlight = false; 
    893     if (arguments.read("--spotLight")) 
    894     { 
    895         spotlight = true; 
    896  
    897         osg::Vec3 center = bb.center(); 
     903    if (spotlight) 
     904    { 
     905        osg::Vec3 center = spotLookat; 
    898906        osg::Vec3 lightdir = center - osg::Vec3(lightpos.x(), lightpos.y(), lightpos.z()); 
    899907        lightdir.normalize();