From 08fc74a4ad7a8d611d2c8fa302109c6bcd94d10d Mon Sep 17 00:00:00 2001 From: Evghenii Date: Mon, 26 Aug 2024 02:07:23 -0400 Subject: [PATCH] - replaced deprecated alpha testing with shader code. --- src/gl/renderer/gl_renderer.cpp | 4 +--- src/gl/renderer/gl_renderstate.cpp | 16 ++-------------- src/gl/renderer/gl_renderstate.h | 28 ++-------------------------- src/gl/scene/gl_decal.cpp | 2 +- src/gl/scene/gl_flats.cpp | 2 +- src/gl/scene/gl_portal.cpp | 4 ++-- src/gl/scene/gl_scene.cpp | 23 +++++++++-------------- src/gl/scene/gl_skydome.cpp | 8 +++----- src/gl/scene/gl_sprite.cpp | 20 +++++--------------- src/gl/scene/gl_walls_draw.cpp | 10 ++++------ src/gl/scene/gl_weapon.cpp | 7 ++----- src/gl/shaders/gl_shader.cpp | 3 +++ src/gl/shaders/gl_shader.h | 3 +++ src/gl/system/gl_framebuffer.cpp | 1 - src/gl/system/gl_wipe.cpp | 6 +++--- wadsrc/static/shaders/glsl/main.fp | 11 ++++++++--- 16 files changed, 49 insertions(+), 99 deletions(-) diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index 03f36471f..affb6684c 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -410,7 +410,7 @@ void FGLRenderer::DrawTexture(FTexture *img, DCanvas::DrawParms &parms) glColor4f(r, g, b, FIXED2FLOAT(parms.alpha)); - gl_RenderState.EnableAlphaTest(false); + gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); gl_RenderState.Apply(); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(u1, v1); @@ -442,8 +442,6 @@ void FGLRenderer::DrawTexture(FTexture *img, DCanvas::DrawParms &parms) glEnd(); } - gl_RenderState.EnableAlphaTest(true); - glScissor(0, 0, screen->GetWidth(), screen->GetHeight()); glDisable(GL_SCISSOR_TEST); gl_RenderState.SetTextureMode(TM_MODULATE); diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index fd7404567..69da14978 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -77,8 +77,6 @@ void FRenderState::Reset() mSrcBlend = GL_SRC_ALPHA; mDstBlend = GL_ONE_MINUS_SRC_ALPHA; glSrcBlend = glDstBlend = -1; - glAlphaFunc = -1; - mAlphaFunc = GL_GEQUAL; mAlphaThreshold = 0.5f; mBlendEquation = GL_FUNC_ADD; glBlendEquation = -1; @@ -209,6 +207,8 @@ bool FRenderState::ApplyShader() } } + glUniform1f(activeShader->alpha_threshold, mAlphaThreshold); + if (fogset != activeShader->currentfogenabled) { glUniform1i(activeShader->fogenabled_index, (activeShader->currentfogenabled = fogset)); @@ -280,18 +280,6 @@ void FRenderState::Apply(bool forcenoshader) glDstBlend = mDstBlend; glBlendFunc(mSrcBlend, mDstBlend); } - if (mAlphaFunc != glAlphaFunc || mAlphaThreshold != glAlphaThreshold) - { - glAlphaFunc = mAlphaFunc; - glAlphaThreshold = mAlphaThreshold; - ::glBlendFunc(mAlphaFunc, mAlphaThreshold); - } - if (mAlphaTest != glAlphaTest) - { - glAlphaTest = mAlphaTest; - if (mAlphaTest) glEnable(GL_ALPHA_TEST); - else glDisable(GL_ALPHA_TEST); - } if (mBlendEquation != glBlendEquation) { glBlendEquation = mBlendEquation; diff --git a/src/gl/renderer/gl_renderstate.h b/src/gl/renderer/gl_renderstate.h index 6fea56707..28d6d858c 100644 --- a/src/gl/renderer/gl_renderstate.h +++ b/src/gl/renderer/gl_renderstate.h @@ -97,9 +97,7 @@ class FRenderState int mNumLights[3]; float *mLightData; int mSrcBlend, mDstBlend; - int mAlphaFunc; float mAlphaThreshold; - bool mAlphaTest; int mBlendEquation; bool m2D; @@ -113,9 +111,7 @@ class FRenderState float mWarpTime; int glSrcBlend, glDstBlend; - int glAlphaFunc; float glAlphaThreshold; - bool glAlphaTest; int glBlendEquation; bool ffTextureEnabled; @@ -236,28 +232,8 @@ class FRenderState void AlphaFunc(int func, float thresh) { - if (!gl_direct_state_change) - { - mAlphaFunc = func; - mAlphaThreshold = thresh; - } - else - { - ::glAlphaFunc(func, thresh); - } - } - - void EnableAlphaTest(bool on) - { - if (!gl_direct_state_change) - { - mAlphaTest = on; - } - else - { - if (on) glEnable(GL_ALPHA_TEST); - else glDisable(GL_ALPHA_TEST); - } + if (func == GL_GREATER) mAlphaThreshold = thresh; + else mAlphaThreshold = thresh - 0.001f; } void BlendEquation(int eq) diff --git a/src/gl/scene/gl_decal.cpp b/src/gl/scene/gl_decal.cpp index bd39f8008..6ae534e07 100644 --- a/src/gl/scene/gl_decal.cpp +++ b/src/gl/scene/gl_decal.cpp @@ -395,7 +395,7 @@ void GLWall::DrawDecal(DBaseDecal *decal) gl_SetRenderStyle(decal->RenderStyle, false, false); // If srcalpha is one it looks better with a higher alpha threshold - if (decal->RenderStyle.SrcAlpha == STYLEALPHA_One) gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_threshold); + if (decal->RenderStyle.SrcAlpha == STYLEALPHA_One) gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_sprite_threshold); else gl_RenderState.AlphaFunc(GL_GREATER, 0.f); gl_RenderState.Apply(); diff --git a/src/gl/scene/gl_flats.cpp b/src/gl/scene/gl_flats.cpp index 3efdcba8b..97afd2760 100644 --- a/src/gl/scene/gl_flats.cpp +++ b/src/gl/scene/gl_flats.cpp @@ -412,7 +412,7 @@ void GLFlat::Draw(int pass) if (renderstyle==STYLE_Add) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE); gl_SetColor(lightlevel, rel, &Colormap, alpha); gl_SetFog(lightlevel, rel, &Colormap, false); - gl_RenderState.AlphaFunc(GL_GEQUAL,gl_mask_threshold*(alpha)); + gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_threshold); if (!gltexture) { gl_RenderState.EnableTexture(false); diff --git a/src/gl/scene/gl_portal.cpp b/src/gl/scene/gl_portal.cpp index 7ab4a3220..8a8fcf57a 100644 --- a/src/gl/scene/gl_portal.cpp +++ b/src/gl/scene/gl_portal.cpp @@ -934,7 +934,7 @@ int GLMirrorPortal::ClipPoint(fixed_t x, fixed_t y) // are 2 problems with it: // // 1. Setting this up completely negates any performance gains. -// 2. It doesn't work with a 360° field of view (as when you are looking up.) +// 2. It doesn't work with a 360� field of view (as when you are looking up.) // // // So the brute force mechanism is just as good. @@ -985,7 +985,7 @@ void GLHorizonPortal::DrawContents() gltexture->Bind(origin->colormap.colormap); - gl_RenderState.EnableAlphaTest(false); + gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); gl_RenderState.BlendFunc(GL_ONE,GL_ZERO); gl_RenderState.Apply(); diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 9fc2fd4a5..2d241c82c 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -392,7 +392,7 @@ void FGLRenderer::RenderScene(int recursion) glDepthFunc(GL_LESS); - gl_RenderState.EnableAlphaTest(false); + gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); glDisable(GL_POLYGON_OFFSET_FILL); // just in case @@ -422,8 +422,6 @@ void FGLRenderer::RenderScene(int recursion) gl_drawinfo->drawlists[GLDL_LIGHTFOG].Draw(pass); - gl_RenderState.EnableAlphaTest(true); - // Part 2: masked geometry. This is set up so that only pixels with alpha>0.5 will show if (!gl_texture) { @@ -431,7 +429,7 @@ void FGLRenderer::RenderScene(int recursion) gl_RenderState.SetTextureMode(TM_MASK); } if (pass == GLPASS_BASE) pass = GLPASS_BASE_MASKED; - gl_RenderState.AlphaFunc(GL_GEQUAL,gl_mask_threshold); + gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_threshold); gl_RenderState.EnableBrightmap(true); gl_drawinfo->drawlists[GLDL_MASKED].Sort(); gl_drawinfo->drawlists[GLDL_MASKED].Draw(pass); @@ -490,10 +488,10 @@ void FGLRenderer::RenderScene(int recursion) glDepthFunc(GL_LEQUAL); if (gl_texture) { - gl_RenderState.EnableAlphaTest(false); + gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); gl_drawinfo->drawlists[GLDL_LIGHT].Sort(); gl_drawinfo->drawlists[GLDL_LIGHT].Draw(GLPASS_TEXTURE); - gl_RenderState.EnableAlphaTest(true); + gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_threshold); gl_drawinfo->drawlists[GLDL_LIGHTBRIGHT].Sort(); gl_drawinfo->drawlists[GLDL_LIGHTBRIGHT].Draw(GLPASS_TEXTURE); gl_drawinfo->drawlists[GLDL_LIGHTMASKED].Sort(); @@ -550,10 +548,9 @@ void FGLRenderer::RenderScene(int recursion) { glDepthMask(false); // don't write to Z-buffer! gl_RenderState.EnableFog(true); - gl_RenderState.EnableAlphaTest(false); + gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); gl_RenderState.BlendFunc(GL_ONE,GL_ZERO); gl_drawinfo->DrawUnhandledMissingTextures(); - gl_RenderState.EnableAlphaTest(true); } glDepthMask(true); @@ -579,8 +576,7 @@ void FGLRenderer::RenderTranslucent() gl_RenderState.SetCameraPos(FIXED2FLOAT(viewx), FIXED2FLOAT(viewy), FIXED2FLOAT(viewz)); // final pass: translucent stuff - gl_RenderState.EnableAlphaTest(true); - gl_RenderState.AlphaFunc(GL_GEQUAL,gl_mask_sprite_threshold); + gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_sprite_threshold); gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); gl_RenderState.EnableBrightmap(true); @@ -590,7 +586,7 @@ void FGLRenderer::RenderTranslucent() glDepthMask(true); - gl_RenderState.AlphaFunc(GL_GEQUAL,0.5f); + gl_RenderState.AlphaFunc(GL_GEQUAL, 0.5f); RenderAll.Unclock(); } @@ -718,7 +714,7 @@ void FGLRenderer::DrawBlend(sector_t * viewsector) // black multiplicative blends are ignored if (extra_red || extra_green || extra_blue) { - gl_RenderState.EnableAlphaTest(false); + gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); gl_RenderState.EnableTexture(false); gl_RenderState.BlendFunc(GL_DST_COLOR,GL_ZERO); glColor4f(extra_red, extra_green, extra_blue, 1.0f); @@ -756,7 +752,7 @@ void FGLRenderer::DrawBlend(sector_t * viewsector) if (blend[3]>0.0f) { gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - gl_RenderState.EnableAlphaTest(false); + gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); gl_RenderState.EnableTexture(false); glColor4fv(blend); gl_RenderState.Apply(true); @@ -809,7 +805,6 @@ void FGLRenderer::EndDrawScene(sector_t * viewsector) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor3f(1.0f,1.0f,1.0f); gl_RenderState.EnableTexture(true); - gl_RenderState.EnableAlphaTest(true); glDisable(GL_SCISSOR_TEST); } diff --git a/src/gl/scene/gl_skydome.cpp b/src/gl/scene/gl_skydome.cpp index bb03eeaa4..494289aa0 100644 --- a/src/gl/scene/gl_skydome.cpp +++ b/src/gl/scene/gl_skydome.cpp @@ -58,7 +58,7 @@ //----------------------------------------------------------------------------- // -// Shamelessly lifted from Doomsday (written by Jaakko Keränen) +// Shamelessly lifted from Doomsday (written by Jaakko Ker�nen) // also shamelessly lifted from ZDoomGL! ;) // //----------------------------------------------------------------------------- @@ -567,7 +567,7 @@ void GLSkyPortal::DrawContents() } gl_RenderState.EnableFog(false); - gl_RenderState.EnableAlphaTest(false); + gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glMatrixMode(GL_MODELVIEW); @@ -588,7 +588,6 @@ void GLSkyPortal::DrawContents() else R=G=B=1.f; RenderBox(origin->skytexno1, origin->texture[0], origin->x_offset[0], CM_Index, origin->sky2); - gl_RenderState.EnableAlphaTest(true); } else { @@ -601,8 +600,7 @@ void GLSkyPortal::DrawContents() gl_RenderState.SetTextureMode(TM_MODULATE); } - gl_RenderState.EnableAlphaTest(true); - gl_RenderState.AlphaFunc(GL_GEQUAL,0.05f); + gl_RenderState.AlphaFunc(GL_GEQUAL, 0.05f); if (origin->doublesky && origin->texture[1]) { diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index 1a35de6e1..4b29d4a06 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -152,11 +152,11 @@ void GLSprite::Draw(int pass) if (hw_styleflags == STYLEHW_NoAlphaTest) { - gl_RenderState.EnableAlphaTest(false); + gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); } else { - gl_RenderState.AlphaFunc(GL_GEQUAL,trans*gl_mask_sprite_threshold); + gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_sprite_threshold); } if (RenderStyle.BlendOp == STYLEOP_Shadow) @@ -180,7 +180,7 @@ void GLSprite::Draw(int pass) minalpha*=factor; } - gl_RenderState.AlphaFunc(GL_GEQUAL,minalpha*gl_mask_sprite_threshold); + gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_sprite_threshold); glColor4f(0.2f,0.2f,0.2f,fuzzalpha); additivefog = true; } @@ -263,7 +263,7 @@ void GLSprite::Draw(int pass) const bool drawWithXYBillboard = ( (particle && gl_billboard_particles) || (!(actor && actor->renderflags & RF_FORCEYBILLBOARD) //&& GLRenderer->mViewActor != NULL && (gl_billboard_mode == 1 || (actor && actor->renderflags & RF_FORCEXYBILLBOARD ))) ); - gl_RenderState.Apply(); + gl_RenderState.Apply(hw_styleflags == STYLEHW_NoAlphaTest); Vector v1; Vector v2; @@ -322,7 +322,7 @@ void GLSprite::Draw(int pass) gl_RenderState.SetFixedColormap(CM_FOGLAYER); gl_RenderState.BlendEquation(GL_FUNC_ADD); gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - gl_RenderState.Apply(); + gl_RenderState.Apply(hw_styleflags == STYLEHW_NoAlphaTest); glBegin(GL_TRIANGLE_STRIP); if (gltexture) @@ -405,16 +405,6 @@ void GLSprite::Draw(int pass) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); gl_RenderState.BlendEquation(GL_FUNC_ADD); gl_RenderState.SetTextureMode(TM_MODULATE); - - // [BB] Restore the alpha test after drawing a smooth particle. - if (hw_styleflags == STYLEHW_NoAlphaTest) - { - gl_RenderState.EnableAlphaTest(true); - } - else - { - gl_RenderState.AlphaFunc(GL_GEQUAL,gl_mask_sprite_threshold); - } } // End of gl_sprite_brightfog hack: restore FadeColor to normalcy diff --git a/src/gl/scene/gl_walls_draw.cpp b/src/gl/scene/gl_walls_draw.cpp index 2c0ef3228..fdf36bba3 100644 --- a/src/gl/scene/gl_walls_draw.cpp +++ b/src/gl/scene/gl_walls_draw.cpp @@ -304,9 +304,8 @@ void GLWall::RenderFogBoundary() int rel = rellight + getExtraLight(); gl_SetFog(lightlevel, rel, &Colormap, false); gl_RenderState.SetEffect(EFF_FOGBOUNDARY); - gl_RenderState.EnableAlphaTest(false); + gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); RenderWall(0, NULL); - gl_RenderState.EnableAlphaTest(true); gl_RenderState.SetEffect(EFF_NONE); } else @@ -382,7 +381,7 @@ void GLWall::RenderMirrorSurface() // Restore the defaults for the translucent pass gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - gl_RenderState.AlphaFunc(GL_GEQUAL,0.5f*gl_mask_sprite_threshold); + gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_sprite_threshold); glDepthFunc(GL_LESS); // This is drawn in the translucent pass which is done after the decal pass @@ -416,8 +415,8 @@ void GLWall::RenderTranslucentWall() // and until that changes I won't fix this code for the new blending modes! bool isadditive = RenderStyle == STYLE_Add; - if (!transparent) gl_RenderState.AlphaFunc(GL_GEQUAL,gl_mask_threshold*fabs(alpha)); - else gl_RenderState.EnableAlphaTest(false); + if (!transparent) gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_threshold); + else gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); if (isadditive) gl_RenderState.BlendFunc(GL_SRC_ALPHA,GL_ONE); int extra; @@ -442,7 +441,6 @@ void GLWall::RenderTranslucentWall() // restore default settings if (isadditive) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - if (transparent) gl_RenderState.EnableAlphaTest(true); if (!gltexture) { diff --git a/src/gl/scene/gl_weapon.cpp b/src/gl/scene/gl_weapon.cpp index 3de7dada2..2fa83e255 100644 --- a/src/gl/scene/gl_weapon.cpp +++ b/src/gl/scene/gl_weapon.cpp @@ -151,7 +151,7 @@ void FGLRenderer::DrawPSprite (player_t * player,pspdef_t *psp,fixed_t sx, fixed if (tex->GetTransparent() || OverrideShader != 0) { - gl_RenderState.EnableAlphaTest(false); + gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); } gl_RenderState.Apply(); glBegin(GL_TRIANGLE_STRIP); @@ -160,10 +160,7 @@ void FGLRenderer::DrawPSprite (player_t * player,pspdef_t *psp,fixed_t sx, fixed glTexCoord2f(fU2, fV1); glVertex2f(x2,y1); glTexCoord2f(fU2, fV2); glVertex2f(x2,y2); glEnd(); - if (tex->GetTransparent() || OverrideShader != 0) - { - gl_RenderState.EnableAlphaTest(true); - } + gl_RenderState.AlphaFunc(GL_GEQUAL, 0.5f); } //========================================================================== diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index 0014cc16a..0a3d5c3bd 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -172,6 +172,9 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * // only print message if there's an error. Printf("Init Shader '%s':\n%s\n", name, error.GetChars()); } + + alpha_threshold = glGetUniformLocation(hShader, "alpha_threshold"); + timer_index = glGetUniformLocation(hShader, "timer"); desaturation_index = glGetUniformLocation(hShader, "desaturation_factor"); fogenabled_index = glGetUniformLocation(hShader, "fogenabled"); diff --git a/src/gl/shaders/gl_shader.h b/src/gl/shaders/gl_shader.h index c10757d87..b9a4f9ab7 100644 --- a/src/gl/shaders/gl_shader.h +++ b/src/gl/shaders/gl_shader.h @@ -26,6 +26,8 @@ class FShader unsigned int hVertProg; unsigned int hFragProg; + float alpha_threshold; + int timer_index; int desaturation_index; int fogenabled_index; @@ -60,6 +62,7 @@ class FShader currentlightfactor = currentlightdist = 0.0f; currentfogdensity = -1; currentfogcolor = 0; + alpha_threshold = 0.5f; timer_index = -1; desaturation_index = -1; diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index 406d25540..f087cfcf9 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -151,7 +151,6 @@ void OpenGLFrameBuffer::InitializeState() glEnable(GL_TEXTURE_2D); glDisable(GL_LINE_SMOOTH); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glAlphaFunc(GL_GEQUAL,0.5f); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); diff --git a/src/gl/system/gl_wipe.cpp b/src/gl/system/gl_wipe.cpp index c41a1fb24..ad695b6b4 100644 --- a/src/gl/system/gl_wipe.cpp +++ b/src/gl/system/gl_wipe.cpp @@ -278,7 +278,7 @@ bool OpenGLFrameBuffer::Wiper_Crossfade::Run(int ticks, OpenGLFrameBuffer *fb) float vb = fb->GetHeight() / FHardwareTexture::GetTexDimension(fb->GetHeight()); gl_RenderState.SetTextureMode(TM_OPAQUE); - gl_RenderState.EnableAlphaTest(false); + gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); gl_RenderState.Apply(); fb->wipestartscreen->Bind(0, CM_DEFAULT); glColor4f(1.f, 1.f, 1.f, 1.f); @@ -305,7 +305,7 @@ bool OpenGLFrameBuffer::Wiper_Crossfade::Run(int ticks, OpenGLFrameBuffer *fb) glTexCoord2f(ur, 0); glVertex2i(fb->Width, fb->Height); glEnd(); - gl_RenderState.EnableAlphaTest(true); + gl_RenderState.AlphaFunc(GL_GEQUAL, 0.5f); gl_RenderState.SetTextureMode(TM_MODULATE); return Clock >= 32; @@ -490,7 +490,7 @@ bool OpenGLFrameBuffer::Wiper_Burn::Run(int ticks, OpenGLFrameBuffer *fb) // Put the initial screen back to the buffer. gl_RenderState.SetTextureMode(TM_OPAQUE); - gl_RenderState.EnableAlphaTest(false); + gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); gl_RenderState.Apply(); fb->wipestartscreen->Bind(0, CM_DEFAULT); glColor4f(1.f, 1.f, 1.f, 1.f); diff --git a/wadsrc/static/shaders/glsl/main.fp b/wadsrc/static/shaders/glsl/main.fp index aa2c33238..605c95580 100644 --- a/wadsrc/static/shaders/glsl/main.fp +++ b/wadsrc/static/shaders/glsl/main.fp @@ -29,6 +29,7 @@ varying vec4 pixelpos; varying vec4 fogparm; //uniform vec2 lightparms; uniform float desaturation_factor; +uniform float alpha_threshold; uniform vec4 topglowcolor; uniform vec4 bottomglowcolor; @@ -183,6 +184,11 @@ vec4 applyFog(vec4 frag, float fogfactor) void main() { + vec4 frag = Process(vec4(1.0)); + + // alpha testing + if (frag.a <= alpha_threshold) discard; + float fogdist = 0.0; float fogfactor = 0.0; @@ -215,9 +221,8 @@ void main() } #endif - vec4 frag = getLightColor(fogdist, fogfactor); - - + frag = getLightColor(fogdist, fogfactor); + #ifdef DYNLIGHT for(int i=0; i