[osg-users] Temporarily overriding alpha channel

Claudio Benghi claudio.benghi at gmail.com
Sun Apr 7 11:46:19 PDT 2019


Hi all,

If anyone finds this useful, my current solution, combining help from this thread and Paul Martz at http://forum.openscenegraph.org/viewtopic.php?t=13877, looks like the following:


Code:

osg::StateSet* state = _rootGroup->getOrCreateStateSet();
if (op == 1)
{
 state->removeAttribute(osg::StateAttribute::BLENDCOLOR);
 state->removeAttribute(osg::StateAttribute::BLENDFUNC);
 state->setRenderingHint(osg::StateSet::DEFAULT_BIN);
}
else
{
 osg::BlendColor* bc = new osg::BlendColor(osg::Vec4(1.0, 1.0, 1.0, op));
 osg::BlendFunc *bf = new osg::BlendFunc();
 state->setAttributeAndModes(bf, osg::StateAttribute::ON);
 state->setAttributeAndModes(bc, osg::StateAttribute::ON);
 bf->setSource(osg::BlendFunc::CONSTANT_ALPHA);
 bf->setDestination(osg::BlendFunc::ONE_MINUS_CONSTANT_ALPHA);
 state->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
}




Next I'll try to see if I can set a material so that the blend settings are ignored for a part of the sub-tree.

Thanks for all the help that carried me this far!
Claudio

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75790#75790







More information about the osg-users mailing list