From b0e5dba5d0fac11b628cde7c961dd2cf6ff073ed Mon Sep 17 00:00:00 2001 From: Steffen Date: Fri, 17 Jul 2026 07:46:43 +0200 Subject: [PATCH 1/2] PBS: honour non-sRGB colour targets in the pass hash preparePassHash hardcodes hw_gamma_write=1, assuming every colour target is sRGB. On a UNORM swapchain the linear lighting result then lands raw in the target and displays gamma-crushed (a mid-albedo surface under a zenith sun reads ~0.03 instead of ~0.5). Derive the property from the current pass descriptor's first colour target instead: sRGB targets keep hardware conversion exactly as before, and non-sRGB targets engage the existing !hw_gamma_write template path, whose shader-side encode was already written for this case but unreachable. --- Components/Hlms/Pbs/src/OgreHlmsPbs.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Components/Hlms/Pbs/src/OgreHlmsPbs.cpp b/Components/Hlms/Pbs/src/OgreHlmsPbs.cpp index 3c1a2292f6d..c4ff32ec894 100644 --- a/Components/Hlms/Pbs/src/OgreHlmsPbs.cpp +++ b/Components/Hlms/Pbs/src/OgreHlmsPbs.cpp @@ -1848,7 +1848,21 @@ namespace Ogre const RenderSystemCapabilities *capabilities = mRenderSystem->getCapabilities(); setProperty( kNoTid, PbsProperty::HwGammaRead, capabilities->hasCapability( RSC_HW_GAMMA ) ); - setProperty( kNoTid, PbsProperty::HwGammaWrite, 1 ); + { + // Honour non-sRGB colour targets: without hardware gamma on write the + // shader must gamma-encode the linear lighting result itself (the + // !hw_gamma_write template path), otherwise PBS output lands raw in a + // UNORM target and displays crushed/dark. + bool hwGammaWrite = true; + const RenderPassDescriptor *colourPassDesc = mRenderSystem->getCurrentPassDescriptor(); + if( colourPassDesc && colourPassDesc->getNumColourEntries() > 0u && + colourPassDesc->mColour[0].texture ) + { + hwGammaWrite = PixelFormatGpuUtils::isSRgb( + colourPassDesc->mColour[0].texture->getPixelFormat() ); + } + setProperty( kNoTid, PbsProperty::HwGammaWrite, hwGammaWrite ? 1 : 0 ); + } retVal.setProperties = mT[kNoTid].setProperties; CamerasInProgress cameras = sceneManager->getCamerasInProgress(); From f0e8cff9075a635af387170e69c683d17a6e7c08 Mon Sep 17 00:00:00 2001 From: Steffen Date: Fri, 17 Jul 2026 16:20:05 +0200 Subject: [PATCH 2/2] Satisfy clang-format --- Components/Hlms/Pbs/src/OgreHlmsPbs.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Components/Hlms/Pbs/src/OgreHlmsPbs.cpp b/Components/Hlms/Pbs/src/OgreHlmsPbs.cpp index c4ff32ec894..c649d2ca5b8 100644 --- a/Components/Hlms/Pbs/src/OgreHlmsPbs.cpp +++ b/Components/Hlms/Pbs/src/OgreHlmsPbs.cpp @@ -1858,8 +1858,8 @@ namespace Ogre if( colourPassDesc && colourPassDesc->getNumColourEntries() > 0u && colourPassDesc->mColour[0].texture ) { - hwGammaWrite = PixelFormatGpuUtils::isSRgb( - colourPassDesc->mColour[0].texture->getPixelFormat() ); + hwGammaWrite = + PixelFormatGpuUtils::isSRgb( colourPassDesc->mColour[0].texture->getPixelFormat() ); } setProperty( kNoTid, PbsProperty::HwGammaWrite, hwGammaWrite ? 1 : 0 ); }