Skip to content

Commit

Permalink
Force cull mode NONE when baking lightmaps
Browse files Browse the repository at this point in the history
  • Loading branch information
darksylinc committed Dec 15, 2024
1 parent 2afdd8d commit ba6d3dc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Components/Hlms/Unlit/src/OgreHlmsUnlit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
2 changes: 1 addition & 1 deletion OgreMain/include/OgreHlms.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions OgreMain/include/OgreHlmsPso.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ namespace Ogre
InvertVertexWinding = 1u << 1u,
NoDepthBuffer = 1u << 2u,
ForceDepthClamp = 1u << 3u,
ForceCullNone = 1u << 4u,
// clang-format on
};
};
Expand Down
13 changes: 11 additions & 2 deletions OgreMain/src/OgreHlms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2923,6 +2926,8 @@ namespace Ogre

const CompositorPass *pass = sceneManager->getCurrentCompositorPass();

bool bForceCullNone = false;

if( !casterPass )
{
size_t numShadowMapLights = 0u;
Expand Down Expand Up @@ -3165,6 +3170,7 @@ namespace Ogre
static_cast<const CompositorPassSceneDef *>( pass->getDefinition() );
if( passSceneDef->mUvBakingSet != 0xFF )
{
bForceCullNone = true;
setProperty( kNoTid, HlmsBaseProp::UseUvBaking, 1 );
setProperty( kNoTid, HlmsBaseProp::UvBaking, passSceneDef->mUvBakingSet );
if( passSceneDef->mBakeLightingOnly )
Expand Down Expand Up @@ -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 &&
Expand All @@ -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();

Expand Down Expand Up @@ -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 ) ||
Expand Down

0 comments on commit ba6d3dc

Please sign in to comment.