Hi Frédéric,

Thanks for your advice. The invisible objects are in the scenegraph
before the visible ones so at least I have that going for me. I think
we won't be moving the camera view too much so I think it will be OK.
I just thought it was weird that I would get the expected behavior
until I rotated the camera to some angles and then portions that
should be occluded would become visible.

Judie

On Apr 16, 7:48 am, Frédéric SPEISSER <[EMAIL PROTECTED]>
wrote:
> Hi Judie,
>
> What I noticed using colormask is, if you want some "invisible" objects
> (with a colormask to false) to occlude some other objects you must add
> the "invisible " ones before the others in the scenegraph. When I say
> before it is from the scenegraph traversal point of view.
>
> I don't know if it can help you...
>
> Frédéric.
>
> Judie a écrit :
>
>
>
>
>
> > Hi Robert,
>
> > I am sorry for not providing an adequate description.
>
> > High level explanation of what I am trying to do:
>
> > Replace some of the geometry in the scene with live camera feed. But
> > in order to do this, I still need the actual geometry in the scene to
> > modify the depth buffer as if it were there even though it is not
> > visible.
>
> > The initial set up for the render states of the scene is:
>
> > osgUtil::CullVisitor *pCullVisitor = m_sceneView->getCullVisitor();
>
> > osgUtil::RenderBin *pRenderBin = pCullVisitor->getCurrentRenderBin();
>
> > pRenderBin->setSortMode(osgUtil::RenderBin::SORT_BACK_TO_FRONT);
>
> > osg::StateSet *pStateSet = m_sceneView->getGlobalStateSet();
>
> > pStateSet->setMode(GL_ALPHA_TEST,osg::StateAttribute::OFF);
>
> > osg::CullFace *pCullFace = new osg::CullFace;
>
> > pCullFace->setMode(osg::CullFace::BACK);
>
> > pStateSet->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
>
> > pStateSet->setAttribute(pCullFace, osg::StateAttribute::ON);
>
> > osg::ShadeModel *pShadeMdl = new osg::ShadeModel;
>
> > pShadeMdl->setMode(osg::ShadeModel::FLAT);
>
> > pStateSet->setAttribute(pShadeMdl, osg::StateAttribute::ON);
>
> > osg::Depth *pDepth = new osg::Depth;
>
> > pDepth->setFunction(osg::Depth::LEQUAL);
>
> > pStateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
>
> > pStateSet->setAttribute(pDepth, osg::StateAttribute::ON);
>
> > All I do to make some of the geometry not visible and yet still drawn
> > to the depth buffer, is disable writes to the color buffer:
>
> > osg::ColorMask *colormaskOff = new osg::ColorMask(false, false, false,
> > false);
>
> > osg::StateSet* state = node->getOrCreateStateSet();
>
> > state->setAttribute(colormaskOff);
>
> > At another point in the scene graph, I enable writes to the color
> > buffer using the same method except the ColorMask values are all true.
> > I never disable depth testing.
>
> > When the scene is rendered, I see my video background and I see my
> > objects that should be visible. However, the depth buffer testing does
> > not seem to work correctly because some parts of the visible geometry
> > that should be occluded by the invisible geometry are showing. But
> > this is not uniform. There are times when the visible geometry is
> > occluded by the invisible geometry as it should be.
>
> > If I change the sorting to this:
>
> > pRenderBin->setSortMode(osgUtil::RenderBin::SORT_FRONT_TO_BACK);
>
> > then it appears to work until I rotate the camera and then there are
> > angles which seem to break the depth testing.
>
> > What doesn't make sense to me is why the behavior should change at all
> > just by disabling writes to the color buffer? I have done the same
> > with OpenGL code in a different application, where I was not sorting
> > (because there was no transparency) and just relying on the graphics
> > drivers\hardware to do the Z buffering, and the occlusion of the
> > inivisible objects worked fine. So it seems there must be some
> > "optimization" taking place inside the scene graph that is culling
> > objects or something. I don't know. It just doesn't make sense to me
> > why I can do something in OpenGL and not with OSG.
>
> > What do you think?
>
> > Thanks,
>
> > Judie
>
> > On Apr 16, 1:57 am, "Robert Osfield" <[EMAIL PROTECTED]> wrote:
>
> >> Hi Judie,
>
> >> I'm afraid I've just found it too difficult to work out what you are
> >> doing to be able to provide any suggestions.  Could you provide a high
> >> level explanation of what you are trying to do and why to give a bit
> >> of context.  Then why you provide code snippets could you space them
> >> better as word wrap has made it extremely difficult to read the code.
>
> >> Robert.
>
> >> On Tue, Apr 15, 2008 at 11:09 PM, Judie <[EMAIL PROTECTED]> wrote:
>
> >>> In my code I have an OSG tree with the following global state
> >>>  attributes defined:
>
> >>>                osgUtil::CullVisitor *pCullVisitor = m_sceneView-
> >>>  >getCullVisitor();
> >>>         osgUtil::RenderBin *pRenderBin = 
> >>> pCullVisitor->getCurrentRenderBin();
> >>>         pRenderBin->setSortMode(osgUtil::RenderBin::SORT_BACK_TO_FRONT);
> >>>                 osg::StateSet *pStateSet = m_sceneView-
> >>>  >getGlobalStateSet();
> >>>                 pStateSet->setMode(GL_ALPHA_TEST,
> >>>  osg::StateAttribute::OFF);
> >>>                osg::CullFace *pCullFace = new osg::CullFace;
> >>>         pCullFace->setMode(osg::CullFace::BACK);
> >>>         pStateSet->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
> >>>         pStateSet->setAttribute(pCullFace, osg::StateAttribute::ON);
> >>>                 osg::ShadeModel *pShadeMdl = new osg::ShadeModel;
> >>>         pShadeMdl->setMode(osg::ShadeModel::FLAT);
> >>>         pStateSet->setAttribute(pShadeMdl, osg::StateAttribute::ON);
> >>>                 osg::Depth *pDepth = new osg::Depth;
> >>>         pDepth->setFunction(osg::Depth::LEQUAL);
> >>>         pStateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
> >>>         pStateSet->setAttribute(pDepth, osg::StateAttribute::ON);
>
> >>>  The only other time I change the state is when I enable and disable
> >>>  the color buffer writes.
>
> >>>  Here is what I am seeing:
> >>>  If I render the scene with the color buffer always on, then objects
> >>>  that should be occluded by other objects behave correctly and are
> >>>  occluded.
>
> >>>  When I render the scene with the color buffer off for some of the
> >>>  nodes in the beginning of the tree, with it enabled again for ones
> >>>  later on, I expect that because I DID NOT disable writes to the depth
> >>>  buffer, that the objects which are occluded by other objects (even
> >>>  though they were not drawn to the color buffer) should behave
> >>>  correctly. However, they do not. Some do and some don't and if I
> >>>  rotate then even ones that behave correctly, begin to misbehave.
>
> >>>  Now I have made the following change because I don't need to worry
> >>>  about transparency anymore:
> >>>  pRenderBin->setSortMode(osgUtil::RenderBin::SORT_FRONT_TO_BACK);
>
> >>>  And this almost fixes the issue except if I rotate to some degree, I
> >>>  still get parts of objects drawn that should be occluded. I know
> >>>  because I can toggle the objects visible and invisible.
>
> >>>  Is there something internally that can be culling parts of objects
> >>>  because I have the color buffer masked for them?
>
> >>>  Thanks,
>
> >>>  Judie
> >>>  _______________________________________________
> >>>  osg-users mailing list
> >>> [EMAIL PROTECTED]
> >>>  http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph...
>
> >> _______________________________________________
> >> osg-users mailing list
> >> [EMAIL 
> >> PROTECTED]://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph...Hide
> >>  quoted text -
>
> >> - Show quoted text -
>
> > _______________________________________________
> > osg-users mailing list
> > [EMAIL PROTECTED]
> >http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph...
>
> _______________________________________________
> osg-users mailing list
> [EMAIL 
> PROTECTED]://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph...-
>  Hide quoted text -
>
> - Show quoted text -
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to