From ed8a21fd86d5f9636e6bb47f81c3e320166a4b61 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 14 Jul 2014 21:14:43 +0200 Subject: [PATCH] - replaced deprecated alpha testing with shader code. --- src/gl/renderer/gl_renderer.cpp | 4 +--- src/gl/renderer/gl_renderstate.cpp | 15 +------------- src/gl/renderer/gl_renderstate.h | 26 ++----------------------- src/gl/scene/gl_decal.cpp | 2 +- src/gl/scene/gl_flats.cpp | 2 +- src/gl/scene/gl_portal.cpp | 2 +- src/gl/scene/gl_scene.cpp | 21 ++++++++------------ src/gl/scene/gl_skydome.cpp | 6 ++---- src/gl/scene/gl_sprite.cpp | 16 +++------------ src/gl/scene/gl_walls_draw.cpp | 10 ++++------ src/gl/scene/gl_weapon.cpp | 7 ++----- src/gl/shaders/gl_shader.cpp | 1 + src/gl/shaders/gl_shader.h | 1 + src/gl/system/gl_framebuffer.cpp | 1 - src/gl/system/gl_system.h | 4 +--- src/gl/system/gl_wipe.cpp | 6 +++--- wadsrc/static/shaders/glsl/main.fp | 6 ++++++ wadsrc/static/shaders/glsl/main.vp | 4 ++-- wadsrc/static/shaders/glsl/shaderdefs.i | 4 ++-- 19 files changed, 42 insertions(+), 96 deletions(-) diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index 2f17ff99b..ae2ba2125 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -383,7 +383,7 @@ void FGLRenderer::DrawTexture(FTexture *img, DCanvas::DrawParms &parms) glScissor(parms.lclip, btm - parms.dclip + space, parms.rclip - parms.lclip, parms.dclip - parms.uclip); gl_RenderState.SetColor(color); - gl_RenderState.EnableAlphaTest(false); + gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); gl_RenderState.Apply(); FFlatVertex *ptr = GLRenderer->mVBO->GetBuffer(); @@ -409,8 +409,6 @@ void FGLRenderer::DrawTexture(FTexture *img, DCanvas::DrawParms &parms) GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP); } - 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 27e4465c1..917170872 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -75,8 +75,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; mObjectColor = 0xffffffff; @@ -151,6 +149,7 @@ bool FRenderState::ApplyShader() activeShader->muInterpolationFactor.Set(mInterpolationFactor); activeShader->muClipHeightTop.Set(mClipHeightTop); activeShader->muClipHeightBottom.Set(mClipHeightBottom); + activeShader->muAlphaThreshold.Set(mAlphaThreshold); if (mGlowEnabled) { @@ -269,18 +268,6 @@ void FRenderState::Apply() glDstBlend = mDstBlend; glBlendFunc(mSrcBlend, mDstBlend); } - if (mAlphaFunc != glAlphaFunc || mAlphaThreshold != glAlphaThreshold) - { - glAlphaFunc = mAlphaFunc; - glAlphaThreshold = mAlphaThreshold; - ::glAlphaFunc(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 d650e49b4..d8168bca5 100644 --- a/src/gl/renderer/gl_renderstate.h +++ b/src/gl/renderer/gl_renderstate.h @@ -53,7 +53,6 @@ class FRenderState int mNumLights[4]; float *mLightData; int mSrcBlend, mDstBlend; - int mAlphaFunc; float mAlphaThreshold; bool mAlphaTest; int mBlendEquation; @@ -76,7 +75,6 @@ class FRenderState int mColormapState; int glSrcBlend, glDstBlend; - int glAlphaFunc; float glAlphaThreshold; bool glAlphaTest; int glBlendEquation; @@ -281,28 +279,8 @@ public: 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 e6d5c144f..98101c987 100644 --- a/src/gl/scene/gl_decal.cpp +++ b/src/gl/scene/gl_decal.cpp @@ -333,7 +333,7 @@ void GLWall::DrawDecal(DBaseDecal *decal) // 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 fb5da4fd2..91c7f1c7e 100644 --- a/src/gl/scene/gl_flats.cpp +++ b/src/gl/scene/gl_flats.cpp @@ -424,7 +424,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 922269636..0cc602967 100644 --- a/src/gl/scene/gl_portal.cpp +++ b/src/gl/scene/gl_portal.cpp @@ -998,7 +998,7 @@ void GLHorizonPortal::DrawContents() gltexture->Bind(); gl_SetPlaneTextureRotation(sp, gltexture); - 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 bf11730aa..e6dc3098c 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -345,7 +345,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 @@ -374,8 +374,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) { @@ -383,7 +381,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_drawinfo->drawlists[GLDL_MASKED].Sort(); gl_drawinfo->drawlists[GLDL_MASKED].Draw(pass); gl_drawinfo->drawlists[GLDL_FOGMASKED].Sort(); @@ -440,10 +438,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(); @@ -495,10 +493,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); glPolygonOffset(0.0f, 0.0f); @@ -523,8 +520,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); @@ -534,7 +530,7 @@ void FGLRenderer::RenderTranslucent() glDepthMask(true); - gl_RenderState.AlphaFunc(GL_GEQUAL,0.5f); + gl_RenderState.AlphaFunc(GL_GEQUAL, 0.5f); RenderAll.Unclock(); } @@ -577,7 +573,7 @@ void FGLRenderer::DrawScene(bool toscreen) static void FillScreen() { - gl_RenderState.EnableAlphaTest(false); + gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); gl_RenderState.EnableTexture(false); gl_RenderState.Apply(); FFlatVertex *ptr = GLRenderer->mVBO->GetBuffer(); @@ -756,7 +752,6 @@ void FGLRenderer::EndDrawScene(sector_t * viewsector) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); gl_RenderState.ResetColor(); 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 d2014c654..240bf6762 100644 --- a/src/gl/scene/gl_skydome.cpp +++ b/src/gl/scene/gl_skydome.cpp @@ -472,7 +472,7 @@ void GLSkyPortal::DrawContents() gl_RenderState.ResetColor(); 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); gl_MatrixStack.Push(gl_RenderState.mViewMatrix); @@ -481,7 +481,6 @@ void GLSkyPortal::DrawContents() if (origin->texture[0] && origin->texture[0]->tex->gl_info.bSkybox) { RenderBox(origin->skytexno1, origin->texture[0], origin->x_offset[0], origin->sky2); - gl_RenderState.EnableAlphaTest(true); } else { @@ -495,8 +494,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 ab0586f58..c70422b32 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -137,11 +137,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) @@ -165,7 +165,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); gl_RenderState.SetColor(0.2f,0.2f,0.2f,fuzzalpha, Colormap.desaturation); additivefog = true; } @@ -294,16 +294,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); - } } gl_RenderState.SetObjectColor(0xffffffff); diff --git a/src/gl/scene/gl_walls_draw.cpp b/src/gl/scene/gl_walls_draw.cpp index b932691de..e28f6315c 100644 --- a/src/gl/scene/gl_walls_draw.cpp +++ b/src/gl/scene/gl_walls_draw.cpp @@ -301,9 +301,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(RWF_BLANK); - gl_RenderState.EnableAlphaTest(true); gl_RenderState.SetEffect(EFF_NONE); } } @@ -349,7 +348,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 @@ -383,8 +382,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; @@ -408,7 +407,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 219eaf115..d0f2ab370 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(); FFlatVertex *ptr = GLRenderer->mVBO->GetBuffer(); @@ -164,10 +164,7 @@ void FGLRenderer::DrawPSprite (player_t * player,pspdef_t *psp,fixed_t sx, fixed ptr->Set(x2, y2, 0, fU2, fV2); ptr++; GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP); - 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 1dbdada24..4373955c2 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -203,6 +203,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * muInterpolationFactor.Init(hShader, "uInterpolationFactor"); muClipHeightTop.Init(hShader, "uClipHeightTop"); muClipHeightBottom.Init(hShader, "uClipHeightBottom"); + muAlphaThreshold.Init(hShader, "uAlphaThreshold"); timer_index = glGetUniformLocation(hShader, "timer"); lights_index = glGetUniformLocation(hShader, "lights"); diff --git a/src/gl/shaders/gl_shader.h b/src/gl/shaders/gl_shader.h index 663d09122..bed37cbb0 100644 --- a/src/gl/shaders/gl_shader.h +++ b/src/gl/shaders/gl_shader.h @@ -195,6 +195,7 @@ class FShader FBufferedUniform1f muInterpolationFactor; FBufferedUniform1f muClipHeightTop; FBufferedUniform1f muClipHeightBottom; + FBufferedUniform1f muAlphaThreshold; int timer_index; int lights_index; diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index e34eb5fce..d3783fd42 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -150,7 +150,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); diff --git a/src/gl/system/gl_system.h b/src/gl/system/gl_system.h index 8140904a2..8273960f9 100644 --- a/src/gl/system/gl_system.h +++ b/src/gl/system/gl_system.h @@ -68,15 +68,13 @@ //GL headers #include +//#include "gl_load.h" #if defined(__APPLE__) #include #elif defined(__unix__) //#include #else // !__APPLE__ && !__unix__ - #define DWORD WINDOWS_DWORD // I don't want to depend on this throughout the GL code! - #include - #undef DWORD #endif #ifdef _WIN32 diff --git a/src/gl/system/gl_wipe.cpp b/src/gl/system/gl_wipe.cpp index e4627fd35..12e7c9e02 100644 --- a/src/gl/system/gl_wipe.cpp +++ b/src/gl/system/gl_wipe.cpp @@ -280,7 +280,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.ResetColor(); gl_RenderState.Apply(); fb->wipestartscreen->Bind(0); @@ -302,7 +302,7 @@ bool OpenGLFrameBuffer::Wiper_Crossfade::Run(int ticks, OpenGLFrameBuffer *fb) gl_RenderState.SetColorAlpha(0xffffff, clamp(Clock/32.f, 0.f, 1.f)); gl_RenderState.Apply(); GLRenderer->mVBO->RenderArray(GL_TRIANGLE_STRIP, offset, count); - 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.ResetColor(); gl_RenderState.Apply(); fb->wipestartscreen->Bind(0); diff --git a/wadsrc/static/shaders/glsl/main.fp b/wadsrc/static/shaders/glsl/main.fp index 5655493bd..30a815b3c 100644 --- a/wadsrc/static/shaders/glsl/main.fp +++ b/wadsrc/static/shaders/glsl/main.fp @@ -223,6 +223,12 @@ void main() #endif vec4 frag = ProcessTexel(); + +#ifndef NO_DISCARD + // alpha testing + if (frag.a <= uAlphaThreshold) discard; +#endif + switch (uFixedColormap) { diff --git a/wadsrc/static/shaders/glsl/main.vp b/wadsrc/static/shaders/glsl/main.vp index 58ca931fb..7a434ccbe 100644 --- a/wadsrc/static/shaders/glsl/main.vp +++ b/wadsrc/static/shaders/glsl/main.vp @@ -52,8 +52,8 @@ void main() #ifdef SPHEREMAP vec3 u = normalize(eyeCoordPos.xyz); - vec3 n = normalize(TextureMatrix * vec4(tc.x, 0.0, tc.y, 0.0); // use texture matrix and coordinates for our normal. Since this is only used on walls, the normal's y coordinate is always 0. - vec3 r = reflect(u, n); + vec4 n = normalize(TextureMatrix * vec4(tc.x, 0.0, tc.y, 0.0)); // use texture matrix and coordinates for our normal. Since this is only used on walls, the normal's y coordinate is always 0. + vec3 r = reflect(u, n.xyz); float m = 2.0 * sqrt( r.x*r.x + r.y*r.y + (r.z+1.0)*(r.z+1.0) ); vec2 sst = vec2(r.x/m + 0.5, r.y/m + 0.5); gl_TexCoord[0].xy = sst; diff --git a/wadsrc/static/shaders/glsl/shaderdefs.i b/wadsrc/static/shaders/glsl/shaderdefs.i index 867e9a709..56e6965b2 100644 --- a/wadsrc/static/shaders/glsl/shaderdefs.i +++ b/wadsrc/static/shaders/glsl/shaderdefs.i @@ -4,6 +4,7 @@ uniform vec4 uCameraPos; uniform float uClipHeightTop, uClipHeightBottom; uniform int uTextureMode; +uniform float uAlphaThreshold; // colors uniform vec4 uObjectColor; @@ -34,8 +35,7 @@ uniform int uFogEnabled; // dynamic lights uniform ivec4 uLightRange; - -// redefine the matrix names to what they actually represent. +// matrices uniform mat4 ProjectionMatrix; uniform mat4 ViewMatrix; uniform mat4 ModelMatrix;