Skip to content

Commit

Permalink
Fix issue when enabling/Disabling Half-lambert Lighting might cause t…
Browse files Browse the repository at this point in the history
…he game to have undefined behaviour (ref #94)
  • Loading branch information
MadDeCoDeR committed Jan 17, 2023
1 parent 8cc3f2f commit 4671ac2
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 9 deletions.
5 changes: 4 additions & 1 deletion base/renderprogs/ambient_lighting.ps.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions base/renderprogs/interactionSM.ps.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion neo/d3xp/menus/MenuScreen_Shell_SystemOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions neo/renderer/OpenGL/BufferObject_GL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}


Expand Down
2 changes: 1 addition & 1 deletion neo/renderer/OpenGL/Image_GL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion neo/renderer/OpenGL/RenderBackend_GL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
}
Expand Down
2 changes: 1 addition & 1 deletion neo/renderer/RenderBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4671ac2

Please sign in to comment.