void MaterialInstance::setColor(float red, float green, float blue, float alpha) { if (mCopyMat.isNull ()) { createCopyMaterial (); } unsigned short i = 0, j; ColourValue sc, dc; // Source colur, destination colour Material::TechniqueIterator techniqueIt = mCopyMat->getTechniqueIterator (); while (techniqueIt.hasMoreElements ()) { Technique *t = techniqueIt.getNext (); Technique::PassIterator passIt = t->getPassIterator (); j = 0; while (passIt.hasMoreElements ()) { sc = mOriginalMat->getTechnique (i)->getPass (j)->getDiffuse (); dc = sc; dc.a = alpha; dc.r = red; dc.g = green; dc.b = blue; passIt.peekNext ()->setAmbient (mOriginalMat->getTechnique (i)->getPass (j)->getAmbient ()); passIt.peekNext ()->setDiffuse (dc); passIt.moveNext (); ++j; } ++i; } }
void MaterialInstance::ChangeOriginalMaterial() { if (mCopyMat.isNull ()) { createCopyMaterial (); } unsigned short i = 0, j; ColourValue sc, dc; // Source colur, destination colour Material::TechniqueIterator techniqueIt = mCopyMat->getTechniqueIterator (); while (techniqueIt.hasMoreElements ()) { Technique *t = techniqueIt.getNext (); Technique::PassIterator passIt = t->getPassIterator (); j = 0; while (passIt.hasMoreElements ()) { sc = mOriginalMat->getTechnique (i)->getPass (j)->getDiffuse (); passIt.peekNext ()->setAmbient (mOriginalMat->getTechnique (i)->getPass (j)->getAmbient ()); passIt.peekNext ()->setDiffuse (sc); passIt.moveNext (); ++j; } ++i; } }
void MaterialInstance::setTransparency (Real transparency) { mCurrentTransparency = transparency; if (mCurrentTransparency > 0.0f) { if (mCurrentTransparency > 1.0f) mCurrentTransparency = 1.0f; if (mCopyMat.isNull ()) { createCopyMaterial (); } unsigned short i = 0, j; ColourValue sc, dc; // Source colur, destination colour Material::TechniqueIterator techniqueIt = mCopyMat->getTechniqueIterator (); while (techniqueIt.hasMoreElements ()) { Technique *t = techniqueIt.getNext (); Technique::PassIterator passIt = t->getPassIterator (); j = 0; while (passIt.hasMoreElements ()) { sc = mOriginalMat->getTechnique (i)->getPass (j)->getDiffuse (); switch (mSBT) { case SBT_ADD: dc = sc; dc.r -= sc.r * mCurrentTransparency; dc.g -= sc.g * mCurrentTransparency; dc.b -= sc.b * mCurrentTransparency; passIt.peekNext ()->setAmbient (ColourValue::Black); break; case SBT_TRANSPARENT_ALPHA: default: dc = sc; dc.a = sc.a * (1.0f - mCurrentTransparency); passIt.peekNext ()->setAmbient (mOriginalMat->getTechnique (i)->getPass (j)->getAmbient ()); break; } passIt.peekNext ()->setDiffuse (dc); passIt.moveNext (); ++j; } ++i; } } else { mCurrentTransparency = 0.0f; } }
void MaterialInstance::createCopyMaterial () { String name; // Avoid name collision do { name = mOriginalMat->getName () + StringConverter::toString (Math::UnitRandom ()); } while (MaterialManager::getSingleton ().resourceExists (name)); mCopyMat = mOriginalMat->clone (name); Material::TechniqueIterator techniqueIt = mCopyMat->getTechniqueIterator (); while (techniqueIt.hasMoreElements ()) { Technique *t = techniqueIt.getNext (); Technique::PassIterator passIt = t->getPassIterator (); while (passIt.hasMoreElements ()) { passIt.peekNext ()->setDepthWriteEnabled (false); passIt.peekNext ()->setSceneBlending (mSBT); passIt.moveNext (); } } }
//=========================================================================== // MaterialPassAction //=========================================================================== void IMaterialPassAction::subEntityAction( SubEntityMaterial* subEntity ) const { if( !subEntity->getMaterial().isNull() ) { unsigned short i = 0 ; for( Material::TechniqueIterator techniqueIt = subEntity->getMaterial()->getTechniqueIterator() ; techniqueIt.hasMoreElements() ; techniqueIt.moveNext(), ++i ) { Technique* techniqueScr = subEntity->getMaterial()->getTechnique( i ) ; unsigned short j = 0; for( Technique::PassIterator passIt = techniqueIt.peekNext()->getPassIterator (); passIt.hasMoreElements() ; passIt.moveNext(), ++j ) { passAction( subEntity, passIt.peekNext(), techniqueScr->getPass( j ) ) ; } } } }