Hi Brian, Robert, all,
For object outlining I use cull callback that traverses node two times (its
a simple workaround for two pass techniques). I use well known technique
rendering back faces in wireframe (
http://en.wikipedia.org/wiki/Cel-shaded_animation) prior regular rendering.
It was mentioned several times on osg-users. To outline selected node You
just need to call node->setCullCallback(new OutlineCallback), there is no
need to tweak the scene graph structure. To change outline color You could
use emissive color tweaking on object material, J-S was mentioning it some
time ago
http://www.mail-archive.com/[email protected]/msg21935.html
class OutlineCallback : public osg::NodeCallback
{
public:
OutlineCallback();
/** Line width for outline effect */
void setLineWidth(float lineWidth);
float getLineWidth() const;
/** Sets required states */
void resetStateSet();
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv);
protected:
osg::ref_ptr<osg::StateSet> _stateSet;
};
OutlineCallback::OutlineCallback()
{
resetStateSet();
setLineWidth(3.0);
}
void OutlineCallback::resetStateSet()
{
if (!_stateSet)
_stateSet = new osg::StateSet;
osg::StateSet *ss = _stateSet.get();
ss->setRenderBinDetails(200, "RenderBin");
ss->setMode(GL_LIGHTING, osg::StateAttribute::OFF |
osg::StateAttribute::OVERRIDE);
for (unsigned int unit=0;unit<4;++unit)
ss->setTextureMode(unit, GL_TEXTURE_2D, osg::StateAttribute::OFF |
osg::StateAttribute::OVERRIDE);
osg::PolygonMode *polygonMode = dynamic_cast<osg::PolygonMode
*>(ss->getAttribute(osg::StateAttribute::POLYGONMODE));
if (!polygonMode)
{
polygonMode = new osg::PolygonMode;
ss->setAttribute(polygonMode, osg::StateAttribute::ON);
}
polygonMode->setMode(osg::PolygonMode::BACK, osg::PolygonMode::LINE);
osg::CullFace *cullFace = dynamic_cast<osg::CullFace
*>(ss->getAttribute(osg::StateAttribute::CULLFACE));
if (!cullFace)
{
cullFace = new osg::CullFace;
ss->setAttribute(cullFace, osg::StateAttribute::ON);
}
cullFace->setMode(osg::CullFace::FRONT);
osg::Depth *depth = dynamic_cast<osg::Depth
*>(ss->getAttribute(osg::StateAttribute::DEPTH));
if (!depth)
{
depth = new osg::Depth;
ss->setAttribute(depth, osg::StateAttribute::ON);
}
depth->setFunction(osg::Depth::LEQUAL);
}
void OutlineCallback::setLineWidth(float width)
{
osg::LineWidth *lineWidth = dynamic_cast<osg::LineWidth
*>(_stateSet->getAttribute(osg::StateAttribute::LINEWIDTH));
if (!lineWidth)
{
lineWidth = new osg::LineWidth;
_stateSet->setAttribute(lineWidth, osg::StateAttribute::ON);
}
lineWidth->setWidth(width);
}
float OutlineCallback::getLineWidth() const
{
osg::LineWidth *lineWidth = dynamic_cast<osg::LineWidth
*>(_stateSet->getAttribute(osg::StateAttribute::LINEWIDTH));
return lineWidth ? lineWidth->getWidth() : 1.0;
}
void OutlineCallback::operator()(osg::Node *node, osg::NodeVisitor *nv)
{
if (nv->getVisitorType() == osg::NodeVisitor::CULL_VISITOR)
{
osgUtil::CullVisitor *cv = dynamic_cast<osgUtil::CullVisitor *>(nv);
if (cv)
{
cv->pushStateSet(_stateSet.get());
traverse(node, cv);
cv->popStateSet();
}
}
traverse(node, nv);
}
Regards,
Maciej
2009/5/21 Robert Osfield <[email protected]>
> Hi Brian,
>
> It sounds like you may have hit upon a threading bug in the Outline
> effect. Try changing the viewer threading mode to either
> SingleThreaded or CullDrawThreadPerCamera, if this works then there
> is an threading issue with changing display lists or StateSet's at the
> same time that these objects are being rendered. Changing the
> DataVariance to STATIC is the usually the best way to solve this, but
> you can also double buffer the problem structures.
>
> Robert.
>
> On Thu, May 21, 2009 at 5:29 PM, Brian Stewart <[email protected]>
> wrote:
> > Hi,
> >
> > I switched my code around to where the model was being added from the
> main loop rather than the update traversal, and it was still crashing. On
> closer examination I noticed that the crashes were occurring during the
> render traversal, so I began to suspect the effect itself. When I replaced
> the effect with an instance of osgFX::Scribe, then everything worked
> correctly. So something was amiss in the Outline effect itself. I was using
> it only because I did not know about the Scribe effect, which is better for
> my purposes anyway.
> >
> > Thank you!
> >
> > Brian
> >
> > ------------------
> > Read this topic online here:
> > http://forum.openscenegraph.org/viewtopic.php?p=12692#12692
> >
> >
> >
> >
> >
> > _______________________________________________
> > osg-users mailing list
> > [email protected]
> >
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org