Skip to content

Commit

Permalink
Fix uninitialized texture in Sample_LocalCubemapsManualProbes
Browse files Browse the repository at this point in the history
When using PCC (the original version, not the Auto/per-pixel one) and
manually assigning cubemaps to materials the routine
CubemapProbe::_clearCubemap would clear the wrong texture.

It would clear the temporary RTT (which is used to avoid a GPU feedback
loop i.e. rendering and sampling to/from same texture) instead of the
real cubemap texture.

The still-uninitialized cubemap texture would then be copied to the
proxy PCC cubemap; and then the temporary RTT cubemap would be rendered
normally, using the uninitialized proxy PCC; causing artifacts.

If Compute Shaders are supported, the cubemap texture must be cleared
using Cubemap textures, which is why now Compute/Tools folder was added
to resources2.cfg file so the necessary Compute Shaders are available.
  • Loading branch information
darksylinc committed Dec 22, 2024
1 parent 003e11c commit e90ee1b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CMake/Templates/resources2.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ FileSystem=@OGRE_MEDIA_DIR_REL@/Hlms/Common/HLSL
FileSystem=@OGRE_MEDIA_DIR_REL@/Hlms/Common/Metal
FileSystem=@OGRE_MEDIA_DIR_REL@/Compute/Algorithms/IBL
FileSystem=@OGRE_MEDIA_DIR_REL@/Compute/Tools/Any
FileSystem=@OGRE_MEDIA_DIR_REL@/Compute/Tools/GLSL
FileSystem=@OGRE_MEDIA_DIR_REL@/Compute/Tools/HLSL
FileSystem=@OGRE_MEDIA_DIR_REL@/Compute/Tools/Metal
FileSystem=@OGRE_MEDIA_DIR_REL@/Compute/Tools

# Do not load this as a resource. It's here merely to tell the code where
# the Hlms templates are located
Expand Down
2 changes: 1 addition & 1 deletion Components/Hlms/Pbs/include/Cubemaps/OgreCubemapProbe.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ namespace Ogre
Real getNDF( const Vector3 &posLS ) const;

void _prepareForRendering();
void _clearCubemap();
void _clearCubemap( HlmsManager *hlmsManager );
void _updateRender();

const Vector3 &getProbeCameraPos() const { return mProbeCameraPos; }
Expand Down
35 changes: 25 additions & 10 deletions Components/Hlms/Pbs/src/Cubemaps/OgreCubemapProbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ THE SOFTWARE.

#include "Compositor/OgreCompositorManager2.h"
#include "Compositor/OgreCompositorWorkspace.h"
#include "Compute/OgreComputeTools.h"
#include "Cubemaps/OgreParallaxCorrectedCubemap.h"
#include "Cubemaps/OgreParallaxCorrectedCubemapBase.h"
#include "OgreCamera.h"
#include "OgreHlmsManager.h"
#include "OgreId.h"
#include "OgreInternalCubemapProbe.h"
#include "OgreLogManager.h"
Expand Down Expand Up @@ -438,10 +440,10 @@ namespace Ogre
(ResourceStatusMap *)0, Vector4::ZERO, 0x00, executionMask );
mWorkspace->addListener( mCreator );

if( !mStatic && !mCreator->getAutomaticMode() )
if( !mStatic && !mCreator->getAutomaticMode() && mTexture->isRenderToTexture() )
{
mClearWorkspace = compositorManager->addWorkspace(
sceneManager, channels, mCamera, "AutoGen_ParallaxCorrectedCubemapClear_Workspace",
sceneManager, mTexture, mCamera, "AutoGen_ParallaxCorrectedCubemapClear_Workspace",
false );
}
}
Expand Down Expand Up @@ -554,18 +556,31 @@ namespace Ogre
}
}
//-----------------------------------------------------------------------------------
void CubemapProbe::_clearCubemap()
void CubemapProbe::_clearCubemap( HlmsManager *hlmsManager )
{
if( !mClearWorkspace && mWorkspace )
{
CompositorWorkspaceDef const *workspaceDef = mCreator->getDefaultWorkspaceDef();
CompositorManager2 *compositorManager = workspaceDef->getCompositorManager();
if( mTexture->isRenderToTexture() )
{
CompositorWorkspaceDef const *workspaceDef = mCreator->getDefaultWorkspaceDef();
CompositorManager2 *compositorManager = workspaceDef->getCompositorManager();

SceneManager *sceneManager = mCreator->getSceneManager();
CompositorChannelVec channels( mWorkspace->getExternalRenderTargets() );
mClearWorkspace = compositorManager->addWorkspace(
sceneManager, channels, mCamera, "AutoGen_ParallaxCorrectedCubemapClear_Workspace",
false );
SceneManager *sceneManager = mCreator->getSceneManager();
mClearWorkspace = compositorManager->addWorkspace(
sceneManager, mTexture, mCamera, "AutoGen_ParallaxCorrectedCubemapClear_Workspace",
false );
}
else
{
ComputeTools computeTools( hlmsManager->getComputeHlms() );
const float clearValue[4] = {
0.0f,
0.0f,
0.0f,
0.0f,
};
computeTools.clearUavFloat( mTexture, clearValue );
}
}

if( !mClearWorkspace )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ namespace Ogre
void ParallaxCorrectedCubemap::updateExpensiveCollectedDirtyProbes( uint16 iterationThreshold )
{
RenderSystem *renderSystem = mSceneManager->getDestinationRenderSystem();
// HlmsManager *hlmsManager = mRoot->getHlmsManager();
HlmsManager *hlmsManager = mRoot->getHlmsManager();

const uint32 oldVisibilityMask = mSceneManager->getVisibilityMask();
mSceneManager->setVisibilityMask( 0xffffffff );
Expand All @@ -906,7 +906,7 @@ namespace Ogre
renderSystem->_beginFrameOnce();
mCopyWorkspace->_beginUpdate( true );
if( j == 0 )
mCollectedProbes[i]->_clearCubemap();
mCollectedProbes[i]->_clearCubemap( hlmsManager );
mCopyWorkspace->_update();
transitionBlendResultToTexture();
mCollectedProbes[i]->_updateRender();
Expand All @@ -930,6 +930,8 @@ namespace Ogre
//-----------------------------------------------------------------------------------
void ParallaxCorrectedCubemap::updateRender()
{
HlmsManager *hlmsManager = mRoot->getHlmsManager();

const uint32 oldVisibilityMask = mSceneManager->getVisibilityMask();
mSceneManager->setVisibilityMask( 0xffffffff );

Expand All @@ -939,7 +941,7 @@ namespace Ogre
{
setFinalProbeTo( i );

mCollectedProbes[i]->_clearCubemap();
mCollectedProbes[i]->_clearCubemap( hlmsManager );

for( int j = 0; j < mCollectedProbes[i]->mNumIterations; ++j )
{
Expand Down
7 changes: 1 addition & 6 deletions Samples/2.0/ApiUsage/ImageVoxelizer/ImageVoxelizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ namespace Demo
else if( *( originalDataFolder.end() - 1 ) != '/' )
originalDataFolder += "/";

const char *c_locations[] = { "Compute/Tools",
"Compute/Tools/Any",
"Compute/Tools/GLSL",
"Compute/Tools/HLSL",
"Compute/Tools/Metal",
"Compute/Algorithms/IrradianceFields",
const char *c_locations[] = { "Compute/Algorithms/IrradianceFields",
"Compute/Algorithms/IrradianceFields/Visualizer",
"VCT",
"VCT/ImageVoxelizer",
Expand Down
1 change: 0 additions & 1 deletion Samples/2.0/Tutorials/Tutorial_OpenVR/Tutorial_OpenVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ namespace Demo
const char *c_locations[] = { "Hlms/Common/GLSL",
"Hlms/Common/HLSL",
"Hlms/Common/Metal",
"Compute/Tools/Any",
"Compute/VR",
"Compute/VR/Foveated",
"2.0/scripts/materials/PbsMaterials" };
Expand Down

0 comments on commit e90ee1b

Please sign in to comment.