Added option to use osgShadow::ShadowMap technique
This commit is contained in:
parent
37526e3bea
commit
bc0fb12d0a
@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs
|
||||
CXXFILES =\
|
||||
osgdepthshadow.cpp\
|
||||
|
||||
LIBS += -losgViewer -losgText -losgGA -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
||||
LIBS += -losgViewer -losgShadow -losgText -losgGA -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
||||
|
||||
INSTFILES = \
|
||||
$(CXXFILES)\
|
||||
|
@ -21,6 +21,9 @@
|
||||
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
#include <osgShadow/ShadowedScene>
|
||||
#include <osgShadow/ShadowMap>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace osg;
|
||||
@ -436,33 +439,65 @@ int main(int argc, char** argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
ref_ptr<MatrixTransform> scene = new MatrixTransform;
|
||||
scene->setMatrix(osg::Matrix::rotate(osg::DegreesToRadians(125.0),1.0,0.0,0.0));
|
||||
|
||||
ref_ptr<Group> shadowed_scene = _create_scene();
|
||||
if (!shadowed_scene.valid()) return 1;
|
||||
|
||||
ref_ptr<MatrixTransform> light_transform = _create_lights();
|
||||
if (!light_transform.valid()) return 1;
|
||||
|
||||
ref_ptr<Group> shadowedScene;
|
||||
|
||||
|
||||
if (withBaseTexture)
|
||||
if (arguments.read("--sm"))
|
||||
{
|
||||
shadowed_scene->getOrCreateStateSet()->setTextureAttributeAndModes( 0, new osg::Texture2D(osgDB::readImageFile("Images/lz.rgb")), osg::StateAttribute::ON);
|
||||
shadowedScene = createShadowedScene(shadowed_scene.get(),light_transform.get(),1);
|
||||
osgShadow::ShadowMap* sm = new osgShadow::ShadowMap;
|
||||
sm->setTextureUnit( withBaseTexture ? 1 : 0 );
|
||||
|
||||
osg::ref_ptr<osgShadow::ShadowedScene> shadowedScene = new osgShadow::ShadowedScene(sm);
|
||||
|
||||
|
||||
ref_ptr<Group> created_scene = _create_scene();
|
||||
if (!created_scene.valid()) return 1;
|
||||
|
||||
shadowedScene->addChild(_create_scene().get());
|
||||
|
||||
|
||||
ref_ptr<MatrixTransform> scene = new MatrixTransform;
|
||||
scene->setMatrix(osg::Matrix::rotate(osg::DegreesToRadians(125.0),1.0,0.0,0.0));
|
||||
|
||||
scene->addChild(_create_lights().get());
|
||||
scene->addChild(shadowedScene.get());
|
||||
|
||||
if (withBaseTexture)
|
||||
{
|
||||
scene->getOrCreateStateSet()->setTextureAttributeAndModes( 0, new osg::Texture2D(osgDB::readImageFile("Images/lz.rgb")), osg::StateAttribute::ON);
|
||||
}
|
||||
|
||||
viewer.setSceneData(scene.get());
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
shadowedScene = createShadowedScene(shadowed_scene.get(),light_transform.get(),0);
|
||||
ref_ptr<MatrixTransform> scene = new MatrixTransform;
|
||||
scene->setMatrix(osg::Matrix::rotate(osg::DegreesToRadians(125.0),1.0,0.0,0.0));
|
||||
|
||||
ref_ptr<Group> created_scene = _create_scene();
|
||||
if (!created_scene.valid()) return 1;
|
||||
|
||||
ref_ptr<MatrixTransform> light_transform = _create_lights();
|
||||
if (!light_transform.valid()) return 1;
|
||||
|
||||
ref_ptr<Group> shadowedScene;
|
||||
|
||||
if (withBaseTexture)
|
||||
{
|
||||
scene->getOrCreateStateSet()->setTextureAttributeAndModes( 0, new osg::Texture2D(osgDB::readImageFile("Images/lz.rgb")), osg::StateAttribute::ON);
|
||||
shadowedScene = createShadowedScene(created_scene.get(),light_transform.get(),1);
|
||||
}
|
||||
else
|
||||
{
|
||||
shadowedScene = createShadowedScene(created_scene.get(),light_transform.get(),0);
|
||||
}
|
||||
|
||||
scene->addChild(shadowedScene.get());
|
||||
|
||||
viewer.setSceneData(scene.get());
|
||||
}
|
||||
|
||||
// viewer.setUpViewOnSingleScreen();
|
||||
|
||||
scene->addChild(shadowedScene.get());
|
||||
|
||||
viewer.setSceneData(scene.get());
|
||||
|
||||
return viewer.run();
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <osgShadow/ShadowedScene>
|
||||
#include <osgShadow/ShadowVolume>
|
||||
#include <osgShadow/ShadowTexture>
|
||||
#include <osgShadow/ShadowMap>
|
||||
|
||||
// include the call which creates the shadowed subgraph.
|
||||
#include "CreateShadowedScene.h"
|
||||
@ -204,6 +205,30 @@ osg::Node* createModel(osg::ArgumentParser& arguments)
|
||||
|
||||
return shadowedScene;
|
||||
|
||||
}
|
||||
else if (arguments.read("--sm"))
|
||||
{
|
||||
|
||||
osgShadow::ShadowedScene* shadowedScene = new osgShadow::ShadowedScene;
|
||||
|
||||
osg::ref_ptr<osgShadow::ShadowMap> shadowMap = new osgShadow::ShadowMap;
|
||||
shadowedScene->setShadowTechnique(shadowMap.get());
|
||||
|
||||
osg::ref_ptr<osg::LightSource> ls = new osg::LightSource;
|
||||
ls->getLight()->setPosition(osg::Vec4(lightPosition,1.0));
|
||||
|
||||
shadowedScene->setRecievesShadowTraversalMask(0x1);
|
||||
shadowed->setNodeMask(shadowedScene->getRecievesShadowTraversalMask());
|
||||
|
||||
shadowedScene->setCastsShadowTraversalMask(0x2);
|
||||
shadower->setNodeMask(shadowedScene->getCastsShadowTraversalMask());
|
||||
|
||||
shadowedScene->addChild(shadower);
|
||||
shadowedScene->addChild(shadowed);
|
||||
shadowedScene->addChild(ls.get());
|
||||
|
||||
return shadowedScene;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user