A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
n9ine
Halfling
Posts: 55 Joined: Mon Aug 25, 2008 4:24 pm
Post
by n9ine » Thu May 13, 2010 10:25 am
Hi all;
I am having a problem to set my textured plane transparent in the scene. It hides other objects.
Code: Select all
Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create("PlaneMat", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
mat->setSceneBlending(Ogre::SBF_SOURCE_ALPHA, Ogre::SBF_DEST_ALPHA);
Ogre::Technique *technique = mat->createTechnique();
technique->createPass();
mat->getTechnique(0)->getPass(0)->setLightingEnabled(true);
mat->getTechnique(0)->getPass(0)->createTextureUnitState("MyTexture");
mat->getTechnique(0)->getPass(0)->setSceneBlending (Ogre::SBT_TRANSPARENT_COLOUR);
MovablePlane *mPlane;
Entity *mPlaneEnt;
SceneNode *mPlaneNode;
mPlane = new MovablePlane("Plane");
mPlane->d = 0;
mPlane->normal = Vector3::UNIT_Z;
MeshManager::getSingleton().createPlane("PlaneMesh", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
*mPlane, 30, 30, 1, 1, true, 1, 1, 1, Vector3::UNIT_Y);
mPlaneEnt = mSceneMgr->createEntity("PlaneEntity", "PlaneMesh");
mPlaneEnt->setMaterialName("PlaneMat");
what goes wrong here?
lingfors
Hobgoblin
Posts: 525 Joined: Mon Apr 02, 2007 12:18 am
Location: Sweden
x 79
Post
by lingfors » Thu May 13, 2010 11:41 am
Are you sure you don't want to blend based on the alpha value in the texture?
Code: Select all
mat->getTechnique(0)->getPass(0)->setSceneBlending (Ogre::SBT_TRANSPARENT_ALPHA);
Alos, this line:
Code: Select all
mat->setSceneBlending(Ogre::SBF_SOURCE_ALPHA, Ogre::SBF_DEST_ALPHA);
is completely useless, since it just iterates through every technique, and through every pass within those techniques, and set the scene blending in those passes. But since you do this before you have created any techniques at all, it wont do anything.
madmarx
OGRE Expert User
Posts: 1671 Joined: Mon Jan 21, 2008 10:26 pm
x 50
Post
by madmarx » Thu May 13, 2010 12:17 pm
1/ there is already a technique & a pass par defaut in any just created material.
2/ you forgot to disable depth write on the pass.
ilotuo
Gnoblar
Posts: 16 Joined: Wed Nov 04, 2015 7:55 am
Post
by ilotuo » Fri Nov 27, 2015 8:20 am
But your code is useful for me .I worked on android ogre sdk.
^_^ thanks.