From 9e81fa89a8101fd752fa212e9c23f0e5b429eae4 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 12 Sep 2020 21:23:14 +0200 Subject: [PATCH] - fixed some of the issues with palette emulation * the palette shader was not bound. * the palette textures were not bound. * palette mode still used regular lighting on top of the palette emulation This works a lot better than before but is still not complete. --- source/common/rendering/gl/gl_renderstate.cpp | 22 ++++++++++++++----- .../hwrenderer/data/hw_shaderpatcher.cpp | 2 +- source/core/gamecontrol.cpp | 2 +- source/glbackend/gl_texture.cpp | 2 +- source/glbackend/glbackend.cpp | 8 +------ source/glbackend/glbackend.h | 2 +- wadsrc/static/shaders/glsl/main.fp | 4 ++++ 7 files changed, 26 insertions(+), 16 deletions(-) diff --git a/source/common/rendering/gl/gl_renderstate.cpp b/source/common/rendering/gl/gl_renderstate.cpp index 5628ca0a5..4c49ac58d 100644 --- a/source/common/rendering/gl/gl_renderstate.cpp +++ b/source/common/rendering/gl/gl_renderstate.cpp @@ -329,12 +329,24 @@ void FGLRenderState::ApplyMaterial(FMaterial *mat, int clampmode, int translatio if (base->BindOrCreate(tex->GetTexture(), 0, clampmode, translation, layer->scaleFlags)) { - for (int i = 1; iscaleFlags & CTF_Indexed)) { - auto systex = static_cast(mat->GetLayer(i, 0, &layer)); - // fixme: Upscale flags must be disabled for certain layers. - systex->BindOrCreate(layer->layerTexture, i, clampmode, 0, layer->scaleFlags); - maxbound = i; + for (int i = 1; i < numLayers; i++) + { + auto systex = static_cast(mat->GetLayer(i, 0, &layer)); + // fixme: Upscale flags must be disabled for certain layers. + systex->BindOrCreate(layer->layerTexture, i, clampmode, 0, layer->scaleFlags); + maxbound = i; + } + } + else + { + for (int i = 1; i < 3; i++) + { + auto systex = static_cast(mat->GetLayer(i, 0, &layer)); + systex->Bind(i, false); + maxbound = i; + } } } // unbind everything from the last texture that's still active diff --git a/source/common/rendering/hwrenderer/data/hw_shaderpatcher.cpp b/source/common/rendering/hwrenderer/data/hw_shaderpatcher.cpp index 0362306d3..6f40fcbfb 100644 --- a/source/common/rendering/hwrenderer/data/hw_shaderpatcher.cpp +++ b/source/common/rendering/hwrenderer/data/hw_shaderpatcher.cpp @@ -277,7 +277,7 @@ const FDefaultShader defaultshaders[] = {"Warp 2", "shaders/glsl/func_warp2.fp", "shaders/glsl/material_normal.fp", ""}, {"Specular", "shaders/glsl/func_spec.fp", "shaders/glsl/material_specular.fp", "#define SPECULAR\n#define NORMALMAP\n"}, {"PBR","shaders/glsl/func_pbr.fp", "shaders/glsl/material_pbr.fp", "#define PBR\n#define NORMALMAP\n"}, - {"Paletted", "shaders/glsl/func_paletted.fp", "shaders/glsl/material_nolight.fp", ""}, + {"Paletted", "shaders/glsl/func_paletted.fp", "shaders/glsl/material_nolight.fp", "#define PALETTE_EMULATION"}, {"No Texture", "shaders/glsl/func_notexture.fp", "shaders/glsl/material_normal.fp", "#define NO_LAYERS\n"}, {"Basic Fuzz", "shaders/glsl/fuzz_standard.fp", "shaders/glsl/material_normal.fp", ""}, {"Smooth Fuzz", "shaders/glsl/fuzz_smooth.fp", "shaders/glsl/material_normal.fp", ""}, diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index fa1025e1a..69171cf0e 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -1002,7 +1002,7 @@ void videoInit() PolymostProcessVoxels(); GLInterface.Init(screen->GetWidth()); - GLInterface.InitGLState(4, 4/*glmultisample*/); + screen->BeginFrame(); screen->SetTextureFilterMode(); setViewport(hud_size); } diff --git a/source/glbackend/gl_texture.cpp b/source/glbackend/gl_texture.cpp index e6899652f..1eeadee8a 100644 --- a/source/glbackend/gl_texture.cpp +++ b/source/glbackend/gl_texture.cpp @@ -87,7 +87,7 @@ bool GLInstance::SetTexture(int picnum, FGameTexture* tex, int paletteid, int sa mat.mMaterial = FMaterial::ValidateTexture(texpick.texture, flags); // todo allow scaling mat.mClampMode = sampler; mat.mTranslation = texpick.translation; - mat.mOverrideShader = 0; + mat.mOverrideShader = -1; mat.mChanged = true; if (TextureType == TT_INDEXED) renderState.Flags |= RF_UsePalette; else renderState.Flags &= ~RF_UsePalette; diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index da6ad6039..e9d2068aa 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -96,13 +96,6 @@ void GLInstance::Init(int ydim) new(&renderState) PolymostRenderState; // reset to defaults. } -void GLInstance::InitGLState(int fogmode, int multisample) -{ - // This is a bad place to call this but without deconstructing the entire render loops in all front ends there is no way to have a well defined spot for this stuff. - // Before doing that the backend needs to work in some fashion, so we have to make sure everything is set up when the first render call is performed. - screen->BeginFrame(); -} - void GLInstance::Deinit() { palmanager.DeleteAll(); @@ -241,6 +234,7 @@ void PolymostRenderState::Apply(FRenderState& state, GLState& oldState) state.EnableFog(1); } else state.EnableFog(0); + state.SetFog((GLInterface.useMapFog) ? PalEntry(0x999999) : FogColor, 350.f); // Fixme: The real density still needs to be implemented. 350 is a reasonable default only. state.SetSoftLightLevel(ShadeDiv >= 1 / 1000.f ? 255 - Scale(Shade, 255, numshades) : 255); diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index ed91273a9..ebc8d3647 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -3,6 +3,7 @@ #include #include #include +#include "c_cvars.h" #include "gl_samplers.h" #include "gl_hwtexture.h" #include "matrix.h" @@ -94,7 +95,6 @@ public: glinfo_t glinfo; void Init(int y); - void InitGLState(int fogmode, int multisample); void Deinit(); diff --git a/wadsrc/static/shaders/glsl/main.fp b/wadsrc/static/shaders/glsl/main.fp index 55904432c..29f01c4d0 100644 --- a/wadsrc/static/shaders/glsl/main.fp +++ b/wadsrc/static/shaders/glsl/main.fp @@ -298,6 +298,7 @@ float R_DoomColormap(float light, float z) //=========================================================================== float R_DoomLightingEquation(float light) { +#ifndef PALETTE_EMULATION // z is the depth in view space, positive going into the screen float z; if (((uPalLightLevels >> 8) & 0xff) == 2) @@ -326,6 +327,9 @@ float R_DoomLightingEquation(float light) // Result is the normalized colormap index (0 bright .. 1 dark) return clamp(colormap, 0.0, 31.0) / 32.0; +#else + return 0.0; // with palette emulation we do not want real lighting. +#endif } //===========================================================================