Skip to content

Commit

Permalink
- mirror clip planes moved - not working yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Jun 22, 2018
1 parent e7531bb commit 80a9028
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 49 deletions.
21 changes: 0 additions & 21 deletions src/gl/renderer/gl_renderstate.cpp
Expand Up @@ -80,8 +80,6 @@ void FRenderState::Reset()
mLightParms[0] = mLightParms[1] = mLightParms[2] = 0.0f;
mLightParms[3] = -1.f;
mSpecialEffect = EFF_NONE;
mClipHeight = 0.f;
mClipHeightDirection = 0.f;
mGlossiness = 0.0f;
mSpecularLevel = 0.0f;
mShaderTimer = 0.0f;
Expand Down Expand Up @@ -165,8 +163,6 @@ bool FRenderState::ApplyShader()
activeShader->muObjectColor2.Set(mObjectColor2);
activeShader->muDynLightColor.Set(mDynColor.vec);
activeShader->muInterpolationFactor.Set(mInterpolationFactor);
activeShader->muClipHeight.Set(mClipHeight);
activeShader->muClipHeightDirection.Set(mClipHeightDirection);
activeShader->muTimer.Set((double)(screen->FrameTime - firstFrame) * (double)mShaderTimer / 1000.);
activeShader->muAlphaThreshold.Set(mAlphaThreshold);
activeShader->muLightIndex.Set(-1);
Expand Down Expand Up @@ -304,20 +300,3 @@ void FRenderState::ApplyLightIndex(int index)
}
activeShader->muLightIndex.Set(index);
}

void FRenderState::SetClipHeight(float height, float direction)
{
mClipHeight = height;
mClipHeightDirection = direction;

if (gl.flags & RFL_NO_CLIP_PLANES) return;

if (direction != 0.f)
{
glEnable(GL_CLIP_DISTANCE0);
}
else
{
glDisable(GL_CLIP_DISTANCE0); // GL_CLIP_PLANE0 is the same value so no need to make a distinction
}
}
2 changes: 0 additions & 2 deletions src/gl/renderer/gl_renderstate.h
Expand Up @@ -196,8 +196,6 @@ class FRenderState
return mClipLineShouldBeActive;
}

void SetClipHeight(float height, float direction);

void SetNormal(FVector3 norm)
{
mNormal.Set(norm.X, norm.Y, norm.Z, 0.f);
Expand Down
18 changes: 1 addition & 17 deletions src/gl/scene/gl_portal.cpp
Expand Up @@ -745,29 +745,13 @@ void GLPlaneMirrorPortal::DrawContents(FDrawInfo *di)

di->UpdateCurrentMapSection();

gl_RenderState.SetClipHeight(planez, PlaneMirrorMode < 0 ? -1.f : 1.f);
di->SetClipHeight(planez, PlaneMirrorMode < 0 ? -1.f : 1.f);
di->DrawScene(DM_PORTAL);
gl_RenderState.SetClipHeight(0.f, 0.f);
PlaneMirrorFlag--;
PlaneMirrorMode = old_pm;
std::swap(screen->instack[sector_t::floor], screen->instack[sector_t::ceiling]);
}

void GLPlaneMirrorPortal::PushState()
{
planestack.Push(gl_RenderState.GetClipHeight());
planestack.Push(gl_RenderState.GetClipHeightDirection());
gl_RenderState.SetClipHeight(0.f, 0.f);
}

void GLPlaneMirrorPortal::PopState()
{
float d, f;
planestack.Pop(d);
planestack.Pop(f);
gl_RenderState.SetClipHeight(f, d);
}

//-----------------------------------------------------------------------------
//
// Common code for line to line and mirror portals
Expand Down
2 changes: 0 additions & 2 deletions src/gl/scene/gl_portal.h
Expand Up @@ -302,8 +302,6 @@ struct GLPlaneMirrorPortal : public GLPortal
virtual void DrawContents(FDrawInfo *di);
virtual void * GetSource() const { return origin; }
virtual const char *GetName();
virtual void PushState();
virtual void PopState();
secplane_t * origin;

