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

2007-11-05 Thread Chris Denham
Hi Mihai,
I rebuilt OSG with your modifications to ShadowMap, but unfortunately
I've still got problems with it.
1. The dummy texture seem to cause the scene to render blocky and dark.
2. If I set textureUnit=0 the shadows stop working completely.
I've posted screen some dumps at:
http://cmdenham.blogspot.com/
Cheers.
Chris.

On 02/11/2007, Chris Denham [EMAIL PROTECTED] wrote:
 Hi Mihai,
 Sorry I didn't see your postings earlier in the day, they could have saved
 me some time.
 Though I guess I learnt something on the way ;-)
 The reason I didn't see your messages was that gmail decided to relegate
 digest Vol5,Issues 23 to my spam folder, and I only realised things where
 missing when Issue4 arrived normally.  hmph... No.. it's not funny.

 Thanks for the valuable tips and code.
 Will your modification to ShadowMap go into the next osg release?

 Chris.



  Date: Fri, 02 Nov 2007 10:41:20 -0700
  From: Mihai Radu [EMAIL PROTECTED]
  Subject: Re: [osg-users] Scene renders black when replacing a
  ShadowedScene
  To: OpenSceneGraph Users osg-users@lists.openscenegraph.org
  Cc: [EMAIL PROTECTED]
  Message-ID: [EMAIL PROTECTED]
  Content-Type: text/plain; charset=iso-8859-1
 
  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:
 
 


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


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

2007-11-02 Thread Chris Denham
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 +
 From: Chris Denham [EMAIL PROTECTED]
 Subject: [osg-users] Scene renders black when replacing a
ShadowedScene
 To: osg-users@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@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


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

2007-11-02 Thread Mihai Radu
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 [EMAIL PROTECTED] 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 +
 From: Chris Denham [EMAIL PROTECTED]
 Subject: [osg-users] Scene renders black when replacing a
ShadowedScene
 To: osg-users@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@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
   
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 

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

2007-11-02 Thread Chris Denham
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 [EMAIL PROTECTED] 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 +
  From: Chris Denham [EMAIL PROTECTED]
  Subject: [osg-users] Scene renders black when replacing a
 ShadowedScene
  To: osg-users@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@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


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

2007-11-02 Thread Mihai Radu
The Matrox was probably not running the shader, and fixed-function will
work.

The fix you are looking for is in my earlier reply on this thread

Cheers
Mihai

Chris Denham 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 +
 From: Chris Denham [EMAIL PROTECTED]
 Subject: [osg-users] Scene renders black when replacing a
ShadowedScene
 To: osg-users@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@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


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

2007-11-02 Thread Chris Denham
Hi Mihai,
Sorry I didn't see your postings earlier in the day, they could have saved 
me some time.
Though I guess I learnt something on the way ;-)
The reason I didn't see your messages was that gmail decided to relegate 
digest Vol5,Issues 23 to my spam folder, and I only realised things where 
missing when Issue4 arrived normally.  hmph... No.. it's not funny.

Thanks for the valuable tips and code.
Will your modification to ShadowMap go into the next osg release?

Chris.



 Date: Fri, 02 Nov 2007 10:41:20 -0700
 From: Mihai Radu [EMAIL PROTECTED]
 Subject: Re: [osg-users] Scene renders black when replacing a
 ShadowedScene
 To: OpenSceneGraph Users osg-users@lists.openscenegraph.org
 Cc: [EMAIL PROTECTED]
 Message-ID: [EMAIL PROTECTED]
 Content-Type: text/plain; charset=iso-8859-1

 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:

 

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


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

2007-11-01 Thread Mihai Radu
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


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

2007-11-01 Thread Adrian Egli
:-) 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 [EMAIL PROTECTED]:

 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




-- 

Adrian Egli
___
osg-users mailing list
osg-users@lists.openscenegraph.org

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

2007-11-01 Thread Mihai Radu
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@cm-labs.comAdrian 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 [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]:

 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;
 
  

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

2007-11-01 Thread Adrian Egli
Thanks Mihai, can you also change the PSSM implementation and update the
code, so robert has only one review to do !
if i will submiss the pssm stuff, he has to review two equal changes.
thanks.

may you can also have a look at PSSM, there are other mails on this topic.
the GLSL shader doesn't work very nice for every
env. may you can test it (The smooth stuff in the PSSM doesn't work nice,
for my ATI card is nice but on others, i don't know)

/Adegli

2007/11/1, Mihai Radu [EMAIL PROTECTED]:

 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@cm-labs.comAdrian 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 [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]:
 
  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));