Just to make sure I understand the issue: from what you are describing, the problem is that non-textured scene is drawn is black.
This is a result of the shader in use, if you are using the one for textured objects, it will do a texture access on unit 0, and since there is no bound texture the result is vec4(0,0,0,1), that when multiplied to any other color value gives black. This is a result of some polish still needed for ShadowMap, and some of the options are: - if using non-textured scene, make use of the relevant shader ( by setting _shadowTextureUnit to 0, and then init() ) - set a custom shader and use per-object uniform flag to control color application ( this is what I've done for work ) like this: > if (!s_TexturedObject) > { > color.rgb *= gl_Color.rgb; > color.a = gl_Color.a; > } > else > { > texColor = texture2D(osgShadow_baseTexture, gl_TexCoord[0].st); > color *= texColor; > } - the most elegant solution : create a 'fake' texture with (1,1,1,1) and set it to the root of the scene, so that it will texture any object that was not textured, but it's superseded by any more localized textures, this way one shader will work for all objects. This is borrowed from ParallelSplitShadowMap, and I hope I'll have time to integrate the same idea in ShadowMap. Cheers Mihai Chris Denham wrote: > I'm getting a problem when assigning a new shadowed scene to the viewer. > What seems to happen is that once the first scene has been rendered, > the assignment of a new shadowed scene results in a everything in the > scene being drawn black. Also odd is the fact that there doesn't seem > to be a problem when a texture is assigned to objects being drawn. > > I have created a minimal example that exhibits the problem, and pasted > it below. > Any ideas what's going wrong? Can anyone reproduce the effect? > > [I'm using osg2.2 on windowsXP with Radeon X300 with latest drivers.] > > ---------------------------------------------------------------------------------------------------- > #include <osg/ShapeDrawable> > #include <osg/Geode> > #include <osgGA/TrackballManipulator> > #include <osgShadow/ShadowedScene> > #include <osgShadow/ShadowMap> > #include <osgDB/ReadFile> > #include <osgViewer/Viewer> > > const int ReceivesShadowTraversalMask = 0x1; > const int CastsShadowTraversalMask = 0x2; > > osg::Node* createShadowedScene(bool withTexture) > { > osgShadow::ShadowedScene* shadowedScene = new osgShadow::ShadowedScene; > > shadowedScene->setReceivesShadowTraversalMask(ReceivesShadowTraversalMask); > shadowedScene->setCastsShadowTraversalMask(CastsShadowTraversalMask); > shadowedScene->setShadowTechnique(new osgShadow::ShadowMap()); > > osg::LightSource* lightSource = new osg::LightSource; > lightSource->getLight()->setPosition(osg::Vec4(0, 0.2, 1, 0)); > > osg::ShapeDrawable * shape = new osg::ShapeDrawable(new > osg::Sphere(osg::Vec3(0.0f, 0.0f, 0.0f), 200.0)); > shape->setColor(osg::Vec4(0.8f, 0.8f, 0.8f, 1.0f)); > osg::Geode* geode = new osg::Geode(); > geode->addDrawable(shape); > > if (withTexture) > { > geode->getOrCreateStateSet()->setTextureAttributeAndModes( 0, > new osg::Texture2D(osgDB::readImageFile("Images/lz.rgb")), > osg::StateAttribute::ON); > } > > shadowedScene->addChild(geode); > shadowedScene->addChild(lightSource); > > return shadowedScene; > } > > int main(int argc, char** argv) > { > bool withTexture = false; > > osgViewer::Viewer viewer; > viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); > viewer.setCameraManipulator(new osgGA::TrackballManipulator()); > viewer.realize(); > > viewer.setSceneData(createShadowedScene(withTexture)); > #if 1 > // Drawing the frame then assigning a new shadowed scene > // seems to result in scene being rendered black. > // Although, seems ok when texture is assigned to the object. > viewer.frame(); > viewer.setSceneData(createShadowedScene(withTexture)); > #endif > > viewer.run(); > > return 0; > } > > #endif > _______________________________________________ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org