- 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 <math.h>
#include <stdlib.h>
@ -139,14 +140,9 @@ VSMatrix::translate(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z)
void
VSMatrix::scale(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z)
{
FLOATTYPE mat[16];
setIdentityMatrix(mat,4);
mat[0] = x;
mat[5] = y;
mat[10] = z;
multMatrix(mat);
mMatrix[0] *= x; mMatrix[1] *= x; mMatrix[2] *= x; mMatrix[3] *= x;
mMatrix[4] *= y; mMatrix[5] *= y; mMatrix[6] *= y; mMatrix[7] *= y;
mMatrix[8] *= z; mMatrix[9] *= z; mMatrix[10] *= z; mMatrix[11] *= z;
}

View file

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

View file

@ -86,8 +86,8 @@ void FRenderState::Reset()
mColormapState = CM_DEFAULT;
mLightParms[3] = -1.f;
mSpecialEffect = EFF_NONE;
mClipHeightTop = 65536.f;
mClipHeightBottom = -65536.f;
mClipHeight = 0.f;
mClipHeightDirection = 0.f;
ClearClipSplit();
stSrcBlend = stDstBlend = -1;
@ -140,8 +140,8 @@ bool FRenderState::ApplyShader()
activeShader->muObjectColor.Set(mObjectColor);
activeShader->muDynLightColor.Set(mDynColor.vec);
activeShader->muInterpolationFactor.Set(mInterpolationFactor);
activeShader->muClipHeightTop.Set(mClipHeightTop);
activeShader->muClipHeightBottom.Set(mClipHeightBottom);
activeShader->muClipHeight.Set(mClipHeight);
activeShader->muClipHeightDirection.Set(mClipHeightDirection);
activeShader->muTimer.Set(gl_frameMS * mShaderTimer / 1000.f);
activeShader->muAlphaThreshold.Set(mAlphaThreshold);
activeShader->muLightIndex.Set(mLightIndex); // will always be -1 for now
@ -324,4 +324,27 @@ void FRenderState::ApplyLightIndex(int 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 mTextureMatrixEnabled;
float mInterpolationFactor;
float mClipHeightTop, mClipHeightBottom;
float mClipHeight, mClipHeightDirection;
float mShaderTimer;
bool mLastDepthClamp;
@ -135,25 +135,17 @@ public:
mCurrentVertexBuffer = NULL;
}
void SetClipHeightTop(float clip)
float GetClipHeight()
{
mClipHeightTop = clip;
return mClipHeight;
}
float GetClipHeightTop()
float GetClipHeightDirection()
{
return mClipHeightTop;
return mClipHeightDirection;
}
void SetClipHeightBottom(float clip)
{
mClipHeightBottom = clip;
}
float GetClipHeightBottom()
{
return mClipHeightBottom;
}
void SetClipHeight(float height, float direction);
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_SetPlaneTextureRotation(&plane, gltexture);
DrawSubsectors(pass, true, true);
DrawSubsectors(pass, gl.lightmethod != LM_SOFTWARE, true);
gl_RenderState.EnableTextureMatrix(false);
}
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);
}
}
planestack.Push(gl_RenderState.GetClipHeightTop());
planestack.Push(gl_RenderState.GetClipHeightBottom());
glDisable(GL_CLIP_DISTANCE0);
gl_RenderState.SetClipHeightBottom(-65536.f);
gl_RenderState.SetClipHeightTop(65536.f);
planestack.Push(gl_RenderState.GetClipHeight());
planestack.Push(gl_RenderState.GetClipHeightDirection());
gl_RenderState.SetClipHeight(0., 0.);
// save viewpoint
savedViewPos = ViewPos;
@ -363,13 +361,10 @@ void GLPortal::End(bool usestencil)
PortalAll.Clock();
GLRenderer->mCurrentPortal = NextPortal;
float f;
float f, d;
planestack.Pop(d);
planestack.Pop(f);
gl_RenderState.SetClipHeightBottom(f);
if (f > -65535.f) glEnable(GL_CLIP_DISTANCE0);
planestack.Pop(f);
gl_RenderState.SetClipHeightTop(f);
if (f < 65535.f) glEnable(GL_CLIP_DISTANCE0);
gl_RenderState.SetClipHeight(f, d);
if (usestencil)
{
@ -804,22 +799,9 @@ void GLPlaneMirrorPortal::DrawContents()
GLRenderer->SetupView(ViewPos.X, ViewPos.Y, ViewPos.Z, ViewAngle, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1));
ClearClipper();
if (PlaneMirrorMode < 0)
{
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);
gl_RenderState.SetClipHeight(planez, PlaneMirrorMode < 0? -1.f : 1.f);
GLRenderer->DrawScene();
glDisable(GL_CLIP_DISTANCE0);
gl_RenderState.SetClipHeightBottom(-65536.f);
gl_RenderState.SetClipHeightTop(65536.f);
gl_RenderState.SetClipHeight(0.f, 0.f);
PlaneMirrorFlag--;
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");
muFixedColormap.Init(hShader, "uFixedColormap");
muInterpolationFactor.Init(hShader, "uInterpolationFactor");
muClipHeightTop.Init(hShader, "uClipHeightTop");
muClipHeightBottom.Init(hShader, "uClipHeightBottom");
muClipHeight.Init(hShader, "uClipHeight");
muClipHeightDirection.Init(hShader, "uClipHeightDirection");
muAlphaThreshold.Init(hShader, "uAlphaThreshold");
muTimer.Init(hShader, "timer");

View file

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB