Page 1 of 1

transparent Entities

Posted: Tue Feb 22, 2005 9:06 pm
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

Posted: Tue Feb 22, 2005 9:55 pm
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.

Posted: Tue Feb 22, 2005 10:28 pm
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%

Posted: Tue Feb 22, 2005 11:04 pm
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.

Posted: Tue Feb 22, 2005 11:45 pm
by Emmeran
ah yes... ok... *g* :shock: :?:

sry do you perhaps have an example for me? :oops:

Posted: Wed Feb 23, 2005 12:15 am
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.

Posted: Wed Feb 23, 2005 4:36 pm
by Emmeran
big thx to you sinbad! great :)