From 28acf2ad0616f3b300a246cb89d3879b357f002e Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 22 Jun 2017 00:01:57 +0200 Subject: [PATCH] - Fix OpenGL software diminishing light to be identical to truecolor swrenderer and softpoly All there is left is to make globVis an uniform and move the LightVisibility::SetVisibility calculations out of the software renderer. That will make it 100% correct for all r_visiblity values and aspect ratios. --- wadsrc/static/shaders/glsl/main.fp | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/wadsrc/static/shaders/glsl/main.fp b/wadsrc/static/shaders/glsl/main.fp index 5b4d1438f3..fd520ce0b1 100644 --- a/wadsrc/static/shaders/glsl/main.fp +++ b/wadsrc/static/shaders/glsl/main.fp @@ -103,34 +103,29 @@ vec4 getTexel(vec2 st) //=========================================================================== float R_DoomLightingEquation(float light) { - // Calculated from r_visibility. It differs between walls, floor and sprites. + // globVis = WallVisibility / r_viewwindow.FocalTangent / 32.0 // - // Wall: globVis = r_WallVisibility - // Floor: r_FloorVisibility / abs(plane.Zat0 - ViewPos.Z) - // Sprite: same as wall - // All are calculated in R_SetVisibility and seem to be decided by the - // aspect ratio amongst other things. - // - // 1706 is the value for walls on 1080p 16:9 displays. - float globVis = 1706.0; + // WallVisibility is calculated in LightVisibility::SetVisibility + // 1706 is the default value for WallVisibility on 1080p 16:9 displays. + float globVis = 1706.0 / 1.3333333333333333 / 32.0; - /* L is the integer light level used in the game */ + // L is the integer light level used in the game float L = light * 255.0; - /* z is the depth in view/eye space, positive going into the screen */ + // z is the depth in view/eye space, positive going into the screen float z = pixelpos.w; - /* The zdoom light equation */ - float vis = globVis / z; - float shade = 64.0 - (L + 12.0) * 32.0/128.0; + // The zdoom light equation + float vis = min(globVis / z, 24.0 / 32.0); + float shade = 2.0 - (L + 12.0) / 128.0; float lightscale; if (uPalLightLevels != 0) - lightscale = clamp(float(int(shade - min(24.0, vis))) / 32.0, 0.0, 31.0/32.0); + lightscale = float(int(shade - vis)); else - lightscale = clamp((shade - min(24.0, vis)) / 32.0, 0.0, 31.0/32.0); + lightscale = shade - vis; // Result is the normalized colormap index (0 bright .. 1 dark) - return lightscale; + return clamp(lightscale, 0.0, 31.0 / 32.0); } //===========================================================================