- cleaned up the clip plane management for portals.

Unfortunately the math behind the old clip planes is utterly impenetrable and so poorly documented that I have no idea how to set that up, so it is deactivated for now. It wasn't working anyway.
This commit is contained in:
Christoph Oelckers 2016-04-27 00:41:00 +02:00
parent 066d5c63e2
commit 09f54b0940
9 changed files with 55 additions and 59 deletions

View file

@ -10,6 +10,7 @@ This is a simplified version of VSMatrix that has been adjusted for GZDoom's nee
----------------------------------------------------*/ ----------------------------------------------------*/
#include <algorithm>
#include "gl/system/gl_system.h" #include "gl/system/gl_system.h"
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
@ -139,14 +140,9 @@ VSMatrix::translate(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z)
void void
VSMatrix::scale(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z) VSMatrix::scale(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z)
{ {
FLOATTYPE mat[16]; mMatrix[0] *= x; mMatrix[1] *= x; mMatrix[2] *= x; mMatrix[3] *= x;
mMatrix[4] *= y; mMatrix[5] *= y; mMatrix[6] *= y; mMatrix[7] *= y;
setIdentityMatrix(mat,4); mMatrix[8] *= z; mMatrix[9] *= z; mMatrix[10] *= z; mMatrix[11] *= z;
mat[0] = x;
mat[5] = y;
mat[10] = z;
multMatrix(mat);
} }

View file

@ -48,6 +48,7 @@ class VSMatrix {
#ifdef USE_DOUBLE #ifdef USE_DOUBLE
void multMatrix(const float *aMatrix); void multMatrix(const float *aMatrix);
#endif #endif
void multVector(FLOATTYPE *aVector);
void multMatrix(const FLOATTYPE *aMatrix); void multMatrix(const FLOATTYPE *aMatrix);
void multMatrix(const VSMatrix &aMatrix) void multMatrix(const VSMatrix &aMatrix)
{ {
@ -92,7 +93,9 @@ class VSMatrix {
{ {
computeNormalMatrix(aMatrix.mMatrix); computeNormalMatrix(aMatrix.mMatrix);
} }
bool inverseMatrix(VSMatrix &result);
void transpose();
protected: protected:
static void crossProduct(const FLOATTYPE *a, const FLOATTYPE *b, FLOATTYPE *res); static void crossProduct(const FLOATTYPE *a, const FLOATTYPE *b, FLOATTYPE *res);
static FLOATTYPE dotProduct(const FLOATTYPE *a, const FLOATTYPE * b); static FLOATTYPE dotProduct(const FLOATTYPE *a, const FLOATTYPE * b);

View file

@ -86,8 +86,8 @@ void FRenderState::Reset()
mColormapState = CM_DEFAULT; mColormapState = CM_DEFAULT;
mLightParms[3] = -1.f; mLightParms[3] = -1.f;
mSpecialEffect = EFF_NONE; mSpecialEffect = EFF_NONE;
mClipHeightTop = 65536.f; mClipHeight = 0.f;
mClipHeightBottom = -65536.f; mClipHeightDirection = 0.f;
ClearClipSplit(); ClearClipSplit();
stSrcBlend = stDstBlend = -1; stSrcBlend = stDstBlend = -1;
@ -140,8 +140,8 @@ bool FRenderState::ApplyShader()
activeShader->muObjectColor.Set(mObjectColor); activeShader->muObjectColor.Set(mObjectColor);
activeShader->muDynLightColor.Set(mDynColor.vec); activeShader->muDynLightColor.Set(mDynColor.vec);
activeShader->muInterpolationFactor.Set(mInterpolationFactor); activeShader->muInterpolationFactor.Set(mInterpolationFactor);
activeShader->muClipHeightTop.Set(mClipHeightTop); activeShader->muClipHeight.Set(mClipHeight);
activeShader->muClipHeightBottom.Set(mClipHeightBottom); activeShader->muClipHeightDirection.Set(mClipHeightDirection);
activeShader->muTimer.Set(gl_frameMS * mShaderTimer / 1000.f); activeShader->muTimer.Set(gl_frameMS * mShaderTimer / 1000.f);
activeShader->muAlphaThreshold.Set(mAlphaThreshold); activeShader->muAlphaThreshold.Set(mAlphaThreshold);
activeShader->muLightIndex.Set(mLightIndex); // will always be -1 for now activeShader->muLightIndex.Set(mLightIndex); // will always be -1 for now
@ -324,4 +324,27 @@ void FRenderState::ApplyLightIndex(int index)
} }
activeShader->muLightIndex.Set(index); activeShader->muLightIndex.Set(index);
} }
} }
void FRenderState::SetClipHeight(float height, float direction)
{
mClipHeight = height;
mClipHeightDirection = direction;
if (direction != 0.f)
{
if (gl.glslversion >= 1.3f) glEnable(GL_CLIP_DISTANCE0);
else
{
// This does not work. Need someone who understands how glClipPlane works...
//glEnable(GL_CLIP_PLANE0);
// Plane mirrors never are slopes.
//double d[4] = { 0, direction, 0, -direction * height };
//glClipPlane(GL_CLIP_PLANE0, d);
}
}
else
{
if (gl.glslversion >= 1.3f) glDisable(GL_CLIP_DISTANCE0);
//else glDisable(GL_CLIP_PLANE0);
}
}

