Jump to content
  • Advertisement
Sign in to follow this  
soconne

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!