Hi Mathieu

I am currently playing with opacity/transparency capabilities of geodes in a 
model.
In that way, i use:

material = (osg::Material *) 
Geode->getStateSet()->getAttribute(osg::StateAttribute::MATERIAL);
Geode->getStateSet()->setMode( GL_BLEND, osg::StateAttribute::ON );
material->setTransparency(osg::Material::FRONT, 1.-opacity);
Geode->getStateSet()->setAttributeAndModes(material, 
osg::StateAttribute::OVERRIDE);

It works, the geode becomes transparent.

But is there a way to see objects behind this geode ?
Most probably, your problem is that the transparent object is rendered first. Then, everything that is behind doesn't pass the z-test and it's culled away. In order to "see" trhough transparent geometry you have to render it after all opaque objects have been rendered. Adding:
Geode->getStateSet()->setRenderBinDetails(1, "transparent");
you will force that geode to be rendered in a different render bin which will be processed after the default render bin. If you have more than one transparent object you also have to make sure that they are rendered back to front. I think that's done with:
Geode->getStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
but I'm not fully sure.

I'd also add:
osg::BlendFunc *fuct = new osg::BlendFunc();
func->setFunction(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Geode->getStateSet()->setAttributeAndModes(func);
I don't know it that's the default blending function but I guess that's the effect you are looking for. Setting it explicitly can't be harmful.

I mean : if i use Geode->setNodeMask(0x000000); the geode is invisible and I 
can see what is behind, but not with the transparency effect.
Setting such a node mask makes all scenegraph traversals ignore that node, that's why it becomes invisible.

Please, do you have an idea how managing the code if i want to see what is 
behind a transparent object ?
Keep in mind that the code above only works correctly for non-intersecting convex objects without back faces and without visibility cycles (so actually it seldom works). In any other case you may see artifacts depending on the view point. If you need reliable transparency you will have to implement a much more sophisticated technique, such as depth peeling, bucket depth peeling or this one https://graphics.stanford.edu/wikis/cs448s-10/FrontPage?action=AttachFile&do=get&target=CS448s-10-11-oit.pdf if your graphics card supports Shader Model 5.

Regards,
Juan

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to