Page 1 of 1

Transparent Plane with Transparent Texture

Posted: Thu May 13, 2010 10:25 am
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?

Re: Transparent Plane with Transparent Texture

Posted: Thu May 13, 2010 11:41 am
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.

Re: Transparent Plane with Transparent Texture

Posted: Thu May 13, 2010 12:17 pm
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.

Re: Transparent Plane with Transparent Texture

Posted: Fri Nov 27, 2015 8:20 am
by ilotuo
But your code is useful for me .I worked on android ogre sdk.
^_^ thanks.