Skip to content

Commit 2c85d92

Browse files
iche033Nate Koenig
andauthored
Fix transparency issue for textures without alpha channel (#186)
* fix alpha Signed-off-by: Ian Chen <[email protected]> * Fix codecheck Signed-off-by: Nate Koenig <[email protected]> Co-authored-by: Nate Koenig <[email protected]>
1 parent 26497e7 commit 2c85d92

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

ogre2/include/ignition/rendering/ogre2/Ogre2ParticleEmitter.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef IGNITION_RENDERING_OGRE2_OGRE2PARTICLEEMITTER_HH_
1818
#define IGNITION_RENDERING_OGRE2_OGRE2PARTICLEEMITTER_HH_
1919

20+
#include <memory>
2021
#include <string>
2122
#include "ignition/rendering/base/BaseParticleEmitter.hh"
2223
#include "ignition/rendering/ogre2/Ogre2Visual.hh"

ogre2/src/Ogre2Material.cc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,17 @@ void Ogre2Material::SetAlphaFromTexture(bool _enabled,
151151
double _alpha, bool _twoSided)
152152
{
153153
BaseMaterial::SetAlphaFromTexture(_enabled, _alpha, _twoSided);
154+
Ogre::HlmsBlendblock block;
154155
if (_enabled)
155156
{
156-
Ogre::HlmsBlendblock block;
157-
block.setBlendType(Ogre::SBT_TRANSPARENT_ALPHA);
158157
this->ogreDatablock->setAlphaTest(Ogre::CMPF_GREATER_EQUAL);
158+
block.setBlendType(Ogre::SBT_TRANSPARENT_ALPHA);
159159
this->ogreDatablock->setBlendblock(block);
160-
this->ogreDatablock->setTwoSidedLighting(_twoSided);
161160
}
162161
else
163162
{
164163
this->ogreDatablock->setAlphaTest(Ogre::CMPF_ALWAYS_PASS);
164+
this->ogreDatablock->setBlendblock(block);
165165
}
166166
this->ogreDatablock->setAlphaTestThreshold(_alpha);
167167
this->ogreDatablock->setTwoSidedLighting(_twoSided);
@@ -455,6 +455,17 @@ void Ogre2Material::SetTextureMapImpl(const std::string &_texture,
455455

456456
this->ogreDatablock->setTexture(_type, texLocation.xIdx, texLocation.texture,
457457
&samplerBlockRef);
458+
459+
// disable alpha from texture if texture does not have an alpha channel
460+
// otherwise this becomes a transparent material
461+
if (_type == Ogre::PBSM_DIFFUSE)
462+
{
463+
if (this->TextureAlphaEnabled() && !texLocation.texture->hasAlpha())
464+
{
465+
this->SetAlphaFromTexture(false, this->AlphaThreshold(),
466+
this->TwoSidedEnabled());
467+
}
468+
}
458469
}
459470

460471
//////////////////////////////////////////////////

0 commit comments

Comments
 (0)