View file

@ -63,7 +63,7 @@ class FRenderState
bool mModelMatrixEnabled; bool mModelMatrixEnabled;
bool mTextureMatrixEnabled; bool mTextureMatrixEnabled;
float mInterpolationFactor; float mInterpolationFactor;
float mClipHeightTop, mClipHeightBottom; float mClipHeight, mClipHeightDirection;
float mShaderTimer; float mShaderTimer;
bool mLastDepthClamp; bool mLastDepthClamp;
@ -135,25 +135,17 @@ public:
mCurrentVertexBuffer = NULL; mCurrentVertexBuffer = NULL;
} }
void SetClipHeightTop(float clip) float GetClipHeight()
{ {
mClipHeightTop = clip; return mClipHeight;
} }
float GetClipHeightTop() float GetClipHeightDirection()
{ {
return mClipHeightTop; return mClipHeightDirection;
} }
void SetClipHeightBottom(float clip) void SetClipHeight(float height, float direction);
{
mClipHeightBottom = clip;
}
float GetClipHeightBottom()
{
return mClipHeightBottom;
}
void SetColor(float r, float g, float b, float a = 1.f, int desat = 0) void SetColor(float r, float g, float b, float a = 1.f, int desat = 0)
{ {

View file

@ -438,7 +438,7 @@ void GLFlat::Draw(int pass, bool trans) // trans only has meaning for GLPASS_LIG
{ {
gl_RenderState.SetMaterial(gltexture, CLAMP_NONE, 0, -1, false); gl_RenderState.SetMaterial(gltexture, CLAMP_NONE, 0, -1, false);
gl_SetPlaneTextureRotation(&plane, gltexture); gl_SetPlaneTextureRotation(&plane, gltexture);
DrawSubsectors(pass, true, true); DrawSubsectors(pass, gl.lightmethod != LM_SOFTWARE, true);
gl_RenderState.EnableTextureMatrix(false); gl_RenderState.EnableTextureMatrix(false);
} }
if (renderstyle==STYLE_Add) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (renderstyle==STYLE_Add) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

View file

@ -300,11 +300,9 @@ bool GLPortal::Start(bool usestencil, bool doquery)
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
} }
} }
planestack.Push(gl_RenderState.GetClipHeightTop()); planestack.Push(gl_RenderState.GetClipHeight());
planestack.Push(gl_RenderState.GetClipHeightBottom()); planestack.Push(gl_RenderState.GetClipHeightDirection());
glDisable(GL_CLIP_DISTANCE0); gl_RenderState.SetClipHeight(0., 0.);
gl_RenderState.SetClipHeightBottom(-65536.f);
gl_RenderState.SetClipHeightTop(65536.f);
// save viewpoint // save viewpoint
savedViewPos = ViewPos; savedViewPos = ViewPos;
@ -363,13 +361,10 @@ void GLPortal::End(bool usestencil)
PortalAll.Clock(); PortalAll.Clock();
GLRenderer->mCurrentPortal = NextPortal; GLRenderer->mCurrentPortal = NextPortal;
float f; float f, d;
planestack.Pop(d);
planestack.Pop(f); planestack.Pop(f);
gl_RenderState.SetClipHeightBottom(f); gl_RenderState.SetClipHeight(f, d);
if (f > -65535.f) glEnable(GL_CLIP_DISTANCE0);
planestack.Pop(f);
gl_RenderState.SetClipHeightTop(f);
if (f < 65535.f) glEnable(GL_CLIP_DISTANCE0);
if (usestencil) if (usestencil)
{ {
@ -804,22 +799,9 @@ void GLPlaneMirrorPortal::DrawContents()
GLRenderer->SetupView(ViewPos.X, ViewPos.Y, ViewPos.Z, ViewAngle, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); GLRenderer->SetupView(ViewPos.X, ViewPos.Y, ViewPos.Z, ViewAngle, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1));
ClearClipper(); ClearClipper();
if (PlaneMirrorMode < 0) gl_RenderState.SetClipHeight(planez, PlaneMirrorMode < 0? -1.f : 1.f);
{
gl_RenderState.SetClipHeightTop(planez); // ceiling mirror: clip everything with a z lower than the portal's ceiling
gl_RenderState.SetClipHeightBottom(-65536.f);
}
else
{
gl_RenderState.SetClipHeightBottom(planez); // floor mirror: clip everything with a z higher than the portal's floor
gl_RenderState.SetClipHeightTop(65536.f);
}
glEnable(GL_CLIP_DISTANCE0);
GLRenderer->DrawScene(); GLRenderer->DrawScene();
glDisable(GL_CLIP_DISTANCE0); gl_RenderState.SetClipHeight(0.f, 0.f);
gl_RenderState.SetClipHeightBottom(-65536.f);
gl_RenderState.SetClipHeightTop(65536.f);
PlaneMirrorFlag--; PlaneMirrorFlag--;
PlaneMirrorMode=old_pm; PlaneMirrorMode=old_pm;
} }

