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
Gnoblar
Posts: 13
Joined: Fri Feb 16, 2018 9:32 am

Material 2nd pass changes

Post by Shem » Wed Apr 25, 2018 2:35 pm

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);
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 800
Joined: Sun Mar 30, 2014 2:51 pm
x 128
Contact:

Re: Material 2nd pass changes

Post by paroj » Wed Apr 25, 2018 6:05 pm

ogre version, rendersystem, etc.
0 x

Shem
Gnoblar
Posts: 13
Joined: Fri Feb 16, 2018 9:32 am

Re: Material 2nd pass changes

Post by Shem » Wed Apr 25, 2018 6:37 pm

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
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 800
Joined: Sun Mar 30, 2014 2:51 pm
x 128
Contact:

Re: Material 2nd pass changes

Post by paroj » Wed Apr 25, 2018 7:19 pm

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.
0 x

Shem
Gnoblar
Posts: 13
Joined: Fri Feb 16, 2018 9:32 am

Re: Material 2nd pass changes

Post by Shem » Wed Apr 25, 2018 9:26 pm

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

Thank you so much
Shem
0 x

Post Reply