From 31cb490c75cd3a8bf0071d914d9b00a7dfa33d5a Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 7 Aug 2011 15:54:21 +0000 Subject: [PATCH] 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 --- examples/osgshadow/osgshadow.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/examples/osgshadow/osgshadow.cpp b/examples/osgshadow/osgshadow.cpp index ffe79fc8d..e62dd6c8b 100644 --- a/examples/osgshadow/osgshadow.cpp +++ b/examples/osgshadow/osgshadow.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -650,12 +651,17 @@ int main(int argc, char** argv) while (arguments.read("--fov",fov)) {} osg::Vec4 lightpos(0.0,0.0,1,0.0); + bool spotlight = false; while (arguments.read("--positionalLight")) { lightpos.set(0.5,0.5,1.5,1.0); } while (arguments.read("--directionalLight")) { lightpos.set(0.0,0.0,1,0.0); } + while (arguments.read("--spotLight")) { lightpos.set(0.5,0.5,1.5,1.0); spotlight = true; } - while ( arguments.read("--light-pos", lightpos.x(), lightpos.y(), lightpos.z(), lightpos.w())) {} - while ( arguments.read("--light-pos", lightpos.x(), lightpos.y(), lightpos.z())) { lightpos.w()=1.0; } - while ( arguments.read("--light-dir", lightpos.x(), lightpos.y(), lightpos.z())) { lightpos.w()=0.0; } + bool keepLightPos = false; + osg::Vec3 spotLookat(0.0,0.0,0.0); + while ( arguments.read("--light-pos", lightpos.x(), lightpos.y(), lightpos.z(), lightpos.w())) { keepLightPos = true; } + while ( arguments.read("--light-pos", lightpos.x(), lightpos.y(), lightpos.z())) { lightpos.w()=1.0; keepLightPos = true; } + while ( arguments.read("--light-dir", lightpos.x(), lightpos.y(), lightpos.z())) { lightpos.w()=0.0; keepLightPos = true; } + while ( arguments.read("--spot-lookat", spotLookat.x(), spotLookat.y(), spotLookat.z())) { } while (arguments.read("--castsShadowMask", CastsShadowTraversalMask )); @@ -805,6 +811,11 @@ int main(int argc, char** argv) else // if( arguments.read( "--DrawBounds" ) ) // default msm = new osgShadow::MinimalDrawBoundsShadowMap; } + else if( arguments.read("--vdsm") ) + { + osg::ref_ptr vdsm = new osgShadow::ViewDependentShadowMap; + shadowedScene->setShadowTechnique(vdsm.get()); + } else /* if (arguments.read("--sm")) */ { osg::ref_ptr sm = new osgShadow::ShadowMap; @@ -860,7 +871,7 @@ int main(int argc, char** argv) model->accept(cbbv); osg::BoundingBox bb = cbbv.getBoundingBox(); - if (lightpos.w()==1.0) + if (lightpos.w()==1.0 && !keepLightPos) { lightpos.x() = bb.xMin()+(bb.xMax()-bb.xMin())*lightpos.x(); lightpos.y() = bb.yMin()+(bb.yMax()-bb.yMin())*lightpos.y(); @@ -889,12 +900,9 @@ int main(int argc, char** argv) osg::ref_ptr ls = new osg::LightSource; ls->getLight()->setPosition(lightpos); - bool spotlight = false; - if (arguments.read("--spotLight")) + if (spotlight) { - spotlight = true; - - osg::Vec3 center = bb.center(); + osg::Vec3 center = spotLookat; osg::Vec3 lightdir = center - osg::Vec3(lightpos.x(), lightpos.y(), lightpos.z()); lightdir.normalize(); ls->getLight()->setDirection(lightdir);