forked from mirrors/0ad
Fix culling for shadows and reflections.
Previously we had a single culling frustum based on the main camera, and any object outside the frustum would never get rendered, even if it should actually contribute to shadows or reflections/refractions. This caused ugly pop-in effects in the shadows and reflections while scrolling. Extend the renderer to support multiple cull groups, each with a separate frustum and with separate lists of submitted objects, so that shadows and reflections will render the correctly culled sets of objects. Update the shadow map generation to compute the (hopefully) correct bounds and matrices for this new scheme. Include terrain patches in the shadow bounds, so hills can cast shadows correctly. Remove the code that tried to render objects slightly outside the camera frustum in order to reduce the pop-in effect, since that was a workaround for the lack of a proper fix. Remove the model/patch filtering code, which was used to cull objects that were in the normal camera frustum but should be excluded from reflections/refractions, since that's redundant now too. Inline DistanceToPlane to save a few hundred usecs per frame inside CCmpUnitRenderer::RenderSubmit. Fixes #504, #579. This was SVN commit r15445.
This commit is contained in:
@@ -477,15 +477,6 @@ void CGameView::BeginFrame()
|
||||
{
|
||||
// Set up cull camera
|
||||
m->CullCamera = m->ViewCamera;
|
||||
|
||||
// One way to fix shadows popping in at the edge of the screen is to widen the culling frustum so that
|
||||
// objects aren't culled as early. The downside is that objects will get rendered even though they appear
|
||||
// off screen, which is somewhat inefficient. A better solution would be to decouple shadow map rendering
|
||||
// from model rendering; as it is now, a shadow map is only rendered if its associated model is to be
|
||||
// rendered.
|
||||
// (See http://trac.wildfiregames.com/ticket/504)
|
||||
m->CullCamera.SetProjection(m->ViewNear, m->ViewFar, GetCullFOV());
|
||||
m->CullCamera.UpdateFrustum();
|
||||
}
|
||||
g_Renderer.SetSceneCamera(m->ViewCamera, m->CullCamera);
|
||||
|
||||
@@ -523,51 +514,7 @@ void CGameView::EnumerateObjects(const CFrustum& frustum, SceneCollector* c)
|
||||
}
|
||||
|
||||
if (!m->Culling || frustum.IsBoxVisible (CVector3D(0,0,0), bounds)) {
|
||||
//c->Submit(patch);
|
||||
|
||||
// set the renderstate for this patch
|
||||
patch->setDrawState(true);
|
||||
|
||||
// set the renderstate for the neighbors
|
||||
CPatch *nPatch;
|
||||
|
||||
nPatch = pTerrain->GetPatch(i-1,j-1);
|
||||
if(nPatch) nPatch->setDrawState(true);
|
||||
|
||||
nPatch = pTerrain->GetPatch(i,j-1);
|
||||
if(nPatch) nPatch->setDrawState(true);
|
||||
|
||||
nPatch = pTerrain->GetPatch(i+1,j-1);
|
||||
if(nPatch) nPatch->setDrawState(true);
|
||||
|
||||
nPatch = pTerrain->GetPatch(i-1,j);
|
||||
if(nPatch) nPatch->setDrawState(true);
|
||||
|
||||
nPatch = pTerrain->GetPatch(i+1,j);
|
||||
if(nPatch) nPatch->setDrawState(true);
|
||||
|
||||
nPatch = pTerrain->GetPatch(i-1,j+1);
|
||||
if(nPatch) nPatch->setDrawState(true);
|
||||
|
||||
nPatch = pTerrain->GetPatch(i,j+1);
|
||||
if(nPatch) nPatch->setDrawState(true);
|
||||
|
||||
nPatch = pTerrain->GetPatch(i+1,j+1);
|
||||
if(nPatch) nPatch->setDrawState(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// draw the patches
|
||||
for (ssize_t j=0; j<patchesPerSide; j++)
|
||||
{
|
||||
for (ssize_t i=0; i<patchesPerSide; i++)
|
||||
{
|
||||
CPatch* patch=pTerrain->GetPatch(i,j); // can't fail
|
||||
if(patch->getDrawState() == true)
|
||||
{
|
||||
c->Submit(patch);
|
||||
patch->setDrawState(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1102,11 +1049,6 @@ float CGameView::GetFOV() const
|
||||
return m->ViewFOV;
|
||||
}
|
||||
|
||||
float CGameView::GetCullFOV() const
|
||||
{
|
||||
return m->ViewFOV + DEGTORAD(6.0f); //add 6 degrees to the default FOV for use with the culling frustum;
|
||||
}
|
||||
|
||||
void CGameView::SetCameraProjection()
|
||||
{
|
||||
m->ViewCamera.SetProjection(m->ViewNear, m->ViewFar, m->ViewFOV);
|
||||
|
||||
Reference in New Issue
Block a user