Discussion:
[osg-users] Shadow in GraphicsWindowEmbedded
Cong Ye
2018-08-15 06:55:31 UTC
Permalink
Hi,

I am recently encountered an interesting problem. I am trying to add shadow to a scene embedded in osgViewer::GraphicsWindowEmbedded. Most of shadow algorithms are working fine if i use osg::Viewer only. However, if I use them in GraphicsWindowEmbedded, nothing will be displayed.

The setting code would be:
_mGraphicsWindow = new osgViewer::GraphicsWindowEmbedded( this->x(), this->y(),
this->width(), this->height() );

osg::Camera* camera = new osg::Camera;
camera->setViewport( 0, 0, this->width(), this->height() );
camera->setClearColor( osg::Vec4( 0.9f, 0.9f, 1.f, 1.f ) );
float aspectRatio = static_cast<float>( this->width()) / static_cast<float>( this->height() );
camera->setProjectionMatrixAsPerspective( 30.f, aspectRatio, 1.f, 1000.f );
camera->setGraphicsContext( _mGraphicsWindow );

If i override the shadow and assign the graphiccontext to the shadow camera, the scene can be rendered, but all in black.

Thank you for any help!

Cheers,
Cong

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74522#74522
Robert Osfield
2018-08-15 07:46:38 UTC
Permalink
HI Cong,

In your code snippet you don't set Camera::setRead.WriteBuffer()
settings. For a double buffer this will need to be GL_BACK.

Robert
Post by Cong Ye
Hi,
I am recently encountered an interesting problem. I am trying to add shadow to a scene embedded in osgViewer::GraphicsWindowEmbedded. Most of shadow algorithms are working fine if i use osg::Viewer only. However, if I use them in GraphicsWindowEmbedded, nothing will be displayed.
_mGraphicsWindow = new osgViewer::GraphicsWindowEmbedded( this->x(), this->y(),
this->width(), this->height() );
osg::Camera* camera = new osg::Camera;
camera->setViewport( 0, 0, this->width(), this->height() );
camera->setClearColor( osg::Vec4( 0.9f, 0.9f, 1.f, 1.f ) );
float aspectRatio = static_cast<float>( this->width()) / static_cast<float>( this->height() );
camera->setProjectionMatrixAsPerspective( 30.f, aspectRatio, 1.f, 1000.f );
camera->setGraphicsContext( _mGraphicsWindow );
If i override the shadow and assign the graphiccontext to the shadow camera, the scene can be rendered, but all in black.
Thank you for any help!
Cheers,
Cong
------------------
http://forum.openscenegraph.org/viewtopic.php?p=74522#74522
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Cong Ye
2018-08-16 05:33:04 UTC
Permalink
Hi Robert

Thanks very much for the quick reply.

I agree this is a problem. But i don't think it causes the shadow not displays in embedded window problem. Could I ask where can I specific the graphicscontext to shadow camera? That may be the problem? Didn't find any methods in shadow technology to do that.

Thanks again
Cong

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74540#74540
Robert Osfield
2018-08-16 07:11:05 UTC
Permalink
Hi Cong,
Post by Cong Ye
I agree this is a problem. But i don't think it causes the shadow not displays in embedded window problem. Could I ask where can I specific the graphicscontext to shadow camera? That may be the problem? Didn't find any methods in shadow technology to do that.
It all depends on how you are doing shadowing.

If you are using the osgShadow NodeKist then it'll create FBO's for
the shadow map generation and won't need a separate graphics context,
just put a ShadowedScene node into your scene graph as per the
osgshadow example and you should be OK.

If you are rolling your own shadows then you'll need to explain more
about your setup for us to give you direction.

Robert.
Cong Ye
2018-08-16 07:52:51 UTC
Permalink
Post by Robert Osfield
Hi Cong,
Post by Cong Ye
I agree this is a problem. But i don't think it causes the shadow not displays in embedded window problem. Could I ask where can I specific the graphicscontext to shadow camera? That may be the problem? Didn't find any methods in shadow technology to do that.
It all depends on how you are doing shadowing.
If you are using the osgShadow NodeKist then it'll create FBO's for
the shadow map generation and won't need a separate graphics context,
just put a ShadowedScene node into your scene graph as per the
osgshadow example and you should be OK.
If you are rolling your own shadows then you'll need to explain more
about your setup for us to give you direction.
Robert.
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
------------------
Post generated by Mail2Forum
I am currently using the osgShadow NodeKist. It only works when I use osgViewer as default graphics context. Now the case is, I have to assign a third party graphics context to the main camera as we are using a Qt Gui for buttons etc. After I assign osgViewer::GraphicsWindowEmbedded to the main camera, the scene cannot be drawn. Only clear color is displayed. So I assume that since the graphics context has been changed, do i have to specify where the shadow texture need to be binded?

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74545#74545
Robert Osfield
2018-08-16 09:04:50 UTC
Permalink
Post by Cong Ye
I am currently using the osgShadow NodeKist. It only works when I use osgViewer as default graphics context. Now the case is, I have to assign a third party graphics context to the main camera as we are using a Qt Gui for buttons etc. After I assign osgViewer::GraphicsWindowEmbedded to the main camera, the scene cannot be drawn. Only clear color is displayed. So I assume that since the graphics context has been changed, do i have to specify where the shadow texture need to be binded?
There isn't any special you need to do with osgShadow, it'll be
looking after itself.

The problem you have is mostly likely down to the issues with the Qt
integration, and using osgShadow isn't revelling this exisiting
problem rather than causing it.

My best guess is that you haven't set the Draw/ReadBuffers correctly
for you viewer level Cameras.

If this doesn't work then please think about using osgQt.

Robert.

Loading...