From 918e9e9b0d1e6d5162ef885d408a319b0c793ebd Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 17 Sep 2021 00:25:28 +0200 Subject: [PATCH] - fixed texture clamping for elements that are partially behind a slope. This is mainly mid textures on linedefs and decals. --- src/common/engine/renderstyle.h | 6 ++++-- .../rendering/hwrenderer/data/hw_renderstate.h | 3 ++- src/rendering/hwrenderer/scene/hw_decal.cpp | 2 +- src/rendering/hwrenderer/scene/hw_walls.cpp | 10 +++++----- wadsrc/static/shaders/glsl/main.fp | 16 ++++++++-------- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/common/engine/renderstyle.h b/src/common/engine/renderstyle.h index 70ad5d561..7d0a7b877 100644 --- a/src/common/engine/renderstyle.h +++ b/src/common/engine/renderstyle.h @@ -51,10 +51,12 @@ enum ETexMode TM_OPAQUE, // (r, g, b, 1) TM_INVERSE, // (1-r, 1-g, 1-b, a) TM_ALPHATEXTURE, // (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_INVERTOPAQUE = 6, // (1-r, 1-g, 1-b, 1) TM_FOGLAYER, // (renders a fog layer in the shape of the active texture) TM_FIXEDCOLORMAP = TM_FOGLAYER, // repurposes the objectcolor uniforms to render a fixed colormap range. (Same constant because they cannot be used in the same context. + + TM_CLAMPY = 0x1000, // (r, g, b, (t >= 0.0 && t <= 1.0)? a:0) + }; // Legacy render styles diff --git a/src/common/rendering/hwrenderer/data/hw_renderstate.h b/src/common/rendering/hwrenderer/data/hw_renderstate.h index 4751cba0b..e6c63ba44 100644 --- a/src/common/rendering/hwrenderer/data/hw_renderstate.h +++ b/src/common/rendering/hwrenderer/data/hw_renderstate.h @@ -342,7 +342,7 @@ public: mTextureMode = mode; } - void SetTextureMode(FRenderStyle style) + void SetTextureMode(FRenderStyle style, bool clampy = false) { if (style.Flags & STYLEF_RedIsAlpha) { @@ -356,6 +356,7 @@ public: { SetTextureMode(TM_INVERSE); } + if (clampy) mTextureMode |= TM_CLAMPY; } int GetTextureMode() diff --git a/src/rendering/hwrenderer/scene/hw_decal.cpp b/src/rendering/hwrenderer/scene/hw_decal.cpp index ac1b34e85..04fe5d4a1 100644 --- a/src/rendering/hwrenderer/scene/hw_decal.cpp +++ b/src/rendering/hwrenderer/scene/hw_decal.cpp @@ -61,7 +61,7 @@ void HWDecal::DrawDecal(HWDrawInfo *di, FRenderState &state) state.SetObjectColor(DecalColor); state.SetLightIndex(dynlightindex); - state.SetTextureMode(decal->RenderStyle); + state.SetTextureMode(decal->RenderStyle, true); state.SetRenderStyle(decal->RenderStyle); state.SetMaterial(texture, UF_Sprite, 0, CLAMP_XY, decal->Translation, -1); diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index 4abf8d33d..5df353550 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -208,13 +208,13 @@ void HWWall::RenderTexturedWall(HWDrawInfo *di, FRenderState &state, int rflags) } #endif + if (flags & HWWall::HWF_CLAMPY && (type == RENDERWALL_M2S || type == RENDERWALL_M2SNF)) + { + state.SetTextureMode(tmode | TM_CLAMPY); + } if (type == RENDERWALL_M2SNF) { - if (flags & HWWall::HWF_CLAMPY) - { - if (tmode == TM_NORMAL) state.SetTextureMode(TM_CLAMPY); - } di->SetFog(state, 255, 0, di->isFullbrightScene(), nullptr, false); } if (type != RENDERWALL_COLOR && seg->sidedef != nullptr) @@ -1933,7 +1933,7 @@ void HWWall::Process(HWDrawInfo *di, seg_t *seg, sector_t * frontsector, sector_ sector_t * segback; #ifdef _DEBUG - if (seg->linedef->Index() == 14454) + if (seg->linedef->Index() == 759) { int a = 0; } diff --git a/wadsrc/static/shaders/glsl/main.fp b/wadsrc/static/shaders/glsl/main.fp index 63b92bd7e..90ad8cbee 100644 --- a/wadsrc/static/shaders/glsl/main.fp +++ b/wadsrc/static/shaders/glsl/main.fp @@ -166,7 +166,7 @@ vec4 getTexel(vec2 st) // // Apply texture modes // - switch (uTextureMode & 0xffff) + switch (uTextureMode & 0xfff) { case 1: // TM_STENCIL texel.rgb = vec3(1.0,1.0,1.0); @@ -187,13 +187,6 @@ vec4 getTexel(vec2 st) break; } - case 5: // TM_CLAMPY - if (st.t < 0.0 || st.t > 1.0) - { - texel.a = 0.0; - } - break; - case 6: // TM_OPAQUEINVERSE texel = vec4(1.0-texel.r, 1.0-texel.b, 1.0-texel.g, 1.0); break; @@ -202,6 +195,13 @@ vec4 getTexel(vec2 st) return texel; } + if ((uTextureMode & 0x1000) != 0) // TM_CLAMPY + { + if (st.t < 0.0 || st.t > 1.0) + { + texel.a = 0.0; + } + } // Apply the texture modification colors. int blendflags = int(uTextureAddColor.a); // this alpha is unused otherwise