From 4671ac280755c2f1847bcee04a556c45191720fe Mon Sep 17 00:00:00 2001 From: MadDeCoDeR Date: Tue, 17 Jan 2023 22:43:54 +0200 Subject: [PATCH] Fix issue when enabling/Disabling Half-lambert Lighting might cause the game to have undefined behaviour (ref #94) --- base/renderprogs/ambient_lighting.ps.hlsl | 5 ++++- base/renderprogs/interactionSM.ps.hlsl | 4 ++-- neo/d3xp/menus/MenuScreen_Shell_SystemOptions.cpp | 2 +- neo/renderer/OpenGL/BufferObject_GL.cpp | 6 ++++-- neo/renderer/OpenGL/Image_GL.cpp | 2 +- neo/renderer/OpenGL/RenderBackend_GL.cpp | 5 ++++- neo/renderer/RenderBackend.cpp | 2 +- 7 files changed, 17 insertions(+), 9 deletions(-) diff --git a/base/renderprogs/ambient_lighting.ps.hlsl b/base/renderprogs/ambient_lighting.ps.hlsl index a952a97d..d34ccc1c 100644 --- a/base/renderprogs/ambient_lighting.ps.hlsl +++ b/base/renderprogs/ambient_lighting.ps.hlsl @@ -78,9 +78,12 @@ void main( PS_IN fragment, out PS_OUT result ) { half3 diffuseColor = diffuseMap * ( rpDiffuseModifier.xyz ) * 1.5f; half3 specularColor = specMap.xyz * specularContribution * ( rpSpecularModifier.xyz ); + float halfLdotN = 1.0f; +#if defined(USE_HALF_LAMBERT) // RB: http://developer.valvesoftware.com/wiki/Half_Lambert - float halfLdotN = dot3( localNormal, lightVector ) * 0.5 + 0.5; + halfLdotN = dot3( localNormal, lightVector ) * 0.5 + 0.5; halfLdotN *= halfLdotN; +#endif // traditional very dark Lambert light model used in Doom 3 float ldotN = dot3( localNormal, lightVector ); diff --git a/base/renderprogs/interactionSM.ps.hlsl b/base/renderprogs/interactionSM.ps.hlsl index 024442b3..b3a597a8 100644 --- a/base/renderprogs/interactionSM.ps.hlsl +++ b/base/renderprogs/interactionSM.ps.hlsl @@ -243,7 +243,7 @@ void main( PS_IN fragment, out PS_OUT result ) float shadow = 0.0; // RB: casting a float to int and using it as index can really kill the performance ... - float numSamples = 6.0; //int(rpScreenCorrectionFactor.w); + float numSamples = 12.0f; //int(rpScreenCorrectionFactor.w); float stepSize = 1.0 / numSamples; float4 jitterTC = ( fragment.position * rpScreenCorrectionFactor ) + rpJitterTexOffset; @@ -255,7 +255,7 @@ void main( PS_IN fragment, out PS_OUT result ) rot.y = sin( random.x ); float shadowTexelSize = rpScreenCorrectionFactor.z * rpJitterTexScale.x; - for( int i = 0; i < 6; i++ ) + for( int i = 0; i < 12; i++ ) { float2 jitter = poissonDisk[i]; float2 jitterRotated; diff --git a/neo/d3xp/menus/MenuScreen_Shell_SystemOptions.cpp b/neo/d3xp/menus/MenuScreen_Shell_SystemOptions.cpp index 21b8397f..5ede9a17 100644 --- a/neo/d3xp/menus/MenuScreen_Shell_SystemOptions.cpp +++ b/neo/d3xp/menus/MenuScreen_Shell_SystemOptions.cpp @@ -614,7 +614,7 @@ void idMenuScreen_Shell_SystemOptions::idMenuDataSource_SystemSettings::AdjustFi const float percent = LinearAdjust(r_lightScale.GetFloat(), 0.0f, 5.0f, 0.0f, 100.0f ); const float adjusted = percent + ( float )adjustAmount; const float clamped = idMath::ClampFloat( 0.0f, 100.0f, adjusted ); - r_exposure.SetFloat( LinearAdjust( clamped, 0.0f, 100.0f, 0.0f, 1.0f ) ); + //r_exposure.SetFloat( LinearAdjust( clamped, 0.0f, 100.0f, 0.0f, 1.0f ) ); r_lightScale.SetFloat( LinearAdjust( clamped, 0.0f, 100.0f, 0.0f, 5.0f ) ); //GK: More light options break; } diff --git a/neo/renderer/OpenGL/BufferObject_GL.cpp b/neo/renderer/OpenGL/BufferObject_GL.cpp index 8a7ed2fd..f95c6687 100644 --- a/neo/renderer/OpenGL/BufferObject_GL.cpp +++ b/neo/renderer/OpenGL/BufferObject_GL.cpp @@ -55,8 +55,10 @@ UnbindBufferObjects */ void UnbindBufferObjects() { - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + if (!glConfig.directStateAccess) { + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + } } diff --git a/neo/renderer/OpenGL/Image_GL.cpp b/neo/renderer/OpenGL/Image_GL.cpp index e8400dc4..639b7363 100644 --- a/neo/renderer/OpenGL/Image_GL.cpp +++ b/neo/renderer/OpenGL/Image_GL.cpp @@ -764,7 +764,7 @@ void idImage::SetTextureParameters() { if( glConfig.textureLODBiasAvailable && ( usage != TD_FONT ) ) { // use a blurring LOD bias in combination with high anisotropy to fix our aliasing grate textures... - glTexParameterf( target, GL_TEXTURE_LOD_BIAS_EXT, 0.5 ); //r_lodBias.GetFloat() ); + glTextureParameterf( texnum, GL_TEXTURE_LOD_BIAS_EXT, r_lodBias.GetFloat() ); } */ // RB end diff --git a/neo/renderer/OpenGL/RenderBackend_GL.cpp b/neo/renderer/OpenGL/RenderBackend_GL.cpp index dbb36380..46bd436a 100644 --- a/neo/renderer/OpenGL/RenderBackend_GL.cpp +++ b/neo/renderer/OpenGL/RenderBackend_GL.cpp @@ -249,6 +249,7 @@ static void R_CheckPortableExtensions() // GL_ARB_seamless_cube_map glConfig.seamlessCubeMapAvailable = GLEW_ARB_seamless_cube_map != 0; + R_PrintExtensionStatus(glConfig.seamlessCubeMapAvailable, "GL_ARB_seamless_cube_map"); r_useSeamlessCubeMap.SetModified(); // the CheckCvars() next frame will enable / disable it // GL_ARB_framebuffer_sRGB @@ -1410,7 +1411,9 @@ void idRenderBackend::CheckCVars() { if( globalImages->images[i] ) { - globalImages->images[i]->Bind(); + if (!glConfig.directStateAccess) { + globalImages->images[i]->Bind(); + } globalImages->images[i]->SetTexParameters(); } } diff --git a/neo/renderer/RenderBackend.cpp b/neo/renderer/RenderBackend.cpp index 38aaa816..3c0837b6 100644 --- a/neo/renderer/RenderBackend.cpp +++ b/neo/renderer/RenderBackend.cpp @@ -1975,7 +1975,7 @@ void idRenderBackend::AmbientPass( const drawSurf_t* const* drawSurfs, int numDr GL_Color( colorWhite ); - const float lightScale = 1.0f; //r_lightScale.GetFloat(); + const float lightScale = r_lightScale.GetFloat(); const idVec4 lightColor = colorWhite * lightScale; // apply the world-global overbright and the 2x factor for specular const idVec4 diffuseColor = lightColor;