Skip to main content
GameDev.net gamedev.net
🔒 Locked

indices - terrain cracks

Started by guts Jan 21, 2004 at 8:44 AM 3 replies 550+ views
Original Post
guts
guts
hi! I'm currently calculation the indices for my geomipmap terrain this way: (per patch)
void CPatch::BuildIndices(int lod)
{
	int index= 0;
	int rX, rZ;

	for(int z=0; z < mTerrain->mPatchsize-1; z+= mIncrement[lod]) 
	{
		for(int x=0; x < mTerrain->mPatchsize; x+= mIncrement[lod]) 
		{
			rX= (mPatchX*(mTerrain->mPatchsize-1)) + x;
			rZ= (mPatchZ*(mTerrain->mPatchsize-1)) + z;
		
			mIndices[lod][index + 0] = (rZ*mTerrain->mMapsize) + rX;
			mIndices[lod][index + 1] = ((rZ + mIncrement[lod])*mTerrain->mMapsize) + rX;
			index += 2;
		}
	}
}
 
however, now i want to get rid of those cracks. i heard of a technique where, because of calculating the right order of indices there won't be cracks. have you any idea how this works?! PS: how are these code tags working? [ C O D E ] ... [ / C O D E ]doesn't work?! does it? [edited by - guts on January 22, 2004 11:52:10 AM]
Agony
Agony
[code]User lower case for "code"[/code] 



"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas nly, and not for things themselves." - John Locke o
BradDaBug
BradDaBug
I''m assuming you''ve looked at this. If not, look.

Basically you figure out what the neightboring block''s LOD is and adjust the connectivity of the verticies of current block.

Game Development Wiki
I like the DARK layout!
guts
guts
thanks for the information on the code tags :D

i already looked at this paper, but i do not know how to calclate the indices ...

is there somebody out there who knows how to?
some hints? (or even source code?!) . . . maybe you think i''m to lazy, but you know, i just don''t get it. (i tried for about 1 month ... and didn''t get any result, what is somehow depressing ...)


bye...
guts
Trienco
Trienco
i guess the usual method is to have different index buffers for the "body" of a tile and the edges. so for each level you have an index buffer thats covering the whole tile and buffers that leave out the edges (all combinations). if you dont mind wasting more memory you can of course create all possible combinations of index buffers for every thinkable combination of lower level neighbours. though that would save up to 4 calls to draw i get a light headache thinking about how many combinations that would be for 32x32 or even 64x64 tiles.

you build those edges in a pretty simple way (i avoid that often used triangle fan approach because in some situations it will just look like sh.. bad)


x---x---x x-------x
\ /|\ / \ \ / /
x-x-x x-x-x

x x
|\ /|
x-x-x-x-x
|/|/|/|/|
x-x-x-x-x


you need a little fantasy for the second, but with only two points in the upper row i hope its obvious. also, keep in mind, that your "bodies" arent rectangles (second row as example).

you can write a function to create the index buffers, though its one of those that i have to look at for a while to figure out what i thought when writing it. without comments or support:


void CLevel::BuildLinkers(unsigned int lvl) {
if (!lvl) return;
Linkers=new CLinkingPiece[lvl];

const int StripsHigh=1<<lvl;
const int HighStep=PSz/StripsHigh;
for (unsigned int lowlvl=0; lowlvl<lvl; ++lowlvl) {
for (unsigned int side=0; side<4; ++side)
{
const unsigned int StripsLow=1<<lowlvl;
const unsigned int LowStep=PSz/StripsLow;
const unsigned int BuffSz=StripsLow*(3+ (LowStep/(2*HighStep)-1)*6) + (StripsLow-1)*6;

int n=513;
unsigned int offset=0;
bool switchorder=false;
int f=1;

glGenBuffersARB(1, &Linkers[lowlvl].IdxBuffer[side]);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, Linkers[lowlvl].IdxBuffer[side]);
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
BuffSz*sizeof(unsigned short), 0, GL_STATIC_DRAW_ARB);
unsigned short* Buffer=
(unsigned short*) glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);

