From ba6d3dc75df51ce1e92f16425a332fbcf649fee7 Mon Sep 17 00:00:00 2001 From: "Matias N. Goldberg" Date: Sun, 15 Dec 2024 20:34:54 -0300 Subject: [PATCH] Force cull mode NONE when baking lightmaps --- Components/Hlms/Unlit/src/OgreHlmsUnlit.cpp | 2 +- OgreMain/include/OgreHlms.h | 2 +- OgreMain/include/OgreHlmsPso.h | 1 + OgreMain/src/OgreHlms.cpp | 13 +++++++++++-- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Components/Hlms/Unlit/src/OgreHlmsUnlit.cpp b/Components/Hlms/Unlit/src/OgreHlmsUnlit.cpp index e440614ded0..398dc0ca13f 100644 --- a/Components/Hlms/Unlit/src/OgreHlmsUnlit.cpp +++ b/Components/Hlms/Unlit/src/OgreHlmsUnlit.cpp @@ -709,7 +709,7 @@ namespace Ogre mListener->preparePassHash( shadowNode, casterPass, dualParaboloid, sceneManager, this ); PassCache passCache; - passCache.passPso = getPassPsoForScene( sceneManager ); + passCache.passPso = getPassPsoForScene( sceneManager, false ); passCache.properties = mT[kNoTid].setProperties; assert( mPassCache.size() <= (size_t)HlmsBits::PassMask && diff --git a/OgreMain/include/OgreHlms.h b/OgreMain/include/OgreHlms.h index ebbba3ea843..4c15ad6b2fe 100644 --- a/OgreMain/include/OgreHlms.h +++ b/OgreMain/include/OgreHlms.h @@ -547,7 +547,7 @@ namespace Ogre HlmsCache preparePassHashBase( const Ogre::CompositorShadowNode *shadowNode, bool casterPass, bool dualParaboloid, SceneManager *sceneManager ); - HlmsPassPso getPassPsoForScene( SceneManager *sceneManager ); + HlmsPassPso getPassPsoForScene( SceneManager *sceneManager, const bool bForceCullNone ); /// OpenGL sets texture binding slots from C++ /// All other APIs set the slots from shader. diff --git a/OgreMain/include/OgreHlmsPso.h b/OgreMain/include/OgreHlmsPso.h index e29259ebb01..29361a60635 100644 --- a/OgreMain/include/OgreHlmsPso.h +++ b/OgreMain/include/OgreHlmsPso.h @@ -111,6 +111,7 @@ namespace Ogre InvertVertexWinding = 1u << 1u, NoDepthBuffer = 1u << 2u, ForceDepthClamp = 1u << 3u, + ForceCullNone = 1u << 4u, // clang-format on }; }; diff --git a/OgreMain/src/OgreHlms.cpp b/OgreMain/src/OgreHlms.cpp index 347cc475603..8616551ce85 100644 --- a/OgreMain/src/OgreHlms.cpp +++ b/OgreMain/src/OgreHlms.cpp @@ -2230,6 +2230,9 @@ namespace Ogre prepassMacroblock.mCullMode = prepassMacroblock.mCullMode == CULL_CLOCKWISE ? CULL_ANTICLOCKWISE : CULL_CLOCKWISE; } + // We need to disable culling. + if( pso.pass.strongMacroblockBits & HlmsPassPso::ForceCullNone ) + prepassMacroblock.mCullMode = CULL_NONE; // Force depth clamp. Probably a directional shadow caster pass if( pso.pass.strongMacroblockBits & HlmsPassPso::ForceDepthClamp ) prepassMacroblock.mDepthClamp = true; @@ -2923,6 +2926,8 @@ namespace Ogre const CompositorPass *pass = sceneManager->getCurrentCompositorPass(); + bool bForceCullNone = false; + if( !casterPass ) { size_t numShadowMapLights = 0u; @@ -3165,6 +3170,7 @@ namespace Ogre static_cast( pass->getDefinition() ); if( passSceneDef->mUvBakingSet != 0xFF ) { + bForceCullNone = true; setProperty( kNoTid, HlmsBaseProp::UseUvBaking, 1 ); setProperty( kNoTid, HlmsBaseProp::UvBaking, passSceneDef->mUvBakingSet ); if( passSceneDef->mBakeLightingOnly ) @@ -3495,7 +3501,7 @@ namespace Ogre mListener->preparePassHash( shadowNode, casterPass, dualParaboloid, sceneManager, this ); PassCache passCache; - passCache.passPso = getPassPsoForScene( sceneManager ); + passCache.passPso = getPassPsoForScene( sceneManager, bForceCullNone ); passCache.properties = mT[kNoTid].setProperties; assert( mPassCache.size() <= HlmsBits::PassMask && @@ -3516,7 +3522,7 @@ namespace Ogre return retVal; } //----------------------------------------------------------------------------------- - HlmsPassPso Hlms::getPassPsoForScene( SceneManager *sceneManager ) + HlmsPassPso Hlms::getPassPsoForScene( SceneManager *sceneManager, const bool bForceCullNone ) { const RenderPassDescriptor *renderPassDesc = mRenderSystem->getCurrentPassDescriptor(); @@ -3564,6 +3570,9 @@ namespace Ogre if( sceneManager->getCamerasInProgress().renderingCamera->getNeedsDepthClamp() ) passPso.strongMacroblockBits |= HlmsPassPso::ForceDepthClamp; + if( bForceCullNone ) + passPso.strongMacroblockBits |= HlmsPassPso::ForceCullNone; + const bool invertVertexWinding = mRenderSystem->getInvertVertexWinding(); if( ( renderPassDesc->requiresTextureFlipping() && !invertVertexWinding ) ||