From 29a10cabcbbbee399f578d9d022dc4dfe710927d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 18 Sep 2020 20:54:08 +0200 Subject: [PATCH] - fixed most issues with palette emulation. Brightness is now correct - I have no idea why this factor of 1/0.85 is needed - something must reduce the brightness of the entire scene but I have no idea what. --- source/glbackend/gl_palmanager.cpp | 8 ++++++++ wadsrc/static/shaders/glsl/func_paletted.fp | 12 ++---------- wadsrc/static/shaders/glsl/main.fp | 1 - 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/source/glbackend/gl_palmanager.cpp b/source/glbackend/gl_palmanager.cpp index e3fe51d0e..aee5dade4 100644 --- a/source/glbackend/gl_palmanager.cpp +++ b/source/glbackend/gl_palmanager.cpp @@ -119,8 +119,16 @@ IHardwareTexture* PaletteManager::GetLookup(int index) { auto p = screen->CreateHardwareTexture(1); + // Perform a 0<->255 index swap. The lookup tables are still the original data. TArray lookup(numshades * 256, true); memcpy(lookup.Data(), lookups.getTable(index), lookup.Size()); + for (int i = 0; i < numshades; i++) + { + auto p = &lookup[i * 256]; + p[255] = p[0]; + p[0] = 0; + for (int v = 1; v <= 255; v++) if (p[v] == 0) p[v] = 255; + } p->CreateTexture(lookup.Data(), 256, numshades, 15, false, "PaletteLookup"); lookuptextures[index] = p; } diff --git a/wadsrc/static/shaders/glsl/func_paletted.fp b/wadsrc/static/shaders/glsl/func_paletted.fp index 681c2ce3f..b47dacb7c 100644 --- a/wadsrc/static/shaders/glsl/func_paletted.fp +++ b/wadsrc/static/shaders/glsl/func_paletted.fp @@ -17,15 +17,7 @@ vec4 ProcessTexel() vec2 newCoord; // z is the depth in view space, positive going into the screen - float z; - if (((uPalLightLevels >> 8) & 0xff) == 2) - { - z = distance(pixelpos.xyz, uCameraPos.xyz)*0.7; - } - else - { - z = pixelpos.w; - } + float z = abs(pixelpos.w); // Coordinate adjustment for NPOT textures. It is somehow fitting that Build games exploited this texture wrapping quirk of the software rendering engine... if (uNpotEmulation.y != 0.0) @@ -68,5 +60,5 @@ vec4 ProcessTexel() color.rgb = uFogColor.rgb * (1.0-fogfactor) + color.rgb * fogfactor;// mix(vec3(0.6), color.rgb, fogfactor); } if (color.a < uAlphaThreshold) discard; // it's only here that we have the alpha value available to be able to perform the alpha test. - return color; + return vec4(color.rgb / 0.85, vColor.a); } diff --git a/wadsrc/static/shaders/glsl/main.fp b/wadsrc/static/shaders/glsl/main.fp index 29f01c4d0..95b01abf2 100644 --- a/wadsrc/static/shaders/glsl/main.fp +++ b/wadsrc/static/shaders/glsl/main.fp @@ -161,7 +161,6 @@ const int Tex_Blend_Hardlight = 4; vec4 getTexel(vec2 st) { vec4 texel = texture(tex, st); - // // Apply texture modes //