From e9d13e5d7440b450eeebbd5fd89322427718fbf9 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Tue, 4 Oct 2016 00:25:35 +0200 Subject: [PATCH] Remove gl_light_math (reverts last remains of old lightmath branch) --- src/gl/dynlights/gl_dynlight1.cpp | 26 +------ src/gl/renderer/gl_renderstate.cpp | 1 - src/gl/shaders/gl_shader.cpp | 1 - src/gl/shaders/gl_shader.h | 1 - src/gl/system/gl_cvars.h | 1 - wadsrc/static/menudef.zz | 8 --- wadsrc/static/shaders/glsl/main.fp | 94 +------------------------ wadsrc/static/shaders/glsl/main.vp | 2 +- wadsrc/static/shaders/glsl/shaderdefs.i | 1 - 9 files changed, 7 insertions(+), 128 deletions(-) diff --git a/src/gl/dynlights/gl_dynlight1.cpp b/src/gl/dynlights/gl_dynlight1.cpp index 5c5e26f030..d20f5c01b1 100644 --- a/src/gl/dynlights/gl_dynlight1.cpp +++ b/src/gl/dynlights/gl_dynlight1.cpp @@ -60,11 +60,6 @@ CVAR (Bool, gl_lights_checkside, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG); CVAR (Bool, gl_light_sprites, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG); CVAR (Bool, gl_light_particles, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG); -CUSTOM_CVAR(Int, gl_light_math, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -{ - if (self < 0 || self > 2) self = 0; -} - //========================================================================== // // Sets up the parameters to render one dynamic light onto one plane @@ -113,25 +108,10 @@ bool gl_GetLight(int group, Plane & p, ADynamicLight * light, bool checkside, FD i = 1; } - float worldPos[4] = { (float)pos.X, (float)pos.Z, (float)pos.Y, 1.0f }; - float eyePos[4]; - gl_RenderState.mViewMatrix.multMatrixPoint(worldPos, eyePos); - - if (gl_light_math != 0) - { - // Move light up because flasks/vials have their light source location at/below the floor. - // - // If the point is exactly on the wall plane it might cause some acne as some pixels could - // be in front and some behind. Move light just a tiny bit to avoid this. - eyePos[0] += 0.01f; - eyePos[1] += 5.01f; - eyePos[2] += 0.01f; - } - float *data = &ldata.arrays[i][ldata.arrays[i].Reserve(8)]; - data[0] = eyePos[0]; - data[1] = eyePos[1]; - data[2] = eyePos[2]; + data[0] = pos.X; + data[1] = pos.Z; + data[2] = pos.Y; data[3] = radius; data[4] = r; data[5] = g; diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index cfaaea3cc0..fa8237cca1 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -158,7 +158,6 @@ bool FRenderState::ApplyShader() activeShader->muTimer.Set(gl_frameMS * mShaderTimer / 1000.f); activeShader->muAlphaThreshold.Set(mAlphaThreshold); activeShader->muLightIndex.Set(mLightIndex); // will always be -1 for now - activeShader->muLightMath.Set(gl_light_math); activeShader->muClipSplit.Set(mClipSplit); if (mGlowEnabled) diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index 9368a268cb..9cbd69ce22 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -220,7 +220,6 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * muColormapStart.Init(hShader, "uFixedColormapStart"); muColormapRange.Init(hShader, "uFixedColormapRange"); muLightIndex.Init(hShader, "uLightIndex"); - muLightMath.Init(hShader, "uLightMath"); muFogColor.Init(hShader, "uFogColor"); muDynLightColor.Init(hShader, "uDynLightColor"); muObjectColor.Init(hShader, "uObjectColor"); diff --git a/src/gl/shaders/gl_shader.h b/src/gl/shaders/gl_shader.h index 934674cbeb..acdd530aae 100644 --- a/src/gl/shaders/gl_shader.h +++ b/src/gl/shaders/gl_shader.h @@ -266,7 +266,6 @@ class FShader FUniform1i muFixedColormap; FUniform4f muColormapStart; FUniform4f muColormapRange; - FBufferedUniform1i muLightMath; FBufferedUniform1i muLightIndex; FBufferedUniformPE muFogColor; FBufferedUniform4f muDynLightColor; diff --git a/src/gl/system/gl_cvars.h b/src/gl/system/gl_cvars.h index b7ac9e435a..836787117d 100644 --- a/src/gl/system/gl_cvars.h +++ b/src/gl/system/gl_cvars.h @@ -26,7 +26,6 @@ EXTERN_CVAR (Bool, gl_attachedlights); EXTERN_CVAR (Bool, gl_lights_checkside); EXTERN_CVAR (Bool, gl_light_sprites); EXTERN_CVAR (Bool, gl_light_particles); -EXTERN_CVAR (Int, gl_light_math); EXTERN_CVAR(Int, gl_fogmode) EXTERN_CVAR(Int, gl_lightmode) diff --git a/wadsrc/static/menudef.zz b/wadsrc/static/menudef.zz index 6eb56be948..d5c2bbc5c0 100644 --- a/wadsrc/static/menudef.zz +++ b/wadsrc/static/menudef.zz @@ -25,13 +25,6 @@ OptionValue "FilterModes" 4, "$OPTVAL_TRILINEAR" } -OptionValue "LightMathModes" -{ - 0, "$OPTVAL_LOW" - 1, "$OPTVAL_MEDIUM" - 2, "$OPTVAL_HIGH" -} - OptionValue "HWGammaModes" { 0, "$OPTVAL_ON" @@ -225,7 +218,6 @@ OptionMenu "GLLightOptions" Option "$GLLIGHTMNU_CLIPLIGHTS", gl_lights_checkside, "YesNo" Option "$GLLIGHTMNU_LIGHTSPRITES", gl_light_sprites, "YesNo" Option "$GLLIGHTMNU_LIGHTPARTICLES", gl_light_particles, "YesNo" - Option "$GLLIGHTMNU_LIGHTMATH", gl_light_math, "LightMathModes" } OptionMenu "GLPrefOptions" diff --git a/wadsrc/static/shaders/glsl/main.fp b/wadsrc/static/shaders/glsl/main.fp index 374edb59c0..1f270728df 100644 --- a/wadsrc/static/shaders/glsl/main.fp +++ b/wadsrc/static/shaders/glsl/main.fp @@ -30,88 +30,6 @@ vec4 Process(vec4 color); vec4 ProcessTexel(); vec4 ProcessLight(vec4 color); -// Smoothed normal used for the face, in eye space. Should be converted to an 'in' variable in the future. -vec3 pixelnormal; - -//=========================================================================== -// -// Calculates the face normal vector for the fragment, in eye space -// -//=========================================================================== - -vec3 calculateFaceNormal() -{ -#if __VERSION__ < 450 - vec3 dFdxPos = dFdx(pixelpos.xyz); - vec3 dFdyPos = dFdy(pixelpos.xyz); -#else - vec3 dFdxPos = dFdxCoarse(pixelpos.xyz); - vec3 dFdyPos = dFdyCoarse(pixelpos.xyz); -#endif - return normalize(cross(dFdxPos,dFdyPos)); -} - -//=========================================================================== -// -// Standard lambertian diffuse light calculation -// -//=========================================================================== - -float diffuseContribution(vec3 eyeLightDirection, vec3 eyeNormal) -{ - return max(dot(eyeNormal, eyeLightDirection), 0.0f); -} - -//=========================================================================== -// -// Blinn specular light calculation -// -//=========================================================================== - -float blinnSpecularContribution(float diffuseContribution, vec3 eyeLightDirection, vec3 eyePosition, vec3 eyeNormal, float glossiness, float specularLevel) -{ - if (diffuseContribution > 0.0f) - { - vec3 viewDir = normalize(-eyePosition); - vec3 halfDir = normalize(eyeLightDirection + viewDir); - float specAngle = max(dot(halfDir, eyeNormal), 0.0f); - float phExp = glossiness * 4.0f; - return specularLevel * pow(specAngle, phExp); - } - else - { - return 0.0f; - } -} - -//=========================================================================== -// -// Calculates the brightness of a dynamic point light -// -//=========================================================================== - -float pointLightAttenuation(vec4 lightpos) -{ - float attenuation = max(lightpos.w - distance(pixelpos.xyz, lightpos.xyz),0.0) / lightpos.w; - if (uLightMath == 0) - { - return attenuation; - } - else - { - vec3 lightDirection = normalize(lightpos.xyz - pixelpos.xyz); - float diffuseAmount = diffuseContribution(lightDirection, pixelnormal); - if (uLightMath == 1) - { - return attenuation * diffuseAmount; - } - else - { - float specularAmount = blinnSpecularContribution(diffuseAmount, lightDirection, pixelpos.xyz, pixelnormal, 3.0, 1.2); - return attenuation * (diffuseAmount + specularAmount); - } - } -} //=========================================================================== // @@ -384,13 +302,6 @@ vec3 AmbientOcclusionColor() void main() { vec4 frag = ProcessTexel(); - -#if defined NUM_UBO_LIGHTS || defined SHADER_STORAGE_LIGHTS - if (uLightMath != 0) // Remove this if pixelnormal is converted to an 'in' variable - { - pixelnormal = calculateFaceNormal(); - } -#endif #ifndef NO_ALPHATEST if (frag.a <= uAlphaThreshold) discard; @@ -416,11 +327,12 @@ void main() } else { - fogdist = max(16.0, length(pixelpos.xyz)); + fogdist = max(16.0, distance(pixelpos.xyz, uCameraPos.xyz)); } fogfactor = exp2 (uFogDensity * fogdist); } + frag *= getLightColor(fogdist, fogfactor); #if defined NUM_UBO_LIGHTS || defined SHADER_STORAGE_LIGHTS @@ -486,7 +398,7 @@ void main() } else { - fogdist = max(16.0, length(pixelpos.xyz)); + fogdist = max(16.0, distance(pixelpos.xyz, uCameraPos.xyz)); } fogfactor = exp2 (uFogDensity * fogdist); diff --git a/wadsrc/static/shaders/glsl/main.vp b/wadsrc/static/shaders/glsl/main.vp index 0baca31f92..1de8854c0d 100644 --- a/wadsrc/static/shaders/glsl/main.vp +++ b/wadsrc/static/shaders/glsl/main.vp @@ -47,7 +47,7 @@ void main() vColor = aColor; #ifndef SIMPLE - pixelpos.xyz = eyeCoordPos.xyz; + pixelpos.xyz = worldcoord.xyz; pixelpos.w = -eyeCoordPos.z/eyeCoordPos.w; glowdist.x = -((uGlowTopPlane.w + uGlowTopPlane.x * worldcoord.x + uGlowTopPlane.y * worldcoord.z) * uGlowTopPlane.z) - worldcoord.y; diff --git a/wadsrc/static/shaders/glsl/shaderdefs.i b/wadsrc/static/shaders/glsl/shaderdefs.i index 81edd7b046..8c5697a661 100644 --- a/wadsrc/static/shaders/glsl/shaderdefs.i +++ b/wadsrc/static/shaders/glsl/shaderdefs.i @@ -44,7 +44,6 @@ uniform int uFogEnabled; // dynamic lights uniform int uLightIndex; -uniform int uLightMath; // 0, when using only attenuation, 1 for diffuse light, 2 for blinn specular light // quad drawer stuff #ifdef USE_QUAD_DRAWER