1
0
forked from 0ad/0ad

fixed Shadow culling: second implementation

This was SVN commit r5052.
This commit is contained in:
christian 2007-05-10 15:28:59 +00:00
parent a34b759720
commit 6fa68cd957
3 changed files with 43 additions and 44 deletions

View File

@ -319,7 +319,36 @@ void CGameView::EnumerateObjects(const CFrustum& frustum, SceneCollector* c)
if (!m->Culling || frustum.IsBoxVisible (CVector3D(0,0,0), bounds)) {
//c->Submit(patch);
patch->setDrawState();
// 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);
}
}
}
@ -333,7 +362,7 @@ void CGameView::EnumerateObjects(const CFrustum& frustum, SceneCollector* c)
if(patch->getDrawState() == true)
{
c->Submit(patch);
patch->resetDrawState();
patch->setDrawState(false);
}
}
}

View File

@ -45,24 +45,6 @@ void CPatch::Initialize(CTerrain* parent,u32 x,u32 z)
}
InvalidateBounds();
// get the neightbors
this->m_Neightbors[CPATCH_NEIGHTBOR_LEFT_TOP] =
this->m_Parent->GetPatch(x-1,z-1);
this->m_Neightbors[CPATCH_NEIGHTBOR_TOP] =
this->m_Parent->GetPatch(x,z-1);
this->m_Neightbors[CPATCH_NEIGHTBOR_RIGHT_TOP] =
this->m_Parent->GetPatch(x+1,z-1);
this->m_Neightbors[CPATCH_NEIGHTBOR_LEFT] =
this->m_Parent->GetPatch(x-1,z);
this->m_Neightbors[CPATCH_NEIGHTBOR_RIGHT] =
this->m_Parent->GetPatch(x+1,z);
this->m_Neightbors[CPATCH_NEIGHTBOR_LEFT_BOTTOM] =
this->m_Parent->GetPatch(x-1,z+1);
this->m_Neightbors[CPATCH_NEIGHTBOR_BOTTOM] =
this->m_Parent->GetPatch(x,z+1);
this->m_Neightbors[CPATCH_NEIGHTBOR_RIGHT_BOTTOM] =
this->m_Parent->GetPatch(x+1,z+1);
}
///////////////////////////////////////////////////////////////////////////////
@ -80,4 +62,3 @@ void CPatch::CalcBounds()
}
}

View File

@ -21,16 +21,16 @@ class CTerrain;
const int PATCH_SIZE = 16;
///////////////////////////////////////////////////////////////////////////////
// CPatchNeightbors: neightbor - IDs for CPatch
// CPatchNeightbors: neighbor - IDs for CPatch
#define CPATCH_NEIGHTBOR_LEFT_TOP 0
#define CPATCH_NEIGHTBOR_TOP 1
#define CPATCH_NEIGHTBOR_RIGHT_TOP 2
#define CPATCH_NEIGHTBOR_LEFT 3
#define CPATCH_NEIGHTBOR_RIGHT 4
#define CPATCH_NEIGHTBOR_LEFT_BOTTOM 5
#define CPATCH_NEIGHTBOR_BOTTOM 6
#define CPATCH_NEIGHTBOR_RIGHT_BOTTOM 7
#define CPATCH_NEIGHBOR_LEFT_TOP 0
#define CPATCH_NEIGHBOR_TOP 1
#define CPATCH_NEIGHBOR_RIGHT_TOP 2
#define CPATCH_NEIGHBOR_LEFT 3
#define CPATCH_NEIGHBOR_RIGHT 4
#define CPATCH_NEIGHBOR_LEFT_BOTTOM 5
#define CPATCH_NEIGHBOR_BOTTOM 6
#define CPATCH_NEIGHBOR_RIGHT_BOTTOM 7
///////////////////////////////////////////////////////////////////////////////
// CPatch: a single terrain patch, PATCH_SIZE tiles square
@ -47,9 +47,6 @@ public:
// calculate and store bounds of this patch
void CalcBounds();
// neightbors of this patch
CPatch *m_Neightbors[8];
// is alread in the DrawList
bool m_bWillBeDrawn;
@ -60,18 +57,10 @@ public:
u32 m_X,m_Z;
// parent terrain
CTerrain* m_Parent;
// draw state...
void resetDrawState() { this->m_bWillBeDrawn = false; }
void setDrawState()
{
for(int i=0;i<8;i++)
{
if(m_Neightbors[i])
m_Neightbors[i]->m_bWillBeDrawn = true;
}
m_bWillBeDrawn = true;
}
bool getDrawState() { return this->m_bWillBeDrawn; }
void setDrawState(bool value) { m_bWillBeDrawn = value; };
bool getDrawState() { return m_bWillBeDrawn; };
};