diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index 15aa56da9..d7f46e07e 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -69,7 +69,7 @@ TArray gl_MatrixStack; void FRenderState::Reset() { mTextureEnabled = true; - mBrightmapEnabled = mFogEnabled = mGlowEnabled = false; + mSplitEnabled = mBrightmapEnabled = mFogEnabled = mGlowEnabled = false; mColorMask[0] = mColorMask[1] = mColorMask[2] = mColorMask[3] = true; currentColorMask[0] = currentColorMask[1] = currentColorMask[2] = currentColorMask[3] = true; mFogColor.d = -1; @@ -104,6 +104,7 @@ void FRenderState::Reset() bool FRenderState::ApplyShader() { + static const float nulvec[] = { 0.f, 0.f, 0.f, 0.f }; if (mSpecialEffect > EFF_NONE) { activeShader = GLRenderer->mShaderManager->BindEffect(mSpecialEffect); @@ -157,7 +158,6 @@ bool FRenderState::ApplyShader() else if (activeShader->currentglowstate) { // if glowing is on, disable it. - static const float nulvec[] = { 0.f, 0.f, 0.f, 0.f }; activeShader->muGlowTopColor.Set(nulvec); activeShader->muGlowBottomColor.Set(nulvec); activeShader->muGlowTopPlane.Set(nulvec); @@ -165,6 +165,18 @@ bool FRenderState::ApplyShader() activeShader->currentglowstate = 0; } + if (mSplitEnabled) + { + activeShader->muSplitTopPlane.Set(mSplitTopPlane.vec); + activeShader->muSplitBottomPlane.Set(mSplitBottomPlane.vec); + activeShader->currentsplitstate = 1; + } + else + { + activeShader->muSplitTopPlane.Set(nulvec); + activeShader->muSplitBottomPlane.Set(nulvec); + } + if (mColormapState != activeShader->currentfixedcolormap) { float r, g, b; diff --git a/src/gl/renderer/gl_renderstate.h b/src/gl/renderer/gl_renderstate.h index aa24072c2..d46bb4996 100644 --- a/src/gl/renderer/gl_renderstate.h +++ b/src/gl/renderer/gl_renderstate.h @@ -46,6 +46,7 @@ class FRenderState bool mTextureEnabled; bool mFogEnabled; bool mGlowEnabled; + bool mSplitEnabled; bool mBrightmapEnabled; bool mColorMask[4]; bool currentColorMask[4]; @@ -72,6 +73,7 @@ class FRenderState FStateVec4 mCameraPos; FStateVec4 mGlowTop, mGlowBottom; FStateVec4 mGlowTopPlane, mGlowBottomPlane; + FStateVec4 mSplitTopPlane, mSplitBottomPlane; PalEntry mFogColor; PalEntry mObjectColor; FStateVec4 mDynColor; @@ -229,6 +231,11 @@ public: mGlowEnabled = on; } + void EnableSplit(bool on) + { + mSplitEnabled = on; + } + void SetLightIndex(int n) { mLightIndex = n; @@ -272,6 +279,12 @@ public: mGlowBottomPlane.Set(FIXED2FLOAT(bottom.a), FIXED2FLOAT(bottom.b), FIXED2FLOAT(bottom.ic), FIXED2FLOAT(bottom.d)); } + void SetSplitPlanes(const secplane_t &top, const secplane_t &bottom) + { + mSplitTopPlane.Set(FIXED2FLOAT(top.a), FIXED2FLOAT(top.b), FIXED2FLOAT(top.ic), FIXED2FLOAT(top.d)); + mSplitBottomPlane.Set(FIXED2FLOAT(bottom.a), FIXED2FLOAT(bottom.b), FIXED2FLOAT(bottom.ic), FIXED2FLOAT(bottom.d)); + } + void SetDynLight(float r, float g, float b) { mDynColor.Set(r, g, b, 0); diff --git a/src/gl/scene/gl_wall.h b/src/gl/scene/gl_wall.h index 5b27d9435..6dc694585 100644 --- a/src/gl/scene/gl_wall.h +++ b/src/gl/scene/gl_wall.h @@ -150,6 +150,8 @@ public: FTextureID topflat,bottomflat; secplane_t topplane, bottomplane; // we need to save these to pass them to the shader for calculating glows. + secplane_t *toplight, *bottomlight; // These refer to the planes within the lightlist_t entries. + // these are not the same as ytop and ybottom!!! float zceil[2]; float zfloor[2]; diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index 2955cf7c8..aa8dfac2b 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -216,6 +216,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * muGlowTopColor.Init(hShader, "uGlowTopColor"); muGlowBottomPlane.Init(hShader, "uGlowBottomPlane"); muGlowTopPlane.Init(hShader, "uGlowTopPlane"); + muSplitBottomPlane.Init(hShader, "uSplitBottomPlane"); + muSplitTopPlane.Init(hShader, "uSplitTopPlane"); muFixedColormap.Init(hShader, "uFixedColormap"); muInterpolationFactor.Init(hShader, "uInterpolationFactor"); muClipHeightTop.Init(hShader, "uClipHeightTop"); diff --git a/src/gl/shaders/gl_shader.h b/src/gl/shaders/gl_shader.h index c5baceceb..cf6480d9b 100644 --- a/src/gl/shaders/gl_shader.h +++ b/src/gl/shaders/gl_shader.h @@ -218,6 +218,8 @@ class FShader FUniform4f muGlowTopColor; FUniform4f muGlowBottomPlane; FUniform4f muGlowTopPlane; + FUniform4f muSplitBottomPlane; + FUniform4f muSplitTopPlane; FBufferedUniform1f muInterpolationFactor; FBufferedUniform1f muClipHeightTop; FBufferedUniform1f muClipHeightBottom; @@ -233,6 +235,7 @@ public: int fakevb_index; private: int currentglowstate; + int currentsplitstate; int currentfixedcolormap; bool currentTextureMatrixState; bool currentModelMatrixState; @@ -243,6 +246,7 @@ public: { hShader = hVertProg = hFragProg = 0; currentglowstate = 0; + currentsplitstate = 0; currentfixedcolormap = 0; currentTextureMatrixState = true; // by setting the matrix state to 'true' it is guaranteed to be set the first time the render state gets applied. currentModelMatrixState = true; diff --git a/src/gl/system/gl_interface.cpp b/src/gl/system/gl_interface.cpp index 2e7d0f1e0..3fd718ff7 100644 --- a/src/gl/system/gl_interface.cpp +++ b/src/gl/system/gl_interface.cpp @@ -174,7 +174,7 @@ void gl_LoadExtensions() void gl_PrintStartupLog() { int v = 0; - glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &v); + if (gl.version >= 3.2) glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &v); Printf ("GL_VENDOR: %s\n", glGetString(GL_VENDOR)); Printf ("GL_RENDERER: %s\n", glGetString(GL_RENDERER)); diff --git a/wadsrc/static/shaders/glsl/main.vp b/wadsrc/static/shaders/glsl/main.vp index 827644eea..1c6aebe47 100644 --- a/wadsrc/static/shaders/glsl/main.vp +++ b/wadsrc/static/shaders/glsl/main.vp @@ -29,6 +29,12 @@ void main() glowdist.x = -((uGlowTopPlane.w + uGlowTopPlane.x * worldcoord.x + uGlowTopPlane.y * worldcoord.z) * uGlowTopPlane.z) - worldcoord.y; glowdist.y = worldcoord.y + ((uGlowBottomPlane.w + uGlowBottomPlane.x * worldcoord.x + uGlowBottomPlane.y * worldcoord.z) * uGlowBottomPlane.z); + + if (uSplitBottomPlane.z != 0) + { + gl_ClipDistance[3] = -((uSplitTopPlane.w + uSplitTopPlane.x * worldcoord.x + uSplitTopPlane.y * worldcoord.z) * uSplitTopPlane.z) - worldcoord.y; + gl_ClipDistance[4] = worldcoord.y + ((uSplitBottomPlane.w + uSplitBottomPlane.x * worldcoord.x + uSplitBottomPlane.y * worldcoord.z) * uSplitBottomPlane.z); + } #endif #ifdef SPHEREMAP @@ -56,4 +62,5 @@ void main() gl_ClipDistance[1] = worldcoord.y - uClipSplit.x; gl_ClipDistance[2] = uClipSplit.y - worldcoord.y; + }