public:
Expand Down
12 changes: 12 additions & 0 deletions src/gl/scene/gl_scene.cpp
Expand Up @@ -76,6 +76,18 @@ void FDrawInfo::ApplyVPUniforms()
{
VPUniforms.CalcDependencies();
GLRenderer->mShaderManager->ApplyMatrices(&VPUniforms, NORMAL_PASS);

if (!(gl.flags & RFL_NO_CLIP_PLANES))
{
if (VPUniforms.mClipHeightDirection != 0.f)
{
glEnable(GL_CLIP_DISTANCE0);
}
else
{
glDisable(GL_CLIP_DISTANCE0);
}
}
}

//-----------------------------------------------------------------------------
Expand Down
6 changes: 4 additions & 2 deletions src/gl/shaders/gl_shader.cpp
Expand Up @@ -324,8 +324,6 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
muSplitTopPlane.Init(hShader, "uSplitTopPlane");
muClipLine.Init(hShader, "uClipLine");
muInterpolationFactor.Init(hShader, "uInterpolationFactor");
muClipHeight.Init(hShader, "uClipHeight");
muClipHeightDirection.Init(hShader, "uClipHeightDirection");
muAlphaThreshold.Init(hShader, "uAlphaThreshold");
muSpecularMaterial.Init(hShader, "uSpecularMaterial");
muTimer.Init(hShader, "timer");
Expand All @@ -345,6 +343,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
camerapos_index = glGetUniformLocation(hShader, "uCameraPos");
pallightlevels_index = glGetUniformLocation(hShader, "uPalLightLevels");
globvis_index = glGetUniformLocation(hShader, "uGlobVis");
clipheight_index = glGetUniformLocation(hShader, "uClipHeight");
clipheightdirection_index = glGetUniformLocation(hShader, "uClipHeightDirection");

if (!(gl.flags & RFL_SHADER_STORAGE_BUFFER))
{
Expand Down Expand Up @@ -446,6 +446,8 @@ void FShader::ApplyMatrices(HWViewpointUniforms *u)
glUniform1i(viewheight_index, u->mViewHeight);
glUniform1i(pallightlevels_index, u->mPalLightLevels);
glUniform1f(globvis_index, u->mGlobVis);
glUniform1f(clipheight_index, u->mClipHeight);
glUniform1f(clipheightdirection_index, u->mClipHeightDirection);
}

//==========================================================================
Expand Down
4 changes: 2 additions & 2 deletions src/gl/shaders/gl_shader.h
Expand Up @@ -259,8 +259,6 @@ class FShader
FUniform4f muSplitTopPlane;
FUniform4f muClipLine;
FBufferedUniform1f muInterpolationFactor;
FBufferedUniform1f muClipHeight;
FBufferedUniform1f muClipHeightDirection;
FBufferedUniform1f muAlphaThreshold;
FBufferedUniform2f muSpecularMaterial;
FBufferedUniform1f muTimer;
Expand All @@ -277,6 +275,8 @@ class FShader
int camerapos_index;
int pallightlevels_index;
int globvis_index;
int clipheight_index;
int clipheightdirection_index;

public:
int vertexmatrix_index;
Expand Down
6 changes: 6 additions & 0 deletions src/hwrenderer/scene/hw_drawinfo.h
Expand Up @@ -158,6 +158,12 @@ struct HWDrawInfo
VPUniforms.mCameraPos = { (float)pos.X, (float)pos.Z, (float)pos.Y, 0.f };
}

void SetClipHeight(float h, float d)
{
VPUniforms.mClipHeight = h;
VPUniforms.mClipHeightDirection = d;
}

void RenderBSPNode(void *node);

void ClearBuffers();
Expand Down
8 changes: 5 additions & 3 deletions src/hwrenderer/scene/hw_viewpointuniforms.h
Expand Up @@ -11,9 +11,11 @@ struct HWViewpointUniforms
FVector4 mCameraPos;
FVector4 mClipLine;

float mGlobVis;
int mPalLightLevels;
int mViewHeight;
float mGlobVis = 1.f;
int mPalLightLevels = 0;
int mViewHeight = 0;
float mClipHeight = 0.f;
float mClipHeightDirection = 0.f;

void CalcDependencies()
{
Expand Down

0 comments on commit 80a9028

Please sign in to comment.