Skip to content

Commit

Permalink
GRAPHICS: Add MaterialManager::setAlphaModifier()
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Jan 28, 2014
1 parent aabb2c9 commit d06fea8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/graphics/materialman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@ void MaterialManager::setColorModifier(const Ogre::MaterialPtr &material, float
texState->setAlphaOperation(Ogre::LBX_MODULATE, Ogre::LBS_CURRENT, Ogre::LBS_MANUAL, a, a, 1.0);
}

void MaterialManager::setAlphaModifier(const Ogre::MaterialPtr &material, float a) {
Ogre::TextureUnitState *texState = getColorModifier(material);
if (!texState)
texState = addColorModifier(material);

texState->setAlphaOperation(Ogre::LBX_MODULATE, Ogre::LBS_CURRENT, Ogre::LBS_MANUAL, a, a, 1.0);
}

Ogre::TextureUnitState *MaterialManager::getColorModifier(const Ogre::MaterialPtr &material) {
uint count = material->getTechnique(0)->getPass(0)->getNumTextureUnitStates();
for (uint i = 0; i < count; i++) {
Expand All @@ -249,6 +257,9 @@ Ogre::TextureUnitState *MaterialManager::addColorModifier(const Ogre::MaterialPt
Ogre::TextureUnitState *texState = material->getTechnique(0)->getPass(0)->createTextureUnitState();
texState->setName("colormodifier");

texState->setColourOperationEx(Ogre::LBX_SOURCE1, Ogre::LBS_CURRENT, Ogre::LBS_CURRENT);
texState->setAlphaOperation(Ogre::LBX_SOURCE1, Ogre::LBS_CURRENT, Ogre::LBS_CURRENT);

return texState;
}

Expand Down
2 changes: 2 additions & 0 deletions src/graphics/materialman.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class MaterialManager : public Common::Singleton<MaterialManager> {

/** Change the material's color modifier. */
void setColorModifier(const Ogre::MaterialPtr &material, float r, float g, float b, float a = 1.0);
/** Change the material's alpha modifier. */
void setAlphaModifier(const Ogre::MaterialPtr &material, float a);

private:
void create(const MaterialDeclaration &decl, Ogre::MaterialPtr material);
Expand Down

0 comments on commit d06fea8

Please sign in to comment.