OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Transparency & Invisibility


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Scorpio
Newbie


Joined: 12 Jul 2010
Posts: 15

PostPosted: Tue Nov 23, 2010 9:45 am    Post subject:
Transparency & Invisibility
Reply with quote

Hello OSG Community

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:ShockedN );
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 ?
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.

Please, do you have an idea how managing the code if i want to see what is behind a transparent object ?


Cheers,
Mathieu
Back to top
View user's profile Send private message
Juan Hernando
Guest





PostPosted: Tue Nov 23, 2010 10:10 am    Post subject:
Transparency & Invisibility
Reply with quote

Hi Mathieu

Quote:
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:ShockedN );
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.

Quote:
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.

Quote:
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



------------------
Post generated by Mail2Forum
Back to top
Scorpio
Newbie


Joined: 12 Jul 2010
Posts: 15

PostPosted: Tue Nov 23, 2010 10:23 am    Post subject:
Reply with quote

Hi Juan

Thank you very much for the precise answer.
I try this !

Cheers,
Mathieu
Back to top
View user's profile Send private message
Skylark (Jean-Sébastien Guay)
Professional


Joined: 05 Jan 2009
Posts: 2249

PostPosted: Tue Nov 23, 2010 2:12 pm    Post subject:
Transparency & Invisibility
Reply with quote

Hello Mathieu,

Quote:
It works, the geode becomes transparent.

But is there a way to see objects behind this geode ?

Juan gave you a good answer, but the short version is add:

Geode->getStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);

Just to be clear, the canonical way of enabling transparency after
setting the alpha in a material or a texture or a geometry color (with
GL_COLOR_MATERIAL) is:

Geode->getStateSet()->setMode( GL_BLEND, osg::StateAttribute:ShockedN );
Geode->getStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);

Juan spoke about adding an osg::BlendFunc, this is only necessary if you
want to override the default blending function, which is set to what he
said by default (it will give the results you likely want).

And his info about when this type of transparency works is spot on, you
will get good results if two objects are disjoint and manifold,
otherwise you will get artifacts but we generally ignore those kinds of
artifacts for the sake of real-time performance.

Hope this helps,

J-S
--
______________________________________________________
Jean-Sebastien Guay
http://www.cm-labs.com/
http://whitestar02.webhop.org/


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Order Independent Transparency and os... beingbad@163.com General 3 Fri Jun 14, 2019 7:56 am View latest post
No new posts Transparency problem beingbad@163.com General 5 Thu Jun 13, 2019 9:28 am View latest post
No new posts How to set the transparency for one o... adrianj General 0 Tue Feb 06, 2018 3:19 am View latest post
No new posts Animating transparency Tiniriel General 0 Fri Sep 16, 2016 12:09 pm View latest post
No new posts Adding transparency loses color Héctor Martínez General 0 Fri Oct 23, 2015 9:10 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP