Skip to content

Commit

Permalink
fix grayscale albedo map (#466)
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 authored Oct 13, 2021
1 parent cde3e08 commit 1c77a8a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ogre2/src/Ogre2Material.cc
Original file line number Diff line number Diff line change
Expand Up @@ -657,23 +657,26 @@ void Ogre2Material::SetTextureMapImpl(const std::string &_texture,
// otherwise this becomes a transparent material
if (_type == Ogre::PBSM_DIFFUSE)
{
if (this->TextureAlphaEnabled())
bool isGrayscale = (Ogre::PixelFormatGpuUtils::getNumberOfComponents(
tex->getPixelFormat()) == 1u);

if (this->TextureAlphaEnabled() || isGrayscale)
{
if (tex)
{
tex->scheduleTransitionTo(Ogre::GpuResidency::Resident);
tex->waitForData();

// only enable alpha from texture if texture has alpha component
if (!Ogre::PixelFormatGpuUtils::hasAlpha(tex->getPixelFormat()))
if (this->TextureAlphaEnabled() &&
!Ogre::PixelFormatGpuUtils::hasAlpha(tex->getPixelFormat()))
{
this->SetAlphaFromTexture(false, this->AlphaThreshold(),
this->TwoSidedEnabled());
}

// treat grayscale texture as RGB
if (Ogre::PixelFormatGpuUtils::getNumberOfComponents(
tex->getPixelFormat()) == 1u)
if (isGrayscale)
{
this->ogreDatablock->setUseDiffuseMapAsGrayscale(true);
}
Expand Down

0 comments on commit 1c77a8a

Please sign in to comment.