diff --git a/source/blood/src/blood.cpp b/source/blood/src/blood.cpp index 8c9c4167a..8649ff0fd 100644 --- a/source/blood/src/blood.cpp +++ b/source/blood/src/blood.cpp @@ -171,7 +171,6 @@ void ShutDown(void) { if (!in3dmode()) return; - G_SaveConfig(); netDeinitialize(); sndTerm(); sfxTerm(); diff --git a/source/common/gamecontrol.cpp b/source/common/gamecontrol.cpp index 06d2a552b..eee4d0fa0 100644 --- a/source/common/gamecontrol.cpp +++ b/source/common/gamecontrol.cpp @@ -258,6 +258,7 @@ int GameMain() // Just let the rest of the function execute. r = exit.Reason(); } + G_SaveConfig(); #ifndef NETCODE_DISABLE if (gHaveNetworking) enet_deinitialize(); #endif diff --git a/source/common/textures/textures.h b/source/common/textures/textures.h index e08db7462..b574bca56 100644 --- a/source/common/textures/textures.h +++ b/source/common/textures/textures.h @@ -259,6 +259,7 @@ public: int alphaThreshold = 128; picanm_t PicAnim = {}; + FixedBitArray<256> NoBrightmapFlag{ 0 }; protected: diff --git a/source/common/utility/tarray.h b/source/common/utility/tarray.h index 486e120e0..77265ece8 100644 --- a/source/common/utility/tarray.h +++ b/source/common/utility/tarray.h @@ -1464,6 +1464,12 @@ class FixedBitArray public: + FixedBitArray() = default; + FixedBitArray(bool set) + { + memset(bytes, set ? -1 : 0, sizeof(bytes)); + } + bool operator[](size_t index) const { return !!(bytes[index >> 3] & (1 << (index & 7))); diff --git a/source/duke3d/src/game.cpp b/source/duke3d/src/game.cpp index e7eef2813..9bca08dc2 100644 --- a/source/duke3d/src/game.cpp +++ b/source/duke3d/src/game.cpp @@ -5674,7 +5674,6 @@ static void G_Cleanup(void) void G_Shutdown(void) { - G_SaveConfig(); S_SoundShutdown(); S_MusicShutdown(); CONTROL_Shutdown(); diff --git a/source/glbackend/gl_shader.cpp b/source/glbackend/gl_shader.cpp index 3f3ddcd29..f5f64959b 100644 --- a/source/glbackend/gl_shader.cpp +++ b/source/glbackend/gl_shader.cpp @@ -170,6 +170,8 @@ bool PolymostShader::Load(const char * name, const char * vert_prog, const char glUniform1i(SamplerLoc, 3); SamplerLoc = glGetUniformLocation(hShader, "s_glow"); glUniform1i(SamplerLoc, 4); + SamplerLoc = glGetUniformLocation(hShader, "s_brightmap"); + glUniform1i(SamplerLoc, 5); glUseProgram(0); return true; diff --git a/source/glbackend/gl_texture.cpp b/source/glbackend/gl_texture.cpp index 879b57b89..1a7a74d98 100644 --- a/source/glbackend/gl_texture.cpp +++ b/source/glbackend/gl_texture.cpp @@ -100,6 +100,7 @@ FHardwareTexture* GLInstance::CreateTrueColorTexture(FTexture* tex, int palid, b bool npoty = false; auto palette = palid < 0? nullptr : palmanager.GetPaletteData(palid); + if (palette == nullptr) return nullptr; auto texbuffer = tex->CreateTexBuffer(palette, CTF_ProcessData); // Check if the texture is fully transparent. When creating a brightmap such textures can be discarded. if (checkfulltransparency) @@ -144,7 +145,7 @@ FHardwareTexture* GLInstance::LoadTexture(FTexture* tex, int textype, int palid) else hwtex = CreateTrueColorTexture(tex, textype == TT_HICREPLACE? -1 : palid, textype == TT_BRIGHTMAP, textype == TT_BRIGHTMAP); - tex->SetHardwareTexture(palid, hwtex); + if (hwtex) tex->SetHardwareTexture(palid, hwtex); return hwtex; } @@ -177,7 +178,12 @@ bool GLInstance::SetTextureInternal(int picnum, FTexture* tex, int palette, int else { // Only look up the palette if we really want to use it (i.e. when creating a true color texture of an ART tile.) - if (TextureType == TT_TRUECOLOR) lookuppal = palmanager.LookupPalette(usepalette, usepalswap, false); + if (TextureType == TT_TRUECOLOR) + { + /*lookuppal = palmanager.LookupPalette(usepalette, usepalswap, true); + if (lookuppal< 0)*/ lookuppal = palmanager.LookupPalette(usepalette, usepalswap, false); + } + } // Load the main texture @@ -191,6 +197,7 @@ bool GLInstance::SetTextureInternal(int picnum, FTexture* tex, int palette, int sampler = sampler + SamplerNoFilterRepeat - SamplerRepeat; } else renderState.Flags &= ~RF_UsePalette; + UseBrightmaps(false); BindTexture(0, mtex, sampler); if (rep && (rep->scale.x != 1.0f || rep->scale.y != 1.0f || xpanning != 0 || ypanning != 0)) @@ -251,7 +258,7 @@ bool GLInstance::SetTextureInternal(int picnum, FTexture* tex, int palette, int BindTexture(4, htex, SamplerRepeat); } } - if (!(tex->PicAnim.sf & PICANM_NOFULLBRIGHT_BIT) && !(globalflags & GLOBAL_NO_GL_FULLBRIGHT)) + if (!(tex->PicAnim.sf & PICANM_NOFULLBRIGHT_BIT) && !(globalflags & GLOBAL_NO_GL_FULLBRIGHT) && !tex->NoBrightmapFlag[usepalswap]) { if (TextureType == TT_HICREPLACE) { @@ -259,9 +266,13 @@ bool GLInstance::SetTextureInternal(int picnum, FTexture* tex, int palette, int if (brep) { auto htex = LoadTexture(brep->faces[0], TT_HICREPLACE, 0); - // UseBrightmapping(true); + UseBrightmaps(true); BindTexture(5, mtex, sampler); } + else + { + tex->PicAnim.sf |= PICANM_NOFULLBRIGHT_BIT; + } } else if (TextureType == TT_TRUECOLOR) { @@ -269,8 +280,16 @@ bool GLInstance::SetTextureInternal(int picnum, FTexture* tex, int palette, int if (lookuppal >= 0) { auto htex = LoadTexture(tex, TT_BRIGHTMAP, lookuppal); - // UseBrightmapping(true); - BindTexture(5, mtex, sampler); + if (htex == nullptr) + { + // Flag the texture as not being brightmapped for the given palette + tex->NoBrightmapFlag.Set(usepalswap); + } + else + { + UseBrightmaps(true); + BindTexture(5, mtex, sampler); + } } } } diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index 4bc88cfb9..cb95ca4b2 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -505,6 +505,8 @@ void GLInstance::DrawImGui(ImDrawData* data) void PolymostRenderState::Apply(PolymostShader* shader) { + // Disable brightmaps if non-black fog is used. + if (!(Flags & RF_FogDisabled) && !FogColor.isBlack()) Flags &= ~RF_Brightmapping; shader->Flags.Set(Flags); shader->Shade.Set(Shade); shader->NumShades.Set(NumShades); diff --git a/source/rr/src/game.cpp b/source/rr/src/game.cpp index 57e80f5bb..7609b8bb9 100644 --- a/source/rr/src/game.cpp +++ b/source/rr/src/game.cpp @@ -7066,7 +7066,6 @@ static void G_Cleanup(void) void G_Shutdown(void) { - G_SaveConfig(); S_SoundShutdown(); S_MusicShutdown(); CONTROL_Shutdown(); diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index 6855fe556..b8a041af7 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -664,7 +664,6 @@ TerminateGame(void) } engineUnInit(); - G_SaveConfig(); //Terminate3DSounds(); // Kill the sounds linked list UnInitSound(); @@ -770,7 +769,6 @@ void MultiSharewareCheck(void) #endif //uninitmultiplayers(); //uninitkeys(); - G_SaveConfig(); engineUnInit(); UnInitSound(); timerUninit(); diff --git a/wadsrc/static/demolition/shaders/glsl/polymost.fp b/wadsrc/static/demolition/shaders/glsl/polymost.fp index 060e46b1d..8a6f4ef35 100644 --- a/wadsrc/static/demolition/shaders/glsl/polymost.fp +++ b/wadsrc/static/demolition/shaders/glsl/polymost.fp @@ -27,6 +27,7 @@ uniform sampler2D s_palette; uniform sampler2D s_detail; uniform sampler2D s_glow; +uniform sampler2D s_brightmap; uniform float u_shade; uniform float u_numShades; @@ -188,19 +189,29 @@ void main() palettedColor.a = c_one-floor(color.r); color = palettedColor; color.rgb *= detailColor.rgb; // with all this palettizing, this can only be applied afterward, even though it is wrong to do it this way. + if (fullbright == 0.0) color.rgb *= v_color.rgb; // Well, this is dead wrong but unavoidable. For colored fog it applies the light to the fog as well... } else { color.rgb *= detailColor.rgb; - if ((u_flags & RF_FogDisabled) == 0) + + vec3 lightcolor = v_color.rgb; + // The lighting model here does not really allow more than a simple on/off brightmap because anything more complex inteferes with the shade ramp... :( + if ((u_flags & RF_Brightmapping) != 0) { + vec4 brightcolor = texture2D(s_brightmap, v_texCoord.xy); + color.rgb *= clamp(brightcolor.rgb + v_color.rgb, 0.0, 1.0); + } + else if ((u_flags & RF_FogDisabled) == 0) + { + color.rgb *= lightcolor; shade = clamp(shade * u_shadeDiv, 0.0, 1.0); // u_shadeDiv is really 1/shadeDiv. // Apply the shade as a linear depth fade ramp. color.rgb = mix(color.rgb, u_fogColor.rgb, shade); } } if (color.a < u_alphaThreshold) discard; // it's only here that we have the alpha value available to be able to perform the alpha test. - if (fullbright == 0.0) color.rgb *= v_color.rgb; + color.a *= v_color.a; } else