[Solved] Multiple texture units.

Get answers to all your basic programming questions. No Ogre questions, please!
Treon
Kobold
Posts: 37
Joined: Mon Mar 07, 2011 2:30 pm

[Solved] Multiple texture units.

Post by Treon »

Hey,

I have a question on material texture units, it is possible to dynamically add and remove a texture unit from a matrial?

Let's say I have this matrial attached to my mesh.

Code: Select all

material weapon_material
{
	technique
	{
		pass
		{
			ambient 0.588235 0.588235 0.588235
			diffuse 0.588235 0.588235 0.588235
			specular 0 0 0 0
			emissive 0 0 0
			texture_unit
			{
				texture weapon.png
			}
		}
	}
}
Then when I hold the mouse over the mesh this shall be added in the weapon material.

Code: Select all

texture_unit
 {
	cubic_texture outline.dds combinedUVW
	tex_address_mode clamp
	colour_op_ex add src_texture src_current
	colour_op_multipass_fallback one one
	env_map cubic_normal
}
Is this possible to do?

Thanks!
Last edited by Treon on Fri Aug 31, 2012 11:07 am, edited 1 time in total.
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: Multiple texture units.

Post by bstone »

Absolutely. See Ogre::Pass::addTextureUnitState()/removeTextureUnitState(). The easiest way to do that would be to add the texture unit to the material script and remove it when your application initializes. Then add it back and remove as needed. Be sure to dispose the texture unit on exit if you own it (as opposed to the material pass owning it). This way you you don't need to write the code creating it from scratch.
Treon
Kobold
Posts: 37
Joined: Mon Mar 07, 2011 2:30 pm

Re: Multiple texture units.

Post by Treon »

bstone wrote:Absolutely. See Ogre::Pass::addTextureUnitState()/removeTextureUnitState(). The easiest way to do that would be to add the texture unit to the material script and remove it when your application initializes. Then add it back and remove as needed. Be sure to dispose the texture unit on exit if you own it (as opposed to the material pass owning it). This way you you don't need to write the code creating it from scratch.
Perfect I'll try that, thanks.

Cheers
Treon
Kobold
Posts: 37
Joined: Mon Mar 07, 2011 2:30 pm

Re: Multiple texture units.

Post by Treon »

bstone wrote:Absolutely. See Ogre::Pass::addTextureUnitState()/removeTextureUnitState(). The easiest way to do that would be to add the texture unit to the material script and remove it when your application initializes. Then add it back and remove as needed. Be sure to dispose the texture unit on exit if you own it (as opposed to the material pass owning it). This way you you don't need to write the code creating it from scratch.
Something like this then?

Code: Select all

Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName("highlight");
Ogre::TextureUnitState *pUnit = mat->getTechnique( 0 )->getPass( 0 )->getTextureUnitState( 0 );
Ogre::Technique *tech = mEntity->getSubEntity(0)->getMaterial()->getTechnique(0);
mMaterialPass = tech->getPass(0);
mMaterialPass->addTextureUnitState(new Ogre::TextureUnitState( mMaterialPass, *pUnit ));
Solved, Thanks.