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 problem


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
beingbad@163.com
Newbie


Joined: 13 Jun 2019
Posts: 6

PostPosted: Thu Jun 13, 2019 9:28 am    Post subject:
Transparency problem
Reply with quote

Hi, Everyone! Is there anybody can help to solve this problem. I tried to make geode node to be transparency in my application. A piece of my code is list below:

osg::StateSet* stateSet = geode->getOrCreateStateSet();

stateSet->setMode(GL_BLEND, osg::StateAttribute:ShockedN | osg::StateAttribute::OVERRIDE);
osg::BlendFunc* blendFunc = dynamic_cast<osg::BlendFunc*>(stateSet->getAttribute(osg::StateAttribute::BLENDFUNC));
if (nullptr == blendFunc) {
blendFunc = new osg::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
stateSet->setAttribute(blendFunc, osg::StateAttribute:ShockedN | osg::StateAttribute::OVERRIDE);
} else {
blendFunc->setSource(GL_SRC_ALPHA);
blendFunc->setDestination(GL_ONE_MINUS_SRC_ALPHA);
}

osg::Material* mat = dynamic_cast<osg::Material*>(stateSet->getAttribute(osg::StateAttribute::MATERIAL));
if (nullptr == mat) {
mat = new osg::Material;
stateSet->setAttribute(mat,osg::StateAttribute:ShockedN | osg::StateAttribute::OVERRIDE);
}
mat->setAmbient(osg::Material::FRONT_AND_BACK,osg::Vec4(0.2f,0.2f,0.2f,0.3f));
mat->setDiffuse(osg::Material::FRONT_AND_BACK,osg::Vec4(0.8f,0.8f,0.8f,0.3f));
mat->setTransparency(osg::Material::FRONT_AND_BACK, 0.4);

osg::LightModel* lm = dynamic_cast<osg::LightModel *>(stateSet->getAttribute(osg::StateAttribute::LIGHTMODEL));
if (nullptr == lm) {
lm = new osg::LightModel();
stateSet->setAttribute(lm,osg::StateAttribute:ShockedN | osg::StateAttribute::OVERRIDE);
}
lm->setTwoSided(false);
stateSet->setAttribute(lm, osg::StateAttribute:ShockedN | osg::StateAttribute::OVERRIDE);

it seems like something is wrong as the transparency effect is miss-up. could anybody figure out what i missed and how to solve this problem.

thanks very much for your help!


Cheers,
Yu
Back to top
View user's profile Send private message
icf80
User


Joined: 12 Apr 2019
Posts: 32

PostPosted: Thu Jun 13, 2019 1:32 pm    Post subject:
Reply with quote

Hi,

This might help you, you have to set the hint

Code:
   if (transparent)
   {
      geode->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
      geode->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
   }
   else
   {
      geode->getOrCreateStateSet()->setRenderingHint(osg::StateSet::OPAQUE_BIN);
   }


Thank you!

Cheers,
Catalin
Back to top
View user's profile Send private message
beingbad@163.com
Newbie


Joined: 13 Jun 2019
Posts: 6

PostPosted: Thu Jun 13, 2019 3:05 pm    Post subject:
Reply with quote

Hi, icf80

thanks for your quickly reply and help. I have made a try, but the transparency effect is still miss up.


...

Thank you!

Cheers,
Yu
Back to top
View user's profile Send private message
icf80
User


Joined: 12 Apr 2019
Posts: 32

PostPosted: Thu Jun 13, 2019 5:17 pm    Post subject:
Reply with quote

Hi,

- your cube might have wrong triangles/vertices order. Did you create the cube by "hand"?

- have you modified the cull settings? The triangles with back face towards the camera need to be culled.

- did you create your own camera?


Thank you!

Cheers,
Catalin
Back to top
View user's profile Send private message
beingbad@163.com
Newbie


Joined: 13 Jun 2019
Posts: 6

PostPosted: Fri Jun 14, 2019 12:57 am    Post subject:
Reply with quote

Dear icf80,

thanks for your reply. Yes, you are right. the cube is created by hand, and the camera is too. I will make a try as you suggest.

thanks for your help again.

...

Thank you!

Cheers,
Yu
Back to top
View user's profile Send private message
beingbad@163.com
Newbie


Joined: 13 Jun 2019
Posts: 6

PostPosted: Fri Jun 14, 2019 7:30 am    Post subject:
Reply with quote

Hi icf80,

thanks for you help. I solved this problem with your suggestion to setting cull. Now the transparency of my cube is normal. Thank you very much for your help.


Cheers,
Yu
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 Problem reading unclamped float value... Omar Álvarez General 0 Mon Oct 14, 2019 2:21 pm View latest post
No new posts Custom cursor problem? tom General 7 Wed Sep 18, 2019 4:44 pm View latest post
No new posts osgVIEWER problem camera skehal General 1 Tue Jul 23, 2019 9:17 am View latest post
No new posts problem about reconstructing world co... swaggydong General 0 Sun Jun 23, 2019 8:26 am View latest post
No new posts Order Independent Transparency and os... beingbad@163.com General 3 Fri Jun 14, 2019 7:56 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