[osg-users] Scene renders black when replacing a ShadowedScene

Mihai Radu radu at cm-labs.com
Thu Nov 1 15:33:54 PDT 2007


Hi Chris, Adrian

Here's an updated version of ShadowMap[.cpp] that includes the 'fake'
texture.

Now any model will show up properly, textured or nor.
To see run [the dumptruck is not textured] :
osgshadow dumptruck.osg

Adrian, in your code (PSSM) you assign black(0,0,0,0) as the color for
the 'fake', this gives the same result as a bad texture access, it works
perfectly if you set it to white(1,1,1,1).

This is a nice loose end to take care of, I can now do without an 'if'
in GLSL, and since it's a pretty costly operation, every little bit helps :)
I will submit this to Robert for svn.

Cheers
Mihai
<cid:part1.08090808.06060803 at cm-labs.com>Adrian Egli wrote:
> :-) Yes a fake texture can help GLSL shader based issue. Feel free to
> migrate the other shadow
> technics.  And if you like working with PSSM feel free to fix the
> little issues we still have. i don't
> get the time to work on PSSM for next generation.
>
> /adegli
>
> 2007/11/1, Mihai Radu <radu at cm-labs.com <mailto:radu at cm-labs.com>>:
>
>     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 at lists.openscenegraph.org
>     <mailto:osg-users at lists.openscenegraph.org>
>     >
>     http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>     >
>     _______________________________________________
>     osg-users mailing list
>     osg-users at lists.openscenegraph.org
>     <mailto:osg-users at lists.openscenegraph.org>
>     http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>     <http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org>
>
>
>
>
> -- 
> ********************************************
> Adrian Egli
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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/20071101/2c4b16c0/attachment.asc 


More information about the osg-users mailing list