//Horizontal Piece

if (1==side || 3==side) {
if (3==side) {offset=PSz; f=-f; switchorder=true;}

unsigned int i, j, num=0;
for (i=offset; i<offset+PSz*n; i+=LowStep*n) {
j=i;

if (switchorder) Buffer[num++] = f*HighStep + (i+(LowStep/2)*n);
Buffer[num++]= i;
if (!switchorder) Buffer[num++] = f*HighStep + (i+(LowStep/2)*n);
Buffer[num++]= i+LowStep*n;

for (j=i+HighStep*n; j<i+(LowStep/2)*n; j+=HighStep*n) {
if (switchorder) Buffer[num++]= f*HighStep+ j+HighStep*n;
Buffer[num++]= f*HighStep+ j;
if (!switchorder) Buffer[num++]= f*HighStep+ j+HighStep*n;
Buffer[num++]= i;
}
for (j=i+(LowStep-HighStep)*n; j>i+(LowStep/2)*n; j-=HighStep*n) {
if (switchorder) Buffer[num++]= i+LowStep*n;
Buffer[num++]= f*HighStep+ j;
if (!switchorder) Buffer[num++]= i+LowStep*n;
Buffer[num++]= f*HighStep+ j-HighStep*n;
}
if (i<offset+PSz*n && i>offset) {
if (switchorder) Buffer[num++]= i;
Buffer[num++]= (f*HighStep)+i;
if (!switchorder) Buffer[num++]= i;
Buffer[num++]= (f*HighStep)+(i-HighStep*n);

if (switchorder) Buffer[num++]= i;
Buffer[num++]= (f*HighStep)+(i+HighStep*n);
if (!switchorder) Buffer[num++]= i;
Buffer[num++]= (f*HighStep)+i;
}
}
Linkers[lowlvl].IdxBufferSz[side]=num;
}

//Vertikal Piece

if (0==side || 2==side) {
if (side==0) {offset=PSz*n; n=-n; switchorder=true;}

unsigned int i, j, num=0;
for (i=offset; i<PSz+offset; i+=LowStep) {
j=i;

if (switchorder) Buffer[num++]= HighStep*n + (i+LowStep/2);
Buffer[num++]= i+LowStep;
if (!switchorder) Buffer[num++]= HighStep*n + (i+LowStep/2);
Buffer[num++]= i;

for (j=i+HighStep; j<i+LowStep/2; j+=HighStep) {
if (switchorder) Buffer[num++]= HighStep*n+ j+HighStep;
Buffer[num++]= i;
if (!switchorder) Buffer[num++]= HighStep*n+ j+HighStep;
Buffer[num++]= HighStep*n+ j;
}
for (j=i+LowStep-HighStep; j>i+LowStep/2; j-=HighStep) {
if (switchorder) Buffer[num++]= i+LowStep;
Buffer[num++]= HighStep*n+ j-HighStep;
if (!switchorder) Buffer[num++]= i+LowStep;
Buffer[num++]= HighStep*n+ j;
}
if (i<PSz+offset && i>offset) {
if (switchorder) Buffer[num++]= i;
Buffer[num++]= HighStep*n+ i-HighStep;
if (!switchorder) Buffer[num++]= i;
Buffer[num++]= HighStep*n+ i;

if (switchorder) Buffer[num++]= HighStep*n+ i;
Buffer[num++]= HighStep*n+ i+HighStep;
if (!switchorder) Buffer[num++]= HighStep*n+ i;
Buffer[num++]= i;
}
}
Linkers[lowlvl].IdxBufferSz[side]=num;
}
glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB);
}
}
}


im not posting the code for the bodies, as this silly insisting on triangle strips causes even sillier "corner" buffers with ridiculous 1-4 triangles. that alone is probably killing any benefit of using strips.
f@dzhttp://festini.device-zero.de

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.