# Geomipmapping Calc Errors Question

This topic is 5462 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've tried implementing the Precalculation of Errors for geomipmapping based on Promit's desciption given here http://www.gamedev.net/community/forums/topic.asp?topic_id=252983 But for some reason I either get highly detailed patches no matter how far away I am from them, or I get no detail at all even if I'm standing on top of the patch. Here's my source for calculating D.
void GeoTerrain::CalculateErrors(float MaxError, int Vres, float FoV, float NearClip)
{

//vars for de Boer's equations
float C, A, T;

T = 2 * MaxError / Vres;
FoV *= (3.141596 / 180.0f);              //convert FoV to radians
A = 1.0f / (float) tan( FoV / 2.0f );
C = A / T;

float Delta;
for(int i=0; i < m_PatchCount; i++)     {
for(int j=0; j < m_PatchCount; j++)     {
Delta = 0;
for(int l=0; l < m_MaxLOD; l++) {
int start = (int)pow(2.0f, l);
int inc = start*2;

for(int z=start; z < m_PatchSize; z+=inc)      {
for(int x=start; x < m_PatchSize; x+=inc)      {

int index = m_Patches[i*m_PatchCount+j].m_Indices[z*m_PatchSize+x];
int i0,i1,i2,i3;
i0 = m_Patches[i*m_PatchCount+j].m_Indices[(z-start)*m_PatchSize+(x-start)];
i1 = m_Patches[i*m_PatchCount+j].m_Indices[(z+start)*m_PatchSize+(x+start)];
i2 = m_Patches[i*m_PatchCount+j].m_Indices[(z-start)*m_PatchSize+(x+start)];
i3 = m_Patches[i*m_PatchCount+j].m_Indices[(z+start)*m_PatchSize+(x-start)];

float diff;

diff = m_Vertices[index*3+1] - ((m_Vertices[i0*3+1] + m_Vertices[i1*3+1]) / 2.0);
if(diff < 0) diff*=-1;
if(Delta < diff) Delta = diff;

diff = m_Vertices[index*3+1] - ((m_Vertices[i2*3+1] + m_Vertices[i3*3+1]) / 2.0);
if(diff < 0) diff*=-1;
if(Delta < diff) Delta = diff;
}
}
m_Patches[i*m_PatchCount+j].D[l] = Delta * C;
}
}
}

}


And when I call the function, I pass in the following values: MaxError = 4.0 VRes = 600 // since i'm using 800x600 FoV = 65 NearClip = 1 Here are some screenshots of my problem screens Anybody know what's wrong?

##### Share on other sites
The first thing I'd check is that on any given loop iteration, if i0, i1, i2, and i3 are the correct values.

Unfortunately, this is a bitch to do. Use conditional breakpoints and break it at a few different test LoD levels, starting with just the first LoD and checking if the indices are being chosen correctly.

Remember that this is based on analyzing the diagonals from each vertex that is being removed, because those are the removed edges. The var start is the amount of verts between each removed vertex. So make sure the vertex indices are correct. If they are, we can move on to looking at the next part of the code, but one thing at a time.

Oh, I have one general recommendation. When doing this, restrict your renderer to drawing patch 0, and confirm that the algorithm works for that single patch. Then put the loop for all the patches back in. This was absolutely key for me to figure out how to make mine work right.

P.S. Your value for pi is wrong. The last digit is a 3, after being rounded off.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 22
• 17
• 46