transparent Entities

Problems building or running the engine, queries about how to use features etc.
Post Reply
_lkoikm
Halfling
Posts: 57
Joined: Fri Feb 11, 2005 7:52 am
Location: Here.

transparent Entities

Post by _lkoikm »

I have a question about material scripts.
When i tried to use various material scripts which use vertex/fragment programs (like those in examples with bumpmap or cel shader )
I tried to make Entity to be affected by more than one light i added

Code: Select all

pass{ 
iteration once_per_light
scene_blend add
....
in material script. But effect is although quite understandable (addition of images gives the effect of transparence ) still not acceptable. What to do?
if needed i could attatch material/cg code...
the point is how to modify material script to one that is nontransparent and uses multilight.
Thanks in advance to Ogre community
beware the alien , the mutant , the heretic...
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67
Contact:

Post by sinbad »

You must only use add for the lighting phase; don't apply textures before or after. See the normal mapping samples for details.

The reason is that you can't use add to contribute colour of anything but light. If you try to use it to apply texture too, the texture may be dark in one pass, and then overbrightened in the next which will wash out all the colours (since the first pass had a limited colour range). You have to lay down ambient light first, then add light in each light pass, then modulate the final result with the textures you want in a decal pass.
User avatar
Emmeran
Goblin
Posts: 272
Joined: Wed Jun 02, 2004 11:47 am
Location: Erlangen
Contact:

Post by Emmeran »

by the way: I never found out, how to make a textured entity entirely transparent, with a defined alpha value, for example the preview of a building in a strategy game with an alpha value of, let's say 70%
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67
Contact:

Post by sinbad »

Either use alpha in a texture, or generate a manual alpha value using an alpha_op_ex in a texture unit. Then use scene_blend alpha_blend in the pass.
User avatar
Emmeran
Goblin
Posts: 272
Joined: Wed Jun 02, 2004 11:47 am
Location: Erlangen
Contact:

Post by Emmeran »

ah yes... ok... *g* :shock: :?:

sry do you perhaps have an example for me? :oops:
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67
Contact:

Post by sinbad »

Code: Select all

		Real alphaLevel = 0.5f;
		MaterialPtr alphamat = MaterialManager::getSingleton().create("testy", 
			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
		Pass* pass = alphamat->getTechnique(0)->getPass(0);
		pass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
		pass->setDepthWriteEnabled(false);
		TextureUnitState* t = pass->createTextureUnitState();
		t->setAlphaOperation(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, alphaLevel);

		ent = mSceneMgr->createEntity("asd", "ogrehead.mesh");
		ent->setMaterialName("testy");
		mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
Note that I don't use any textures here, I just use the texture unit to generate the alpha. You can combine that with a real texture too if you want. I've shown the code because you can all setAlphaOperation many times to vary the alpha level dynamically.
User avatar
Emmeran
Goblin
Posts: 272
Joined: Wed Jun 02, 2004 11:47 am
Location: Erlangen
Contact:

Post by Emmeran »

big thx to you sinbad! great :)
Post Reply