[osg-users] Scene renders black when replacing a ShadowedScene
Mihai Radu
radu at cm-labs.com
Fri Nov 2 10:41:20 PDT 2007
Hi Chris,
Please check the thread for fixes.
I'm attaching, again, the fixed version of ShadowMap.cpp
Cheers
Mihai
Chris Denham wrote:
> After some serious digging and tweaking inside osgShadow::ShadowMap I
> have come up with a partial workaround for this problem. The problem
> seems to boil down to issues around the pushing and popping of
> statsets containing instance of:
>
> new osg::Uniform("osgShadow_shadowTexture",(int)_shadowTextureUnit);
>
> ShadowMap uses a default value of 1 for _shadowTextureUnit
>
> It seems that for geometries that have no texture assigned, I need to
> set a value of 0 to _shadowTextureUnit, otherwise I get problems (as
> least I do on my Radeon-X300)
>
> So... my partial workaround is to setup my scene like:
> osgShadow::ShadowMap* shadowMap = new osgShadow::ShadowMap();
> shadowMap->setTextureUnit(0);
> shadowedScene->setShadowTechnique(shadowMap);
>
> For scenes that do not have textures, this is a perfect workround for
> me, but for scenes containing textured AND untextured objects,
> unfortunately the workround causes the textures to be lost.
>
> I wonder if the PROPER solution to the problem requires some kind of
> stateset override for nodes that is a function of whether the node has
> textures?
>
> Intersectingly the problem is a little bit bigger that I thought, as
> untextured objects in shadowed scenes have strange artifacts on their
> surfaces unless I setTextureUnit to zero (even the first time the
> scene is assigned)
>
> Is this info useful to anyone that actually knows what they are doing?
> I'm begining to feel a bit out of my z-depth. ;-)
>
> Chris.
>
>
> On 02/11/2007, Chris Denham <c.m.denham at gmail.com> wrote:
>
>> Hmm... think this might me a video card/driver specific problem.
>> I just tried this test on my colleague's PC that has a matrox video
>> card and seemed to work ok.
>> Oh rats.... does that mean it not so easy/impossible to fix the problem? :-(
>> Chris.
>>
>>
>>
>>> Date: Thu, 1 Nov 2007 17:56:06 +0000
>>> From: "Chris Denham" <c.m.denham at gmail.com>
>>> Subject: [osg-users] Scene renders black when replacing a
>>> ShadowedScene
>>> To: osg-users at lists.openscenegraph.org
>>>
>>> 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 at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ShadowMap.cpp
Url: http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20071102/a39de9ff/attachment.pot
More information about the osg-users
mailing list