From 03c5e0273b7ae91a394df6ccef894a1a5a39ee24 Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Sun, 18 Apr 2021 21:20:29 +0200 Subject: [PATCH] Small bugfixes and r_useHDR 1 is now fixed for OpenGL --- .../lighting/ambient_lightgrid_IBL.ps.hlsl | 9 ++++- .../lighting/ambient_lighting_IBL.ps.hlsl | 7 ++-- neo/renderer/OpenGL/Image_GL.cpp | 39 +++++++------------ neo/renderer/OpenGL/RenderBackend_GL.cpp | 35 ----------------- neo/renderer/RenderCommon.h | 9 ++++- neo/renderer/RenderSystem.h | 1 - neo/renderer/RenderSystem_init.cpp | 5 +-- neo/renderer/RenderWorld_lightgrid.cpp | 38 ++++++++++++++++-- neo/renderer/RenderWorld_local.h | 2 + 9 files changed, 73 insertions(+), 72 deletions(-) diff --git a/base/renderprogs/builtin/lighting/ambient_lightgrid_IBL.ps.hlsl b/base/renderprogs/builtin/lighting/ambient_lightgrid_IBL.ps.hlsl index 365cc2f2..0a330fcc 100644 --- a/base/renderprogs/builtin/lighting/ambient_lightgrid_IBL.ps.hlsl +++ b/base/renderprogs/builtin/lighting/ambient_lightgrid_IBL.ps.hlsl @@ -150,7 +150,7 @@ void main( PS_IN fragment, out PS_OUT result ) float3 reflectionVector = globalNormal * dot3( globalView, globalNormal ); reflectionVector = normalize( ( reflectionVector * 2.0f ) - globalView ); -#if 1 +#if 0 // parallax box correction using portal area bounds float hitScale = 0.0; float3 bounds[2]; @@ -368,6 +368,12 @@ void main( PS_IN fragment, out PS_OUT result ) float3 radiance = textureLod( samp8, normalizedOctCoordZeroOne, mip ).rgb; //radiance = float3( 0.0 ); + // RB: HACK dim down room radiance by better local irradiance brightness + //float luma = PhotoLuma( irradiance ); + //float luma = dot( irradiance, LUMINANCE_LINEAR.rgb ); + //float luma = length( irradiance.rgb ); + //radiance *= ( luma * rpSpecularModifier.x * 3.0 ); + float2 envBRDF = texture( samp3, float2( max( vDotN, 0.0 ), roughness ) ).rg; #if 0 @@ -388,6 +394,7 @@ void main( PS_IN fragment, out PS_OUT result ) #endif half3 lightColor = sRGBToLinearRGB( rpAmbientColor.rgb ); + //half3 lightColor = ( rpAmbientColor.rgb ); //result.color.rgb = diffuseLight; //result.color.rgb = diffuseLight * lightColor; diff --git a/base/renderprogs/builtin/lighting/ambient_lighting_IBL.ps.hlsl b/base/renderprogs/builtin/lighting/ambient_lighting_IBL.ps.hlsl index 981c9ded..582324ec 100644 --- a/base/renderprogs/builtin/lighting/ambient_lighting_IBL.ps.hlsl +++ b/base/renderprogs/builtin/lighting/ambient_lighting_IBL.ps.hlsl @@ -150,7 +150,7 @@ void main( PS_IN fragment, out PS_OUT result ) float3 reflectionVector = globalNormal * dot3( globalView, globalNormal ); reflectionVector = normalize( ( reflectionVector * 2.0f ) - globalView ); -#if 1 +#if 0 // parallax box correction using portal area bounds float hitScale = 0.0; float3 bounds[2]; @@ -266,7 +266,7 @@ void main( PS_IN fragment, out PS_OUT result ) float specAO = ComputeSpecularAO( vDotN, ao, roughness ); float3 specularLight = radiance * ( kS * envBRDF.x + float3( envBRDF.y ) ) * specAO * ( rpSpecularModifier.xyz * 0.5 ); -#if 0 +#if 1 // Marmoset Horizon Fade trick const half horizonFade = 1.3; half horiz = saturate( 1.0 + horizonFade * saturate( dot3( reflectionVector, globalNormal ) ) ); @@ -275,11 +275,12 @@ void main( PS_IN fragment, out PS_OUT result ) #endif half3 lightColor = sRGBToLinearRGB( rpAmbientColor.rgb ); + //half3 lightColor = ( rpAmbientColor.rgb ); //result.color.rgb = diffuseLight; //result.color.rgb = diffuseLight * lightColor; //result.color.rgb = specularLight; - result.color.rgb = ( diffuseLight + specularLight ) * lightColor * fragment.color.rgb; + result.color.rgb = ( diffuseLight + specularLight * horiz ) * lightColor * fragment.color.rgb; //result.color.rgb = localNormal.xyz * 0.5 + 0.5; //result.color.rgb = float3( ao ); result.color.w = fragment.color.a; diff --git a/neo/renderer/OpenGL/Image_GL.cpp b/neo/renderer/OpenGL/Image_GL.cpp index 80a8dad4..ac447078 100644 --- a/neo/renderer/OpenGL/Image_GL.cpp +++ b/neo/renderer/OpenGL/Image_GL.cpp @@ -615,70 +615,62 @@ void idImage::AllocImage() GL_CheckErrors(); PurgeImage(); - int sRGB = r_useSRGB.GetInteger(); - switch( opts.format ) { case FMT_RGBA8: - //internalFormat = GL_RGBA8; - //internalFormat = ( glConfig.sRGBFramebufferAvailable && ( sRGB == 1 || sRGB == 3 ) ) ? GL_SRGB8_ALPHA8 : GL_RGBA8; - internalFormat = ( glConfig.sRGBFramebufferAvailable && ( sRGB == 1 || sRGB == 3 ) ) ? GL_SRGB8_ALPHA8 : GL_RGBA8; + internalFormat = GL_RGBA8; dataFormat = GL_RGBA; dataType = GL_UNSIGNED_BYTE; break; + case FMT_XRGB8: - internalFormat = ( glConfig.sRGBFramebufferAvailable && ( sRGB == 1 || sRGB == 3 ) ) ? GL_SRGB : GL_RGB; + internalFormat = GL_RGB; dataFormat = GL_RGBA; dataType = GL_UNSIGNED_BYTE; break; + case FMT_RGB565: - //internalFormat = ( glConfig.sRGBFramebufferAvailable && ( sRGB == 1 || sRGB == 3 ) ) ? GL_SRGB : GL_RGB; internalFormat = GL_RGB; dataFormat = GL_RGB; dataType = GL_UNSIGNED_SHORT_5_6_5; break; + case FMT_ALPHA: -#if 1 - if( ( glConfig.sRGBFramebufferAvailable && ( sRGB == 1 || sRGB == 3 ) ) ) - { - internalFormat = GL_SRGB; - dataFormat = GL_RED; - } - else -#endif - { - internalFormat = GL_R8; - dataFormat = GL_RED; - } + internalFormat = GL_R8; + dataFormat = GL_RED; dataType = GL_UNSIGNED_BYTE; break; + case FMT_L8A8: internalFormat = GL_RG8; dataFormat = GL_RG; dataType = GL_UNSIGNED_BYTE; break; + case FMT_LUM8: internalFormat = GL_R8; dataFormat = GL_RED; dataType = GL_UNSIGNED_BYTE; break; + case FMT_INT8: internalFormat = GL_R8; dataFormat = GL_RED; dataType = GL_UNSIGNED_BYTE; break; + case FMT_DXT1: - internalFormat = ( glConfig.sRGBFramebufferAvailable && ( sRGB == 1 || sRGB == 3 ) ) ? GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT : GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; - //internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; + internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; dataFormat = GL_RGBA; dataType = GL_UNSIGNED_BYTE; break; + case FMT_DXT5: - internalFormat = ( glConfig.sRGBFramebufferAvailable && ( sRGB == 1 || sRGB == 3 ) && opts.colorFormat != CFM_YCOCG_DXT5 && opts.colorFormat != CFM_NORMAL_DXT5 ) ? GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT : GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; - //internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; dataFormat = GL_RGBA; dataType = GL_UNSIGNED_BYTE; break; + case FMT_DEPTH: internalFormat = GL_DEPTH_COMPONENT; dataFormat = GL_DEPTH_COMPONENT; @@ -731,7 +723,6 @@ void idImage::AllocImage() internalFormat = GL_R11F_G11F_B10F; dataFormat = GL_RGB; dataType = GL_UNSIGNED_INT_10F_11F_11F_REV; - //dataType = GL_FLOAT; break; default: diff --git a/neo/renderer/OpenGL/RenderBackend_GL.cpp b/neo/renderer/OpenGL/RenderBackend_GL.cpp index 0329538f..2700a2e1 100644 --- a/neo/renderer/OpenGL/RenderBackend_GL.cpp +++ b/neo/renderer/OpenGL/RenderBackend_GL.cpp @@ -263,10 +263,6 @@ static void R_CheckPortableExtensions() glConfig.seamlessCubeMapAvailable = GLEW_ARB_seamless_cube_map != 0; r_useSeamlessCubeMap.SetModified(); // the CheckCvars() next frame will enable / disable it - // GL_ARB_framebuffer_sRGB - glConfig.sRGBFramebufferAvailable = GLEW_ARB_framebuffer_sRGB != 0; - r_useSRGB.SetModified(); // the CheckCvars() next frame will enable / disable it - // GL_ARB_vertex_buffer_object if( glConfig.driverType == GLDRV_OPENGL_MESA_CORE_PROFILE ) { @@ -1407,21 +1403,6 @@ void idRenderBackend::GL_Clear( bool color, bool depth, bool stencil, byte stenc glClear( clearFlags ); // RB begin - /* - if( r_useHDR.GetBool() && clearHDR && globalFramebuffers.hdrFBO != NULL ) - { - bool isDefaultFramebufferActive = Framebuffer::IsDefaultFramebufferActive(); - - globalFramebuffers.hdrFBO->Bind(); - glClear( clearFlags ); - - if( isDefaultFramebufferActive ) - { - Framebuffer::Unbind(); - } - } - */ - if( r_useHDR.GetBool() && clearHDR ) { bool isDefaultFramebufferActive = Framebuffer::IsDefaultFramebufferActive(); @@ -1518,22 +1499,6 @@ void idRenderBackend::CheckCVars() } } - if( r_useSRGB.IsModified() ) - { - r_useSRGB.ClearModified(); - if( glConfig.sRGBFramebufferAvailable ) - { - if( r_useSRGB.GetBool() && r_useSRGB.GetInteger() != 3 ) - { - glEnable( GL_FRAMEBUFFER_SRGB ); - } - else - { - glDisable( GL_FRAMEBUFFER_SRGB ); - } - } - } - if( r_antiAliasing.IsModified() ) { switch( r_antiAliasing.GetInteger() ) diff --git a/neo/renderer/RenderCommon.h b/neo/renderer/RenderCommon.h index fe4dc241..4745e649 100644 --- a/neo/renderer/RenderCommon.h +++ b/neo/renderer/RenderCommon.h @@ -1058,7 +1058,6 @@ extern idCVar r_useShadowDepthBounds; // use depth bounds test on individual sh extern idCVar r_useShadowMapping; // use shadow mapping instead of stencil shadows extern idCVar r_useHalfLambertLighting; // use Half-Lambert lighting instead of classic Lambert extern idCVar r_useHDR; -extern idCVar r_useSRGB; extern idCVar r_useSeamlessCubeMap; // RB end @@ -1451,6 +1450,14 @@ public: tics = 0; nextTicCount = 0; } + + void Reset( int expected ) + { + expectedCount = expected; + count = 0; + tics = 0; + nextTicCount = 0; + } }; /* diff --git a/neo/renderer/RenderSystem.h b/neo/renderer/RenderSystem.h index 4db32ab6..88fcfa18 100644 --- a/neo/renderer/RenderSystem.h +++ b/neo/renderer/RenderSystem.h @@ -199,7 +199,6 @@ struct glconfig_t bool anisotropicFilterAvailable; bool textureLODBiasAvailable; bool seamlessCubeMapAvailable; - bool sRGBFramebufferAvailable; bool vertexBufferObjectAvailable; bool mapBufferRangeAvailable; bool vertexArrayObjectAvailable; diff --git a/neo/renderer/RenderSystem_init.cpp b/neo/renderer/RenderSystem_init.cpp index 73efde88..4b5ac273 100644 --- a/neo/renderer/RenderSystem_init.cpp +++ b/neo/renderer/RenderSystem_init.cpp @@ -86,7 +86,6 @@ idCVar r_useNodeCommonChildren( "r_useNodeCommonChildren", "1", CVAR_RENDERER | idCVar r_useShadowSurfaceScissor( "r_useShadowSurfaceScissor", "1", CVAR_RENDERER | CVAR_BOOL, "scissor shadows by the scissor rect of the interaction surfaces" ); idCVar r_useCachedDynamicModels( "r_useCachedDynamicModels", "1", CVAR_RENDERER | CVAR_BOOL, "cache snapshots of dynamic models" ); idCVar r_useSeamlessCubeMap( "r_useSeamlessCubeMap", "1", CVAR_RENDERER | CVAR_BOOL, "use ARB_seamless_cube_map if available" ); -idCVar r_useSRGB( "r_useSRGB", "0", CVAR_RENDERER | CVAR_INTEGER | CVAR_ARCHIVE, "1 = both texture and framebuffer, 2 = framebuffer only, 3 = texture only" ); idCVar r_maxAnisotropicFiltering( "r_maxAnisotropicFiltering", "8", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_INTEGER, "limit aniso filtering" ); idCVar r_useTrilinearFiltering( "r_useTrilinearFiltering", "1", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_BOOL, "Extra quality filtering" ); // RB: not used anymore @@ -262,9 +261,9 @@ idCVar r_shadowMapSunDepthBiasScale( "r_shadowMapSunDepthBiasScale", "0.999991", // RB: HDR parameters #if defined( USE_VULKAN ) - idCVar r_useHDR( "r_useHDR", "0", CVAR_RENDERER | CVAR_ROM | CVAR_STATIC | CVAR_BOOL, "use high dynamic range rendering" ); + idCVar r_useHDR( "r_useHDR", "0", CVAR_RENDERER | CVAR_ROM | CVAR_STATIC | CVAR_BOOL, "Can't be changed, is broken on Vulkan backend" ); #else - idCVar r_useHDR( "r_useHDR", "1", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_BOOL, "use high dynamic range rendering" ); + idCVar r_useHDR( "r_useHDR", "1", CVAR_RENDERER | CVAR_ROM | CVAR_STATIC | CVAR_BOOL, "Can't be changed: Use high dynamic range rendering" ); #endif idCVar r_hdrAutoExposure( "r_hdrAutoExposure", "0", CVAR_RENDERER | CVAR_BOOL, "EXPENSIVE: enables adapative HDR tone mapping otherwise the exposure is derived by r_exposure" ); diff --git a/neo/renderer/RenderWorld_lightgrid.cpp b/neo/renderer/RenderWorld_lightgrid.cpp index 0bed4604..9ac2039d 100644 --- a/neo/renderer/RenderWorld_lightgrid.cpp +++ b/neo/renderer/RenderWorld_lightgrid.cpp @@ -95,7 +95,7 @@ void LightGrid::SetupLightGrid( const idBounds& bounds, const char* mapName, con { lightGridPoints.SetNum( numGridPoints ); - idLib::Printf( "area %i (%i x %i x %i) = %i grid points \n", area, lightGridBounds[0], lightGridBounds[1], lightGridBounds[2], numGridPoints ); + idLib::Printf( "\narea %i (%i x %i x %i) = %i grid points \n", area, lightGridBounds[0], lightGridBounds[1], lightGridBounds[2], numGridPoints ); idLib::Printf( "area %i grid size (%i %i %i)\n", area, ( int )lightGridSize[0], ( int )lightGridSize[1], ( int )lightGridSize[2] ); idLib::Printf( "area %i grid bounds (%i %i %i)\n", area, ( int )lightGridBounds[0], ( int )lightGridBounds[1], ( int )lightGridBounds[2] ); idLib::Printf( "area %i %9u x %" PRIuSIZE " = lightGridSize = (%.2fMB)\n", area, numGridPoints, sizeof( lightGridPoint_t ), ( float )( lightGridPoints.MemoryUsed() ) / ( 1024.0f * 1024.0f ) ); @@ -226,6 +226,21 @@ idVec3 LightGrid::GetProbeIndexDebugColor( const int probeIndex ) return GetGridCoordDebugColor( gridCoord ); } +int LightGrid::CountValidGridPoints() const +{ + int validCount = 0; + + for( int i = 0; i < lightGridPoints.Num(); i += 1 ) + { + if( lightGridPoints[i].valid > 0 ) + { + validCount++; + } + } + + return validCount; +} + void LightGrid::CalculateLightGridPointPositions( const idRenderWorld* world, int area ) { // calculate grid point positions @@ -368,12 +383,19 @@ void idRenderWorldLocal::SetupLightGrid() } else { + int totalGridPoints = 0; + for( int i = 0; i < numPortalAreas; i++ ) { portalArea_t* area = &portalAreas[i]; area->lightGrid.SetupLightGrid( area->globalBounds, mapName, this, i, -1 ); + + totalGridPoints += area->lightGrid.CountValidGridPoints(); } + + idLib::Printf( "----------------------------------\n" ); + idLib::Printf( "Total valid light grid points %i\n", totalGridPoints ); } } @@ -627,7 +649,7 @@ void idRenderWorldLocal::ParseLightGridPoints( idLexer* src, idFile* fileOut ) area->lightGrid.lightGridPoints.SetNum( numLightGridPoints ); - idLib::Printf( "area %i (%i x %i x %i) = %i grid points \n", areaIndex, area->lightGrid.lightGridBounds[0], area->lightGrid.lightGridBounds[1], area->lightGrid.lightGridBounds[2], numLightGridPoints ); + idLib::Printf( "\narea %i (%i x %i x %i) = %i grid points \n", areaIndex, area->lightGrid.lightGridBounds[0], area->lightGrid.lightGridBounds[1], area->lightGrid.lightGridBounds[2], numLightGridPoints ); idLib::Printf( "area %i grid size (%i %i %i)\n", areaIndex, ( int )area->lightGrid.lightGridSize[0], ( int )area->lightGrid.lightGridSize[1], ( int )area->lightGrid.lightGridSize[2] ); idLib::Printf( "area %i grid bounds (%i %i %i)\n", areaIndex, ( int )area->lightGrid.lightGridBounds[0], ( int )area->lightGrid.lightGridBounds[1], ( int )area->lightGrid.lightGridBounds[2] ); idLib::Printf( "area %i %9u x %" PRIuSIZE " = lightGridSize = (%.2fMB)\n", areaIndex, numLightGridPoints, sizeof( lightGridPoint_t ), ( float )( area->lightGrid.lightGridPoints.MemoryUsed() ) / ( 1024.0f * 1024.0f ) ); @@ -695,7 +717,7 @@ void idRenderWorldLocal::ReadBinaryLightGridPoints( idFile* file ) area->lightGrid.lightGridPoints.SetNum( numLightGridPoints ); - idLib::Printf( "area %i (%i x %i x %i) = %i grid points \n", areaIndex, area->lightGrid.lightGridBounds[0], area->lightGrid.lightGridBounds[1], area->lightGrid.lightGridBounds[2], numLightGridPoints ); + idLib::Printf( "\narea %i (%i x %i x %i) = %i grid points \n", areaIndex, area->lightGrid.lightGridBounds[0], area->lightGrid.lightGridBounds[1], area->lightGrid.lightGridBounds[2], numLightGridPoints ); idLib::Printf( "area %i grid size (%i %i %i)\n", areaIndex, ( int )area->lightGrid.lightGridSize[0], ( int )area->lightGrid.lightGridSize[1], ( int )area->lightGrid.lightGridSize[2] ); idLib::Printf( "area %i grid bounds (%i %i %i)\n", areaIndex, ( int )area->lightGrid.lightGridBounds[0], ( int )area->lightGrid.lightGridBounds[1], ( int )area->lightGrid.lightGridBounds[2] ); idLib::Printf( "area %i %9u x %" PRIuSIZE " = lightGridSize = (%.2fMB)\n", areaIndex, numLightGridPoints, sizeof( lightGridPoint_t ), ( float )( area->lightGrid.lightGridPoints.MemoryUsed() ) / ( 1024.0f * 1024.0f ) ); @@ -1099,6 +1121,7 @@ CONSOLE_COMMAND( bakeLightGrids, "Bake irradiance/vis light grid data", NULL ) // CAPTURE SCENE LIGHTING TO CUBEMAPS //-------------------------------------------- + int totalStart = Sys_Milliseconds(); for( int a = 0; a < tr.primaryWorld->NumAreas(); a++ ) { @@ -1205,7 +1228,7 @@ CONSOLE_COMMAND( bakeLightGrids, "Bake irradiance/vis light grid data", NULL ) if( !useThreads ) { - progressBar.Reset(); + progressBar.Reset( tr.lightGridJobs.Num() ); progressBar.Start(); } @@ -1301,6 +1324,13 @@ CONSOLE_COMMAND( bakeLightGrids, "Bake irradiance/vis light grid data", NULL ) #endif } + + int totalEnd = Sys_Milliseconds(); + + common->Printf( "Baked light grid irradiance in %5.1f minutes\n\n", ( totalEnd - totalStart ) / ( 1000.0f * 60 ) ); + + // everything went ok so let's save the configurations to disc + // so we can load the texture atlases with the correct subdivisions next time filename.Format( "%s.lightgrid", baseName.c_str() ); tr.primaryWorld->WriteLightGridsToFile( filename ); } diff --git a/neo/renderer/RenderWorld_local.h b/neo/renderer/RenderWorld_local.h index 653425cc..c2c58b4c 100644 --- a/neo/renderer/RenderWorld_local.h +++ b/neo/renderer/RenderWorld_local.h @@ -94,6 +94,8 @@ public: idVec3 GetGridCoordDebugColor( int gridCoord[3] ); idVec3 GetProbeIndexDebugColor( const int probeIndex ); + int CountValidGridPoints() const; + idImage* GetIrradianceImage() const { return irradianceImage;