From 612fb40f3a89bd7bbf322c8dce43d20dbefbe071 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 14 Jun 2018 21:28:03 +0200 Subject: [PATCH] - don't use uniforms related to fixed colormaps for other things. The fixed colormap is a per-scene global setting that normally does not need to change ever during rendering of a scene so it's easily shoved aside into a static uniform buffer. Having to change this buffer for inconsequential stuff should be avoided, especially when there's other uniforms that are just as good to hold these values. --- src/gl/renderer/gl_renderer.cpp | 2 +- src/gl/renderer/gl_renderstate.cpp | 20 ++----------- src/gl/renderer/gl_renderstate.h | 6 ---- src/gl/scene/gl_sprite.cpp | 4 +-- src/gl_load/gl_interface.h | 1 + wadsrc/static/shaders/glsl/main.fp | 46 +++++++++++++++++------------- 6 files changed, 32 insertions(+), 47 deletions(-) diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index cac056bd4..81b9a401d 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -565,7 +565,7 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer) { if (!gl.legacyMode) { - gl_RenderState.Set2DOverlayColor(cmd.mColor1); + gl_RenderState.SetFog(cmd.mColor1, 0); gl_RenderState.SetFixedColormap(CM_PLAIN2D); } else if (cmd.mDesaturate > 0) diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index a0a1c5cc8..9473a057a 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -221,25 +221,9 @@ bool FRenderState::ApplyShader() activeShader->currentcliplinestate = 0; } - if (mColormapState < -1) // 2D operations + if (mColormapState == CM_PLAIN2D) // 2D operations { - if (mColormapState != CM_SPECIAL2D) - { - activeShader->muColormapStart.Set(m2DColors[0]); - activeShader->muFixedColormap.Set(4); - } - else - { - float startr = m2DColors[0].r / 255.f; - float startg = m2DColors[0].g / 255.f; - float startb = m2DColors[0].b / 255.f; - float ranger = m2DColors[1].r / 255.f - startr; - float rangeg = m2DColors[1].g / 255.f - startg; - float rangeb = m2DColors[1].b / 255.f - startb; - activeShader->muColormapStart.Set(startr, startg, startb, 0.f); - activeShader->muColormapRange.Set(ranger, rangeg, rangeb, 0.f); - activeShader->muFixedColormap.Set(1); - } + activeShader->muFixedColormap.Set(4); activeShader->currentfixedcolormap = mColormapState; } else if (mColormapState != activeShader->currentfixedcolormap) diff --git a/src/gl/renderer/gl_renderstate.h b/src/gl/renderer/gl_renderstate.h index 8aa4d0093..3cd505611 100644 --- a/src/gl/renderer/gl_renderstate.h +++ b/src/gl/renderer/gl_renderstate.h @@ -112,7 +112,6 @@ class FRenderState PalEntry mFogColor; PalEntry mObjectColor; PalEntry mObjectColor2; - PalEntry m2DColors[2]; // in the shader these will reuse the colormap ramp uniforms. FStateVec4 mDynColor; float mClipSplit[2]; @@ -402,11 +401,6 @@ public: mObjectColor2 = pe; } - void Set2DOverlayColor(PalEntry pe) - { - m2DColors[0] = pe; - } - void SetSpecular(float glossiness, float specularLevel) { mGlossiness = glossiness; diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index 2bafaf72a..b4116d60e 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -266,12 +266,12 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass) { // If we get here we know that we have colored fog and no fixed colormap. mDrawer->SetFog(sprite->foglevel, rel, &sprite->Colormap, additivefog); - gl_RenderState.SetFixedColormap(CM_FOGLAYER); + gl_RenderState.SetTextureMode(TM_FOGLAYER); gl_RenderState.BlendEquation(GL_FUNC_ADD); gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); gl_RenderState.Apply(); qd.Render(GL_TRIANGLE_STRIP); - gl_RenderState.SetFixedColormap(CM_DEFAULT); + gl_RenderState.SetTextureMode(TM_MODULATE); } } else diff --git a/src/gl_load/gl_interface.h b/src/gl_load/gl_interface.h index 1fa697cdf..35568e0e6 100644 --- a/src/gl_load/gl_interface.h +++ b/src/gl_load/gl_interface.h @@ -21,6 +21,7 @@ enum TexMode TM_REDTOALPHA, // (1, 1, 1, r) TM_CLAMPY, // (r, g, b, (t >= 0.0 && t <= 1.0)? a:0) TM_INVERTOPAQUE, // (1-r, 1-g, 1-b, 1) + TM_FOGLAYER, // (renders a fog layer in the shape of the active texture) }; enum ELightMethod diff --git a/wadsrc/static/shaders/glsl/main.fp b/wadsrc/static/shaders/glsl/main.fp index 3e47f0e43..0fdd3abdd 100644 --- a/wadsrc/static/shaders/glsl/main.fp +++ b/wadsrc/static/shaders/glsl/main.fp @@ -89,6 +89,9 @@ vec4 getTexel(vec2 st) case 6: // TM_OPAQUEINVERSE texel = vec4(1.0-texel.r, 1.0-texel.b, 1.0-texel.g, 1.0); break; + + case 7: //TM_FOGLAYER + return texel; } if (uObjectColor2.a == 0.0) texel *= uObjectColor; else texel *= mix(uObjectColor, uObjectColor2, glowdist.z); @@ -428,7 +431,27 @@ void main() if (frag.a <= uAlphaThreshold) discard; #endif - switch (uFixedColormap) + if (uTextureMode == 7) + { + float fogdist; + float fogfactor; + + // + // calculate fog factor + // + if (uFogEnabled == -1) + { + fogdist = pixelpos.w; + } + else + { + fogdist = max(16.0, distance(pixelpos.xyz, uCameraPos.xyz)); + } + fogfactor = exp2 (uFogDensity * fogdist); + + frag = vec4(uFogColor.rgb, (1.0 - fogfactor) * frag.a * 0.75 * vColor.a); + } + else switch (uFixedColormap) { case 0: // in-game rendering. { @@ -480,32 +503,15 @@ void main() break; } - case 3: // fog layer + case 3: // unused { - float fogdist; - float fogfactor; - - // - // calculate fog factor - // - if (uFogEnabled == -1) - { - fogdist = pixelpos.w; - } - else - { - fogdist = max(16.0, distance(pixelpos.xyz, uCameraPos.xyz)); - } - fogfactor = exp2 (uFogDensity * fogdist); - - frag = vec4(uFogColor.rgb, (1.0 - fogfactor) * frag.a * 0.75 * vColor.a); break; } case 4: // simple 2D (reuses a uniform for the special colormap for the color overlay.) { frag = frag * ProcessLight(vColor); - frag.rgb = frag.rgb + uFixedColormapStart.rgb; + frag.rgb = frag.rgb + uFogColor.rgb; break; }