View file

@ -280,8 +280,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
muSplitTopPlane.Init(hShader, "uSplitTopPlane"); muSplitTopPlane.Init(hShader, "uSplitTopPlane");
muFixedColormap.Init(hShader, "uFixedColormap"); muFixedColormap.Init(hShader, "uFixedColormap");
muInterpolationFactor.Init(hShader, "uInterpolationFactor"); muInterpolationFactor.Init(hShader, "uInterpolationFactor");
muClipHeightTop.Init(hShader, "uClipHeightTop"); muClipHeight.Init(hShader, "uClipHeight");
muClipHeightBottom.Init(hShader, "uClipHeightBottom"); muClipHeightDirection.Init(hShader, "uClipHeightDirection");
muAlphaThreshold.Init(hShader, "uAlphaThreshold"); muAlphaThreshold.Init(hShader, "uAlphaThreshold");
muTimer.Init(hShader, "timer"); muTimer.Init(hShader, "timer");

View file

@ -221,8 +221,8 @@ class FShader
FUniform4f muSplitBottomPlane; FUniform4f muSplitBottomPlane;
FUniform4f muSplitTopPlane; FUniform4f muSplitTopPlane;
FBufferedUniform1f muInterpolationFactor; FBufferedUniform1f muInterpolationFactor;
FBufferedUniform1f muClipHeightTop; FBufferedUniform1f muClipHeight;
FBufferedUniform1f muClipHeightBottom; FBufferedUniform1f muClipHeightDirection;
FBufferedUniform1f muAlphaThreshold; FBufferedUniform1f muAlphaThreshold;
FBufferedUniform1f muTimer; FBufferedUniform1f muTimer;

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB