From e90ee1b2ccf971f2947d4bb722dd43a84a33d7ea Mon Sep 17 00:00:00 2001 From: "Matias N. Goldberg" Date: Sun, 22 Dec 2024 13:23:00 -0300 Subject: [PATCH] Fix uninitialized texture in Sample_LocalCubemapsManualProbes 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. --- CMake/Templates/resources2.cfg.in | 4 +++ .../Pbs/include/Cubemaps/OgreCubemapProbe.h | 2 +- .../Pbs/src/Cubemaps/OgreCubemapProbe.cpp | 35 +++++++++++++------ .../Cubemaps/OgreParallaxCorrectedCubemap.cpp | 8 +++-- .../ImageVoxelizer/ImageVoxelizer.cpp | 7 +--- .../Tutorial_OpenVR/Tutorial_OpenVR.cpp | 1 - 6 files changed, 36 insertions(+), 21 deletions(-) diff --git a/CMake/Templates/resources2.cfg.in b/CMake/Templates/resources2.cfg.in index 3d7c952defb..a1c92eb8183 100644 --- a/CMake/Templates/resources2.cfg.in +++ b/CMake/Templates/resources2.cfg.in @@ -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 diff --git a/Components/Hlms/Pbs/include/Cubemaps/OgreCubemapProbe.h b/Components/Hlms/Pbs/include/Cubemaps/OgreCubemapProbe.h index b8ae94640d5..640f1d9ebff 100644 --- a/Components/Hlms/Pbs/include/Cubemaps/OgreCubemapProbe.h +++ b/Components/Hlms/Pbs/include/Cubemaps/OgreCubemapProbe.h @@ -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; } diff --git a/Components/Hlms/Pbs/src/Cubemaps/OgreCubemapProbe.cpp b/Components/Hlms/Pbs/src/Cubemaps/OgreCubemapProbe.cpp index 641ff7ae01b..91160dbf73b 100644 --- a/Components/Hlms/Pbs/src/Cubemaps/OgreCubemapProbe.cpp +++ b/Components/Hlms/Pbs/src/Cubemaps/OgreCubemapProbe.cpp @@ -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" @@ -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 ); } } @@ -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 ) diff --git a/Components/Hlms/Pbs/src/Cubemaps/OgreParallaxCorrectedCubemap.cpp b/Components/Hlms/Pbs/src/Cubemaps/OgreParallaxCorrectedCubemap.cpp index 54edb22d46a..7b71540e3ce 100644 --- a/Components/Hlms/Pbs/src/Cubemaps/OgreParallaxCorrectedCubemap.cpp +++ b/Components/Hlms/Pbs/src/Cubemaps/OgreParallaxCorrectedCubemap.cpp @@ -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 ); @@ -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(); @@ -930,6 +930,8 @@ namespace Ogre //----------------------------------------------------------------------------------- void ParallaxCorrectedCubemap::updateRender() { + HlmsManager *hlmsManager = mRoot->getHlmsManager(); + const uint32 oldVisibilityMask = mSceneManager->getVisibilityMask(); mSceneManager->setVisibilityMask( 0xffffffff ); @@ -939,7 +941,7 @@ namespace Ogre { setFinalProbeTo( i ); - mCollectedProbes[i]->_clearCubemap(); + mCollectedProbes[i]->_clearCubemap( hlmsManager ); for( int j = 0; j < mCollectedProbes[i]->mNumIterations; ++j ) { diff --git a/Samples/2.0/ApiUsage/ImageVoxelizer/ImageVoxelizer.cpp b/Samples/2.0/ApiUsage/ImageVoxelizer/ImageVoxelizer.cpp index d200fd3e1b9..480aaf04b4b 100644 --- a/Samples/2.0/ApiUsage/ImageVoxelizer/ImageVoxelizer.cpp +++ b/Samples/2.0/ApiUsage/ImageVoxelizer/ImageVoxelizer.cpp @@ -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", diff --git a/Samples/2.0/Tutorials/Tutorial_OpenVR/Tutorial_OpenVR.cpp b/Samples/2.0/Tutorials/Tutorial_OpenVR/Tutorial_OpenVR.cpp index 5afbbae0c74..2f5ef658fff 100644 --- a/Samples/2.0/Tutorials/Tutorial_OpenVR/Tutorial_OpenVR.cpp +++ b/Samples/2.0/Tutorials/Tutorial_OpenVR/Tutorial_OpenVR.cpp @@ -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" };