Material 2nd pass changes

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
Shem
Halfling
Posts: 55
Joined: Fri Feb 16, 2018 9:32 am
x 8

Material 2nd pass changes

Post by Shem »

Hi All,

When I try to make changes to the 2nd pass dynamically they don't take affect other than the 1st time.

A simple

Code: Select all

ppass->setDiffuse(1.0f, 1.0f, 1.0f, opacity);  
works fine on the first pass for every frame but won't update for the 2nd one.

Here is my code:

Code: Select all

	Ogre::MaterialPtr Mat = m_mmgr->getByName(m_MaterialName);
		Ogre::Pass* ppass;
		Ogre::TextureUnitState* ptus;

		//Background
		if (Mat->getTechnique(0)->getNumPasses() < 1)
			ppass = Mat->getTechnique(0)->createPass();
		else
			ppass = Mat->getTechnique(0)->getPass(0);
		
		if (ppass->getNumTextureUnitStates() < 1)
			ptus = ppass->createTextureUnitState();
		else
			ptus = ppass->getTextureUnitState(0);

		//First Time
		if (ptus->getTextureName() != m_BGTexture->getName())
		{
			ppass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
			ptus->setTexture(m_BGTexture);
			ptus->setTextureAddressingMode(Ogre::TextureUnitState::TextureAddressingMode::TAM_CLAMP);
			ptus->setTextureFiltering(Ogre::TextureFilterOptions::TFO_ANISOTROPIC);
		}
		ppass->setDiffuse(1.0f, 1.0f, 1.0f, opacity);

		//Create Text
		if (Mat->getTechnique(0)->getNumPasses() < 2)
			ppass = Mat->getTechnique(0)->createPass();
		else
			ppass = Mat->getTechnique(0)->getPass(1);

		//First Time
		if (ppass->getNumTextureUnitStates() < 1)
		{
			ppass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
			ptus = ppass->createTextureUnitState();
			ptus->setColourOperationEx(LBX_BLEND_TEXTURE_ALPHA);
			ptus->setTextureAddressingMode(Ogre::TextureUnitState::TextureAddressingMode::TAM_CLAMP);
			ptus->setTextureFiltering(Ogre::TextureFilterOptions::TFO_ANISOTROPIC);
			ptus->setTexture(m_Texture);
		}
		else
			ptus = ppass->getTextureUnitState(0);

		ppass->setDiffuse(1.0f, 1.0f, 1.0f, opacity);
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: Material 2nd pass changes

Post by paroj »

ogre version, rendersystem, etc.
Shem
Halfling
Posts: 55
Joined: Fri Feb 16, 2018 9:32 am
x 8

Re: Material 2nd pass changes

Post by Shem »

Hi Paroj,

Ogre 1.10, ogl 3+.
Everything I'm seeing is pointing to issues with per frame changes in material.
Is it possible that this issue is due to mixing textures with different pixel formats? The same code works fine the first time so that threw me off.

Thanks in advance.
Shem
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: Material 2nd pass changes

Post by paroj »

for GL3+, the RTSS will generate a new programmable technique, based on the base technique on the first use. However it will not sync these two afterwards. Therefore you should use Material::getBestTechnique to get the new one when available.
Shem
Halfling
Posts: 55
Joined: Fri Feb 16, 2018 9:32 am
x 8

Re: Material 2nd pass changes

Post by Shem »

OMG!!! That was it. I can't thank you enough. Been pulling hair for days now.

Thank you so much
Shem
Post Reply