diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index 4648808955..bdd0867b9f 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -106,8 +106,7 @@ bool FRenderState::ApplyShader() } else { - // todo: check how performance is affected by using 'discard' in a shader and if necessary create a separate set of discard-less shaders. - activeShader = GLRenderer->mShaderManager->Get(mTextureEnabled ? mEffectState : 4); + activeShader = GLRenderer->mShaderManager->Get(mTextureEnabled ? mEffectState : 4, mAlphaThreshold >= 0.f); activeShader->Bind(); } diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index 7cd6ead74f..26a1b3159a 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -387,6 +387,8 @@ void FShaderManager::CompileShaders() { mActiveShader = NULL; + mTextureEffects.Clear(); + mTextureEffectsNAT.Clear(); for (int i = 0; i < MAX_EFFECTS; i++) { mEffectShaders[i] = NULL; @@ -396,6 +398,11 @@ void FShaderManager::CompileShaders() { FShader *shc = Compile(defaultshaders[i].ShaderName, defaultshaders[i].gettexelfunc, true); mTextureEffects.Push(shc); + if (i <= 3) + { + FShader *shc = Compile(defaultshaders[i].ShaderName, defaultshaders[i].gettexelfunc, false); + mTextureEffectsNAT.Push(shc); + } } for(unsigned i = 0; i < usershaders.Size(); i++) @@ -430,6 +437,10 @@ void FShaderManager::Clean() glUseProgram(0); mActiveShader = NULL; + for (unsigned int i = 0; i < mTextureEffectsNAT.Size(); i++) + { + if (mTextureEffectsNAT[i] != NULL) delete mTextureEffectsNAT[i]; + } for (unsigned int i = 0; i < mTextureEffects.Size(); i++) { if (mTextureEffects[i] != NULL) delete mTextureEffects[i]; @@ -440,6 +451,7 @@ void FShaderManager::Clean() mEffectShaders[i] = NULL; } mTextureEffects.Clear(); + mTextureEffectsNAT.Clear(); } //========================================================================== @@ -504,10 +516,12 @@ EXTERN_CVAR(Int, gl_fuzztype) void FShaderManager::ApplyMatrices(VSMatrix *proj, VSMatrix *view) { - for (int i = 0; i <= 4; i++) + for (int i = 0; i < 4; i++) { mTextureEffects[i]->ApplyMatrices(proj, view); + mTextureEffectsNAT[i]->ApplyMatrices(proj, view); } + mTextureEffects[4]->ApplyMatrices(proj, view); if (gl_fuzztype != 0) { mTextureEffects[4+gl_fuzztype]->ApplyMatrices(proj, view); diff --git a/src/gl/shaders/gl_shader.h b/src/gl/shaders/gl_shader.h index e100e9bf1a..92ef221af2 100644 --- a/src/gl/shaders/gl_shader.h +++ b/src/gl/shaders/gl_shader.h @@ -249,6 +249,7 @@ public: class FShaderManager { TArray mTextureEffects; + TArray mTextureEffectsNAT; FShader *mActiveShader; FShader *mEffectShaders[MAX_EFFECTS]; @@ -268,9 +269,13 @@ public: return mActiveShader; } - FShader *Get(unsigned int eff) + FShader *Get(unsigned int eff, bool alphateston) { // indices 0-2 match the warping modes, 3 is brightmap, 4 no texture, the following are custom + if (!alphateston && eff <= 3) + { + return mTextureEffectsNAT[eff]; // Non-alphatest shaders are only created for default, warp1+2 and brightmap. The rest won't get used anyway + } if (eff < mTextureEffects.Size()) { return mTextureEffects[eff];