From 1c77a8ac05cce3ed5a5b99e56030db833ad67b0a Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Tue, 12 Oct 2021 22:02:05 -0700 Subject: [PATCH] fix grayscale albedo map (#466) Signed-off-by: Ian Chen --- ogre2/src/Ogre2Material.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ogre2/src/Ogre2Material.cc b/ogre2/src/Ogre2Material.cc index f3151f332..6e5215220 100644 --- a/ogre2/src/Ogre2Material.cc +++ b/ogre2/src/Ogre2Material.cc @@ -657,7 +657,10 @@ 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) { @@ -665,15 +668,15 @@ void Ogre2Material::SetTextureMapImpl(const std::string &_texture, 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); }