Transparent Plane with Transparent Texture

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
User avatar
n9ine
Halfling
Posts: 55
Joined: Mon Aug 25, 2008 4:24 pm

Transparent Plane with Transparent Texture

Post by n9ine »

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?
User avatar
lingfors
Hobgoblin
Posts: 525
Joined: Mon Apr 02, 2007 12:18 am
Location: Sweden
x 79

Re: Transparent Plane with Transparent Texture

Post by lingfors »

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.
User avatar
madmarx
OGRE Expert User
OGRE Expert User
Posts: 1671
Joined: Mon Jan 21, 2008 10:26 pm
x 50

Re: Transparent Plane with Transparent Texture

Post by madmarx »

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.
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
ilotuo
Gnoblar
Posts: 16
Joined: Wed Nov 04, 2015 7:55 am

Re: Transparent Plane with Transparent Texture

Post by ilotuo »

But your code is useful for me .I worked on android ogre sdk.
^_^ thanks.