Skip to content

Commit

Permalink
enable grayscale albedo map to fix red color highlights and disable h…
Browse files Browse the repository at this point in the history
…ardware gamma to fix dark sky color

Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 committed Apr 14, 2021
1 parent 01aeec2 commit 62bb629
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)
#============================================================================
# Initialize the project
#============================================================================
project(ignition-rendering6 VERSION 6.0.0)
project(ignition-rendering5 VERSION 5.0.0)

#============================================================================
# Find ignition-cmake
Expand Down
2 changes: 1 addition & 1 deletion examples/ogre2_demo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(ignition-rendering-ogre2-demo)

find_package(ignition-rendering6)
find_package(ignition-rendering5)

include_directories(SYSTEM
${PROJECT_BINARY_DIR}
Expand Down
28 changes: 21 additions & 7 deletions ogre2/src/Ogre2Material.cc
Original file line number Diff line number Diff line change
Expand Up @@ -425,24 +425,30 @@ void Ogre2Material::SetLightMap(const std::string &_name, unsigned int _uvSet)
this->lightMapName = _name;
this->lightMapUvSet = _uvSet;

// reserve detail map 0 for light map
Ogre::PbsTextureTypes type = Ogre::PBSM_DETAIL0;
// in ign-rendering5 + ogre 2.1, we reserved detail map 0 for light map
// and set a blend mode (PBSM_BLEND_OVERLAY AND PBSM_BLEND_MULTIPLY2X
// produces better results) to blend with base albedo map. However, this
// creates unwanted red highlights with ogre 2.2. So switching to use the
// emissive map slot and calling setUseEmissiveAsLightmap(true)
// Ogre::PbsTextureTypes type = Ogre::PBSM_DETAIL0;
// this->ogreDatablock->setDetailMapBlendMode(0, Ogre::PBSM_BLEND_OVERLAY);
Ogre::PbsTextureTypes type = Ogre::PBSM_EMISSIVE;

// lightmap usually uses a different tex coord set
this->SetTextureMapImpl(this->lightMapName, type);

this->ogreDatablock->setTextureUvSource(type, this->lightMapUvSet);

// PBSM_BLEND_OVERLAY and PBSM_BLEND_MULTIPLY2X produces better results
this->ogreDatablock->setDetailMapBlendMode(0, Ogre::PBSM_BLEND_OVERLAY);
this->ogreDatablock->setUseEmissiveAsLightmap(true);
}

//////////////////////////////////////////////////
void Ogre2Material::ClearLightMap()
{
this->lightMapName = "";
this->lightMapUvSet = 0u;
this->ogreDatablock->setTexture(Ogre::PBSM_DETAIL0, this->lightMapName);

// in ogre 2.2, we swtiched to use the emissive map slot for light map
this->ogreDatablock->setTexture(Ogre::PBSM_EMISSIVE, this->lightMapName);
this->ogreDatablock->setUseEmissiveAsLightmap(false);
}

//////////////////////////////////////////////////
Expand Down Expand Up @@ -557,11 +563,19 @@ void Ogre2Material::SetTextureMapImpl(const std::string &_texture,
tex->scheduleTransitionTo(Ogre::GpuResidency::Resident);
tex->waitForData();

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

// treat grayscale texture as RGB
if (Ogre::PixelFormatGpuUtils::getNumberOfComponents(
tex->getPixelFormat()) == 1u)
{
this->ogreDatablock->setUseDiffuseMapAsGrayscale(true);
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions ogre2/src/Ogre2RenderTarget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ void Ogre2RenderTarget::UpdateBackgroundMaterial()
mat->getTechnique(0u)->getPass(0u)->getTextureUnitState(0u);
texUnit->setTextureName(this->backgroundMaterial->EnvironmentMap(),
Ogre::TextureTypes::TypeCube);
texUnit->setHardwareGammaEnabled(false);
}

this->backgroundMaterialDirty = false;
Expand Down

0 comments on commit 62bb629

Please sign in to comment.