diff --git a/src/common/engine/renderstyle.h b/src/common/engine/renderstyle.h index 7d0a7b8774..70ad5d5614 100644 --- a/src/common/engine/renderstyle.h +++ b/src/common/engine/renderstyle.h @@ -51,12 +51,10 @@ enum ETexMode TM_OPAQUE, // (r, g, b, 1) TM_INVERSE, // (1-r, 1-g, 1-b, a) TM_ALPHATEXTURE, // (1, 1, 1, r) - TM_INVERTOPAQUE = 6, // (1-r, 1-g, 1-b, 1) + 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) 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/gl/gl_renderstate.cpp b/src/common/rendering/gl/gl_renderstate.cpp index b8272e58dd..c660fb98e1 100644 --- a/src/common/rendering/gl/gl_renderstate.cpp +++ b/src/common/rendering/gl/gl_renderstate.cpp @@ -124,9 +124,7 @@ bool FGLRenderState::ApplyShader() activeShader->muDesaturation.Set(mStreamData.uDesaturationFactor); activeShader->muFogEnabled.Set(fogset); - int f = mTextureModeFlags; - if (!mBrightmapEnabled) f &= ~(TEXF_Brightmap | TEXF_Glowmap); - activeShader->muTextureMode.Set((mTextureMode == TM_NORMAL && mTempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode) | f); + activeShader->muTextureMode.Set(GetTextureModeAndFlags(mTempTM)); activeShader->muLightParms.Set(mLightParms); activeShader->muFogColor.Set(mStreamData.uFogColor); activeShader->muObjectColor.Set(mStreamData.uObjectColor); diff --git a/src/common/rendering/gles/gles_renderstate.cpp b/src/common/rendering/gles/gles_renderstate.cpp index fa2561d175..78bfc23de0 100644 --- a/src/common/rendering/gles/gles_renderstate.cpp +++ b/src/common/rendering/gles/gles_renderstate.cpp @@ -144,14 +144,15 @@ bool FGLRenderState::ApplyShader() } - flavour.textureMode = (mTextureMode == TM_NORMAL && mTempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode) & 0xff; - if (mTextureClamp && flavour.textureMode == TM_NORMAL) flavour.textureMode = 5; // fixme. Clamp can now be combined with all modes. + int tm = GetTextureModeAndFlags(mTempTM); + flavour.textureMode = tm & 0xffff; + flavour.texFlags = tm >> 16; //Move flags to start of word + + if (mTextureClamp && flavour.textureMode == TM_NORMAL) flavour.textureMode = TM_CLAMPY; // fixme. Clamp can now be combined with all modes. if (flavour.textureMode == -1) flavour.textureMode = 0; - flavour.texFlags = mTextureModeFlags; if (!mBrightmapEnabled) flavour.texFlags &= ~(TEXF_Brightmap | TEXF_Glowmap); - flavour.texFlags >>= 16; //Move flags to start of word flavour.blendFlags = (int)(mStreamData.uTextureAddColor.a + 0.01); @@ -238,9 +239,6 @@ bool FGLRenderState::ApplyShader() activeShader->cur->muDesaturation.Set(mStreamData.uDesaturationFactor); //activeShader->cur->muFogEnabled.Set(fogset); - int f = mTextureModeFlags; - if (!mBrightmapEnabled) f &= ~(TEXF_Brightmap | TEXF_Glowmap); - //activeShader->cur->muTextureMode.Set((mTextureMode == TM_NORMAL && mTempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode) | f); activeShader->cur->muLightParms.Set(mLightParms); activeShader->cur->muFogColor.Set(mStreamData.uFogColor); activeShader->cur->muObjectColor.Set(mStreamData.uObjectColor); diff --git a/src/common/rendering/hwrenderer/data/hw_renderstate.h b/src/common/rendering/hwrenderer/data/hw_renderstate.h index ebe172da82..5b4af56811 100644 --- a/src/common/rendering/hwrenderer/data/hw_renderstate.h +++ b/src/common/rendering/hwrenderer/data/hw_renderstate.h @@ -378,6 +378,14 @@ public: return mTextureMode; } + int GetTextureModeAndFlags(int tempTM) + { + int f = mTextureModeFlags; + if (!mBrightmapEnabled) f &= ~(TEXF_Brightmap | TEXF_Glowmap); + if (mTextureClamp) f |= TEXF_ClampY; + return (mTextureMode == TM_NORMAL && tempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode) | f; + } + void EnableTexture(bool on) { mTextureEnabled = on; diff --git a/src/common/rendering/polyrenderer/backend/poly_renderstate.cpp b/src/common/rendering/polyrenderer/backend/poly_renderstate.cpp index 9a1d9d12a4..14077e4893 100644 --- a/src/common/rendering/polyrenderer/backend/poly_renderstate.cpp +++ b/src/common/rendering/polyrenderer/backend/poly_renderstate.cpp @@ -287,7 +287,7 @@ void PolyRenderState::Apply() PolyPushConstants constants; constants.uFogEnabled = fogset; - constants.uTextureMode = (mTextureMode == TM_NORMAL && mTempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode); + constants.uTextureMode = GetTextureModeAndFlags(mTempTM); constants.uLightDist = mLightParms[0]; constants.uLightFactor = mLightParms[1]; constants.uFogDensity = mLightParms[2]; diff --git a/src/common/rendering/polyrenderer/drawers/screen_shader.cpp b/src/common/rendering/polyrenderer/drawers/screen_shader.cpp index c6dae48b7d..7e225bef1f 100644 --- a/src/common/rendering/polyrenderer/drawers/screen_shader.cpp +++ b/src/common/rendering/polyrenderer/drawers/screen_shader.cpp @@ -380,11 +380,7 @@ static void ProcessMaterial(int x0, int x1, PolyTriangleThreadData* thread) { auto constants = thread->PushConstants; - if (constants->uTextureMode == TM_CLAMPY) - { - FuncNormal_ClampY(x0, x1, thread); - } - else switch (constants->uTextureMode & 0xff) + switch (constants->uTextureMode) { default: case TM_NORMAL: @@ -393,6 +389,7 @@ static void ProcessMaterial(int x0, int x1, PolyTriangleThreadData* thread) case TM_OPAQUE: FuncNormal_Opaque(x0, x1, thread); break; case TM_INVERSE: FuncNormal_Inverse(x0, x1, thread); break; case TM_ALPHATEXTURE: FuncNormal_AlphaTexture(x0, x1, thread); break; + case TM_CLAMPY: FuncNormal_ClampY(x0, x1, thread); break; case TM_INVERTOPAQUE: FuncNormal_InvertOpaque(x0, x1, thread); break; } diff --git a/src/common/rendering/vulkan/renderer/vk_renderstate.cpp b/src/common/rendering/vulkan/renderer/vk_renderstate.cpp index b933046e30..d8314405d6 100644 --- a/src/common/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/common/rendering/vulkan/renderer/vk_renderstate.cpp @@ -371,9 +371,7 @@ void VkRenderState::ApplyPushConstants() tempTM = TM_OPAQUE; mPushConstants.uFogEnabled = fogset; - int f = mTextureModeFlags; - if (!mBrightmapEnabled) f &= ~(TEXF_Brightmap|TEXF_Glowmap); - mPushConstants.uTextureMode = (mTextureMode == TM_NORMAL && tempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode) | f; + mPushConstants.uTextureMode = GetTextureModeAndFlags(tempTM); mPushConstants.uLightDist = mLightParms[0]; mPushConstants.uLightFactor = mLightParms[1]; mPushConstants.uFogDensity = mLightParms[2]; diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index c5a85fd6b2..a24dba5fa4 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -92,6 +92,7 @@ enum texflags TEXF_Brightmap = 0x10000, TEXF_Detailmap = 0x20000, TEXF_Glowmap = 0x40000, + TEXF_ClampY = 0x80000, }; diff --git a/wadsrc/static/shaders/glsl/main.fp b/wadsrc/static/shaders/glsl/main.fp index 513dae3a70..c77cc79fe6 100644 --- a/wadsrc/static/shaders/glsl/main.fp +++ b/wadsrc/static/shaders/glsl/main.fp @@ -45,6 +45,7 @@ vec2 GetTexCoord(); const int TEXF_Brightmap = 0x10000; const int TEXF_Detailmap = 0x20000; const int TEXF_Glowmap = 0x40000; +const int TEXF_ClampY = 0x80000; //=========================================================================== // @@ -166,7 +167,7 @@ vec4 getTexel(vec2 st) // // Apply texture modes // - switch (uTextureMode & 0xfff) + switch (uTextureMode & 0xffff) { case 1: // TM_STENCIL texel.rgb = vec3(1.0,1.0,1.0); @@ -187,6 +188,13 @@ 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; @@ -195,7 +203,8 @@ vec4 getTexel(vec2 st) return texel; } - if ((uTextureMode & 0x1000) != 0) // TM_CLAMPY + + if (uTextureMode & TEXF_ClampY) { if (st.t < 0.0 || st.t > 1.0) {