From Mihair Radu, "Most of the additions are small utility methods:
- set the resolution of the shadow map; it calls dirty() to re-initialize at next update - keep a list of Shader objects to use instead of the default ones, if the list is empty, the default shaders are used - explicitly create the Uniform variables, so that subsequent additions that require more Uniforms can put them in a central place - set a Light or LightSource to use explicitly for shadow casting, allows multiple lights in the scene, with one casting shadows There are two additions that do not ( yet ) function correctly, but in the present usage they do not interfere with the regular usage of the techique: - support for using spotlights, it's using Light.spotCutoff to determine if it's a spot-light and not point-light, there is an error in the setup of either the shadow camera or the texgen, most likely due to the direction of the spotlight, since the position is being used just like in point or directional lights. - creation of a debugHUD the hud is created properly, ( the example included shows it ), but it displays only white, there has been some discussion of displaying the shadow map, but I could not find it, the addition of a simple fragment shader with the appropriate color transform should get this going."
This commit is contained in:
@@ -665,7 +665,11 @@ int main(int argc, char** argv)
|
||||
{
|
||||
osg::ref_ptr<osgShadow::ShadowMap> sm = new osgShadow::ShadowMap;
|
||||
shadowedScene->setShadowTechnique(sm.get());
|
||||
}
|
||||
|
||||
int mapres = 1024;
|
||||
while (arguments.read("--mapres", mapres))
|
||||
sm->setTextureSize(osg::Vec2s(mapres,mapres));
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Node> model = osgDB::readNodeFiles(arguments);
|
||||
if (model.valid())
|
||||
@@ -715,6 +719,22 @@ int main(int argc, char** argv)
|
||||
|
||||
osg::ref_ptr<osg::LightSource> ls = new osg::LightSource;
|
||||
ls->getLight()->setPosition(lightpos);
|
||||
|
||||
bool spotlight = false;
|
||||
if (arguments.read("--spotLight"))
|
||||
{
|
||||
spotlight = true;
|
||||
|
||||
osg::Vec3 center = bb.center();
|
||||
osg::Vec3 lightdir = center - osg::Vec3(lightpos.x(), lightpos.y(), lightpos.z());
|
||||
lightdir.normalize();
|
||||
ls->getLight()->setDirection(lightdir);
|
||||
ls->getLight()->setSpotCutoff(30.0f);
|
||||
|
||||
//set the LightSource, only for checking, there is only 1 light in the scene
|
||||
dynamic_cast<osgShadow::ShadowMap*>(shadowedScene->getShadowTechnique())->setLight(ls.get());
|
||||
}
|
||||
|
||||
if ( arguments.read("--coloured-light"))
|
||||
{
|
||||
ls->getLight()->setAmbient(osg::Vec4(1.0,0.0,0.0,1.0));
|
||||
@@ -730,10 +750,29 @@ int main(int argc, char** argv)
|
||||
shadowedScene->addChild(ls.get());
|
||||
|
||||
viewer.setSceneData(shadowedScene.get());
|
||||
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize();
|
||||
|
||||
// it is done after viewer.realize() so that the windows are already initialized
|
||||
if ( arguments.read("--debugHUD"))
|
||||
{
|
||||
osgViewer::Viewer::Windows windows;
|
||||
viewer.getWindows(windows);
|
||||
|
||||
if (windows.empty()) return 1;
|
||||
|
||||
osgShadow::ShadowMap* sm = dynamic_cast<osgShadow::ShadowMap*>(shadowedScene->getShadowTechnique());
|
||||
osg::ref_ptr<osg::Camera> hudCamera = sm->makeDebugHUD();
|
||||
|
||||
// set up cameras to rendering on the first window available.
|
||||
hudCamera->setGraphicsContext(windows[0]);
|
||||
hudCamera->setViewport(0,0,windows[0]->getTraits()->width, windows[0]->getTraits()->height);
|
||||
|
||||
viewer.addSlave(hudCamera.get(), false);
|
||||
}
|
||||
|
||||
|
||||
// osgDB::writeNodeFile(*group,"test.osg");
|
||||
|
||||
while (!viewer.done())
|
||||
@@ -743,7 +782,7 @@ int main(int argc, char** argv)
|
||||
float t = viewer.getFrameStamp()->getSimulationTime();
|
||||
if (postionalLight)
|
||||
{
|
||||
lightpos.set(bb.center().x()+sinf(t)*bb.radius(), bb.center().y() + cosf(t)*bb.radius(), bb.zMax() + bb.radius() ,1.0f);
|
||||
lightpos.set(bb.center().x()+sinf(t)*bb.radius(), bb.center().y() + cosf(t)*bb.radius(), bb.zMax() + bb.radius()*2.0f ,1.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -752,6 +791,9 @@ int main(int argc, char** argv)
|
||||
ls->getLight()->setPosition(lightpos);
|
||||
|
||||
osg::Vec3f lightDir(-lightpos.x(),-lightpos.y(),-lightpos.z());
|
||||
if(spotlight)
|
||||
lightDir = osg::Vec3(bb.center().x()+sinf(t)*bb.radius()/2.0, bb.center().y() + cosf(t)*bb.radius()/2.0, bb.center().z())
|
||||
- osg::Vec3(lightpos.x(), lightpos.y(), lightpos.z()) ;
|
||||
lightDir.normalize();
|
||||
ls->getLight()->setDirection(lightDir);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user