Skip to content

Commit

Permalink
Fixed|Renderer: Z-buffering of sky models
Browse files Browse the repository at this point in the history
3D models won't look right without Z buffering, however they must not
interfere with world geometry. This commit enables Z buffering for
sky models and clears the depth buffer afterwards.

Excessive clears of the depth buffer could be avoided by using a
separate depth buffer for the sky, however the sky stencil should be
drawn there as well. This could be a topic for a future refactoring.

IssueID #1922
  • Loading branch information
skyjake committed Dec 20, 2014
1 parent 0322974 commit f25548d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
3 changes: 2 additions & 1 deletion doomsday/client/src/render/r_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ void Rend_Draw3DPlayerSprites()
Rend_ModelViewMatrix(false /* don't apply view angle rotation */);

static GLTexture localDepth; // note: static!
GLTarget::AlternativeBuffer altDepth(GLState::current().target(), localDepth, GLTarget::DepthStencil);
GLTarget::AlternativeBuffer altDepth(GLState::current().target(), localDepth,
GLTarget::DepthStencil);

for(int i = 0; i < DDMAXPSPRITES; ++i)
{
Expand Down
9 changes: 5 additions & 4 deletions doomsday/client/src/render/rend_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3504,8 +3504,11 @@ static void drawSky()
}

// We do not want to update color and/or depth.
glDisable(GL_DEPTH_TEST);
GLState::push().setColorMask(gl::WriteNone).apply();
GLState::push()
.setDepthTest(false)
.setDepthWrite(false)
.setColorMask(gl::WriteNone)
.apply();

// Mask out stencil buffer, setting the drawn areas to 1.
glEnable(GL_STENCIL_TEST);
Expand All @@ -3524,7 +3527,6 @@ static void drawSky()

// Restore previous GL state.
GLState::pop().apply();
glEnable(GL_DEPTH_TEST);
glDisable(GL_STENCIL_TEST);

// Now, only render where the stencil is set to 1.
Expand All @@ -3541,7 +3543,6 @@ static void drawSky()

// Return GL state to normal.
glDisable(GL_STENCIL_TEST);
glEnable(GL_DEPTH_TEST);
}

static bool generateHaloForVisSprite(vissprite_t const *spr, bool primary = false)
Expand Down
20 changes: 8 additions & 12 deletions doomsday/client/src/render/skydrawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,10 @@ DENG2_PIMPL(SkyDrawable)
{
if(!haveModels) return;

// We don't want anything written in the depth buffer.
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
// Sky models use depth testing, but they won't interfere with world geometry.
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glClear(GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
Expand Down Expand Up @@ -505,15 +506,12 @@ DENG2_PIMPL(SkyDrawable)
Rend_DrawModel(vis);
}

// We don't want that anything interferes with what was drawn.
//glClear(GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glPopMatrix();

// Restore assumed default GL state.
glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
// We don't want that anything in the world geometry interferes with what was
// drawn in the sky.
glClear(GL_DEPTH_BUFFER_BIT);
}

void setupModels(Record const *def)
Expand Down Expand Up @@ -694,13 +692,11 @@ MaterialVariantSpec const &SkyDrawable::layerMaterialSpec(bool masked) // static
0, -1, -1, false, true, false, false);
}

namespace {
void markSphereForRebuild()
static void markSphereForRebuild()
{
// Defer this task until draw time, when we can be sure we are in the correct thread.
hemisphere.needRebuild = true;
}
}

void SkyDrawable::consoleRegister() // static
{
Expand Down

0 comments on commit f25548d

Please sign in to comment.