From 0feeab91ddb668f95242b6d6d631dea13739a5bb Mon Sep 17 00:00:00 2001 From: nillerusr Date: Sat, 16 Apr 2022 12:54:00 +0300 Subject: [PATCH] engine: fix hdr to ldr conversion --- appframework/sdlmgr.cpp | 4 ++-- engine/cmodel_bsp.cpp | 2 +- engine/l_studio.cpp | 8 ++++---- engine/modelloader.cpp | 12 ++++++------ game/client/detailobjectsystem.cpp | 2 +- game/client/viewpostprocess.cpp | 2 +- game/server/portal/portal_player.cpp | 8 ++++---- game/server/server_base.vpc | 2 +- materialsystem/shaderapidx9/hardwareconfig.cpp | 6 ++++-- materialsystem/shaderapidx9/shaderdevicedx8.cpp | 11 ++++++----- public/shaderapi/ishaderdynamic.h | 2 +- 11 files changed, 31 insertions(+), 28 deletions(-) diff --git a/appframework/sdlmgr.cpp b/appframework/sdlmgr.cpp index b92055f1..20a299c2 100644 --- a/appframework/sdlmgr.cpp +++ b/appframework/sdlmgr.cpp @@ -612,10 +612,10 @@ InitReturnVal_t CSDLMgr::Init() _eglGetDisplay = (t_eglGetDisplay)dlsym(l_egl, "eglGetDisplay"); _eglQueryString = (t_eglQueryString)dlsym(l_egl, "eglQueryString"); - if( _eglInitialize && _eglInitialize && _eglQueryString) + if( _eglInitialize && _eglInitialize && _eglQueryString ) { EGLDisplay display = _eglGetDisplay(EGL_DEFAULT_DISPLAY); - if( _eglInitialize(display, NULL, NULL) != -1 + if( _eglInitialize(display, NULL, NULL) != -1 && strstr(_eglQueryString(display, EGL_EXTENSIONS) ,"EGL_KHR_gl_colorspace") ) SET_GL_ATTR(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1) } diff --git a/engine/cmodel_bsp.cpp b/engine/cmodel_bsp.cpp index 8dfff86a..cdecce69 100644 --- a/engine/cmodel_bsp.cpp +++ b/engine/cmodel_bsp.cpp @@ -1110,7 +1110,7 @@ void CollisionBSPData_LoadDispInfo( CCollisionBSPData *pBSPData ) // get face data // int face_lump_to_load = LUMP_FACES; - if ( /*g_pMaterialSystemHardwareConfig->GetHDRType() != HDR_TYPE_NONE &&*/ + if ( g_pMaterialSystemHardwareConfig->GetHDREnabled() && /*g_pMaterialSystemHardwareConfig->GetHDRType() != HDR_TYPE_NONE &&*/ CMapLoadHelper::LumpSize( LUMP_FACES_HDR ) > 0 ) { face_lump_to_load = LUMP_FACES_HDR; diff --git a/engine/l_studio.cpp b/engine/l_studio.cpp index c0da11cd..f1bb594c 100644 --- a/engine/l_studio.cpp +++ b/engine/l_studio.cpp @@ -3637,7 +3637,7 @@ void CModelRender::ValidateStaticPropColorData( ModelInstanceHandle_t handle ) // fetch the header CUtlBuffer utlBuf; char fileName[MAX_PATH]; - if ( g_bBakedPropLightingNoSeparateHDR ) + if ( !g_pMaterialSystemHardwareConfig->GetHDREnabled() || g_bBakedPropLightingNoSeparateHDR ) { Q_snprintf( fileName, sizeof( fileName ), "sp_%d%s.vhv", StaticPropMgr()->GetStaticPropIndex( pProp ), GetPlatformExt() ); } @@ -3930,13 +3930,13 @@ bool CModelRender::LoadStaticPropColorData( IHandleEntity *pProp, DataCacheHandl // each static prop has its own compiled color mesh char fileName[MAX_PATH]; - if ( g_bBakedPropLightingNoSeparateHDR ) + if ( !g_pMaterialSystemHardwareConfig->GetHDREnabled() || g_bBakedPropLightingNoSeparateHDR ) { - Q_snprintf( fileName, sizeof( fileName ), "sp_%d%s.vhv", StaticPropMgr()->GetStaticPropIndex( pProp ), GetPlatformExt() ); + Q_snprintf( fileName, sizeof( fileName ), "sp_%d%s.vhv", StaticPropMgr()->GetStaticPropIndex( pProp ), GetPlatformExt() ); } else { - Q_snprintf( fileName, sizeof( fileName ), "sp_hdr_%d%s.vhv", StaticPropMgr()->GetStaticPropIndex( pProp ), GetPlatformExt() ); + Q_snprintf( fileName, sizeof( fileName ), "sp_hdr_%d%s.vhv", StaticPropMgr()->GetStaticPropIndex( pProp ), GetPlatformExt() ); } // mark as invalid, async callback will set upon completion diff --git a/engine/modelloader.cpp b/engine/modelloader.cpp index 6bb5d2c8..58ffea68 100644 --- a/engine/modelloader.cpp +++ b/engine/modelloader.cpp @@ -1038,7 +1038,7 @@ bool Map_CheckForHDR( model_t *pModel, const char *pLoadName ) } bool bEnableHDR = ( IsX360() && bHasHDR ) || - ( bHasHDR && ( mat_hdr_level.GetInt() >= 2 ) && + ( bHasHDR && ( g_pMaterialSystemHardwareConfig->GetDXSupportLevel() >= 90 ) ); EnableHDR( bEnableHDR ); @@ -1856,7 +1856,7 @@ void Mod_LoadFaces( void ) int ti, di; int face_lump_to_load = LUMP_FACES; - if ( CMapLoadHelper::LumpSize( LUMP_FACES_HDR ) > 0 ) + if ( g_pMaterialSystemHardwareConfig->GetHDREnabled() && CMapLoadHelper::LumpSize( LUMP_FACES_HDR ) > 0 ) { face_lump_to_load = LUMP_FACES_HDR; } @@ -2288,7 +2288,7 @@ void Mod_LoadLeafs( void ) Mod_LoadLeafs_Version_0( lh ); break; case 1: - if( CMapLoadHelper::LumpSize( LUMP_LEAF_AMBIENT_LIGHTING_HDR ) > 0 ) + if( g_pMaterialSystemHardwareConfig->GetHDREnabled() && CMapLoadHelper::LumpSize( LUMP_LEAF_AMBIENT_LIGHTING_HDR ) > 0 ) { CMapLoadHelper mlh( LUMP_LEAF_AMBIENT_LIGHTING_HDR ); CMapLoadHelper mlhTable( LUMP_LEAF_AMBIENT_INDEX_HDR ); @@ -2383,7 +2383,7 @@ void Mod_LoadCubemapSamples( void ) lh.GetMap()->m_pCubemapSamples = out; lh.GetMap()->m_nCubemapSamples = count; - bool bHDR = true; //g_pMaterialSystemHardwareConfig->GetHDRType() != HDR_TYPE_NONE; + bool bHDR = g_pMaterialSystemHardwareConfig->GetHDREnabled(); //g_pMaterialSystemHardwareConfig->GetHDRType() != HDR_TYPE_NONE; int nCreateFlags = bHDR ? 0 : TEXTUREFLAGS_SRGB; // We have separate HDR versions of the textures. In order to deal with this, @@ -4451,7 +4451,7 @@ void CModelLoader::Map_LoadModel( model_t *mod ) // Until BSP version 19, this must occur after loading texinfo COM_TimestampedLog( " Mod_LoadLighting" ); - if ( CMapLoadHelper::LumpSize( LUMP_LIGHTING_HDR ) > 0 ) + if ( g_pMaterialSystemHardwareConfig->GetHDREnabled() && CMapLoadHelper::LumpSize( LUMP_LIGHTING_HDR ) > 0 ) { CMapLoadHelper mlh( LUMP_LIGHTING_HDR ); Mod_LoadLighting( mlh ); @@ -4543,7 +4543,7 @@ void CModelLoader::Map_LoadModel( model_t *mod ) &m_worldBrushData.m_nAreas ); COM_TimestampedLog( " Mod_LoadWorldlights" ); - if ( CMapLoadHelper::LumpSize( LUMP_WORLDLIGHTS_HDR ) > 0 ) + if ( g_pMaterialSystemHardwareConfig->GetHDREnabled() && CMapLoadHelper::LumpSize( LUMP_WORLDLIGHTS_HDR ) > 0 ) { CMapLoadHelper mlh( LUMP_WORLDLIGHTS_HDR ); Mod_LoadWorldlights( mlh, true ); diff --git a/game/client/detailobjectsystem.cpp b/game/client/detailobjectsystem.cpp index 3e211bb0..8acac352 100644 --- a/game/client/detailobjectsystem.cpp +++ b/game/client/detailobjectsystem.cpp @@ -1491,7 +1491,7 @@ void CDetailObjectSystem::LevelInitPreEntity() } int detailPropLightingLump; - if( g_pMaterialSystemHardwareConfig->GetHDRType() != HDR_TYPE_NONE ) + if( g_pMaterialSystemHardwareConfig->GetHDREnabled() ) { detailPropLightingLump = GAMELUMP_DETAIL_PROP_LIGHTING_HDR; } diff --git a/game/client/viewpostprocess.cpp b/game/client/viewpostprocess.cpp index 39c2237e..6048209e 100644 --- a/game/client/viewpostprocess.cpp +++ b/game/client/viewpostprocess.cpp @@ -1460,7 +1460,7 @@ static float GetBloomAmount( void ) if ( hdrType == HDR_TYPE_NONE ) { - flBloomAmount *= mat_non_hdr_bloom_scalefactor.GetFloat(); + flBloomAmount *= mat_non_hdr_bloom_scalefactor.GetFloat()/2.f; } flBloomAmount *= mat_bloom_scalefactor_scalar.GetFloat(); diff --git a/game/server/portal/portal_player.cpp b/game/server/portal/portal_player.cpp index 72cc063f..a72e2e94 100644 --- a/game/server/portal/portal_player.cpp +++ b/game/server/portal/portal_player.cpp @@ -549,15 +549,15 @@ void CPortal_Player::UpdateExpression( void ) GetExpresser()->SetOuter( this ); ClearExpression(); - AI_Response response; - bool result = SpeakFindResponse( response, g_pszChellConcepts[iConcept] ); - if ( !result ) + AI_Response *response = SpeakFindResponse( g_pszChellConcepts[iConcept] ); + if ( !response ) { m_flExpressionLoopTime = gpGlobals->curtime + RandomFloat(30,40); return; } - char const *szScene = response.GetResponsePtr(); + char const szScene[256]; + response->GetResponse( szScene, sizeof(szScene) ); // Ignore updates that choose the same scene if ( m_iszExpressionScene != NULL_STRING && stricmp( STRING(m_iszExpressionScene), szScene ) == 0 ) diff --git a/game/server/server_base.vpc b/game/server/server_base.vpc index f1c3c835..73e3608f 100644 --- a/game/server/server_base.vpc +++ b/game/server/server_base.vpc @@ -52,7 +52,7 @@ $Configuration $Compiler { $AdditionalIncludeDirectories "$BASE;.\;$SRCDIR\game\shared;$SRCDIR\utils\common;$SRCDIR\game\shared\econ;$SRCDIR\game\server\NextBot" - $PreprocessorDefinitions "$BASE;GAME_DLL;VECTOR;VERSION_SAFE_STEAM_API_INTERFACES;PROTECTED_THINGS_ENABLE;sprintf=use_Q_snprintf_instead_of_sprintf;strncpy=use_Q_strncpy_instead;_snprintf=use_Q_snprintf_instead" + $PreprocessorDefinitions "$BASE;GAME_DLL;VECTOR;VERSION_SAFE_STEAM_API_INTERFACES;PROTECTED_THINGS_ENABLE;strncpy=use_Q_strncpy_instead;_snprintf=use_Q_snprintf_instead" $PreprocessorDefinitions "$BASE;SWDS" [$POSIX] $PreprocessorDefinitions "$BASE;fopen=dont_use_fopen" [$WINDOWS||$X360] $Create/UsePrecompiledHeader "Use Precompiled Header (/Yu)" diff --git a/materialsystem/shaderapidx9/hardwareconfig.cpp b/materialsystem/shaderapidx9/hardwareconfig.cpp index 133be43e..f7c757a3 100644 --- a/materialsystem/shaderapidx9/hardwareconfig.cpp +++ b/materialsystem/shaderapidx9/hardwareconfig.cpp @@ -24,6 +24,8 @@ static CHardwareConfig s_HardwareConfig; CHardwareConfig *g_pHardwareConfig = &s_HardwareConfig; +extern ConVar mat_hdr_level; + EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CHardwareConfig, IMaterialSystemHardwareConfig, MATERIALSYSTEM_HARDWARECONFIG_INTERFACE_VERSION, s_HardwareConfig ) @@ -1238,12 +1240,12 @@ int CHardwareConfig::GetMaxVertexTextureDimension() const HDRType_t CHardwareConfig::GetHDRType() const { - bool enabled = m_bHDREnabled; + bool enabled = (mat_hdr_level.GetInt() >= 2) && GetHDREnabled(); int dxlev = GetDXSupportLevel(); int dxsupp = dxlev >= 90; HDRType_t caps_hdr = m_Caps.m_HDRType; HDRType_t result = HDR_TYPE_NONE; - + //printf("\nCHardwareConfig::GetHDRType..."); if (enabled) { diff --git a/materialsystem/shaderapidx9/shaderdevicedx8.cpp b/materialsystem/shaderapidx9/shaderdevicedx8.cpp index cdd59c50..328a1ea3 100644 --- a/materialsystem/shaderapidx9/shaderdevicedx8.cpp +++ b/materialsystem/shaderapidx9/shaderdevicedx8.cpp @@ -939,10 +939,6 @@ bool CShaderDeviceMgrDx8::ComputeCapsFromD3D( HardwareCaps_t *pCaps, int nAdapte D3DFMT_X8R8G8B8, D3DUSAGE_QUERY_FILTER, D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16 ) == S_OK ); -#ifdef TOGLES - bSupportsInteger16Textures = caps.SupportInt16Format; -#endif - // Does the device support filterable fp16 textures? bool bSupportsFloat16Textures = ( D3D()->CheckDeviceFormat( nAdapter, DX8_DEVTYPE, @@ -1051,6 +1047,11 @@ bool CShaderDeviceMgrDx8::ComputeCapsFromD3D( HardwareCaps_t *pCaps, int nAdapte } } + +#ifdef TOGLES + bSupportsInteger16Textures = caps.SupportInt16Format; +#endif + // Do we have everything necessary to run with integer HDR? Note that // even if we don't support integer 16-bit/component textures, we // can still run in this mode if fp16 textures are supported. @@ -1058,7 +1059,7 @@ bool CShaderDeviceMgrDx8::ComputeCapsFromD3D( HardwareCaps_t *pCaps, int nAdapte pCaps->m_SupportsVertexShaders_2_0 && // (caps.Caps3 & D3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD) && // (caps.PrimitiveMiscCaps & D3DPMISCCAPS_SEPARATEALPHABLEND) && - ( bSupportsInteger16Textures || bSupportsFloat16Textures ) && + bSupportsInteger16Textures && pCaps->m_SupportsSRGB; // Do we have everything necessary to run with float HDR? diff --git a/public/shaderapi/ishaderdynamic.h b/public/shaderapi/ishaderdynamic.h index d8718c42..49237ad5 100644 --- a/public/shaderapi/ishaderdynamic.h +++ b/public/shaderapi/ishaderdynamic.h @@ -36,7 +36,7 @@ struct LightState_t { int m_nNumLights; bool m_bAmbientLight; - bool m_bStaticLight; + bool m_bStaticLightTexel; bool m_bStaticLightVertex; inline int HasDynamicLight() { return (m_bAmbientLight || (m_nNumLights > 0)) ? 1 : 0; } };