Sign in to follow this  

[Win32 C++ 2003] Terrain Patch Glitches (Update)

This topic is 3795 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 finally managed to build a terrain and split it into patches. Currently working as a 3 x 3 patch display. However if you look at the following image you will see a tear in the seams. Is there anyway this can be resolved? I assume the stretching of a texture over the whole terrain solves the problem but is there anything else ? Thanks for any ideas that can be thrown my way as to why it does this. It seems to be related to the height as the more height there is in an area the more pronounced the tear. [Edited by - Xrystal on July 24, 2007 7:35:46 PM]

Share this post


Link to post
Share on other sites
That picture is too compressed to really allow us to tell what is going on. How about upload another one, less compressed and zoomed in the on the problem?
From what little I can make out it looks like the background is showing through the model, so its not a texture problem but a geometry one.
Perhaps you could upload the code where you build the patch aswell?

Share this post


Link to post
Share on other sites
Yeah, more information is needed for any of us to actually help you. There are several well-documented crack-fixing methods around the vast Intarweb that could help you out if you searched in the right places, but for us to help out we will, as was said, need more information.

I also hear there is a book on this matter. Not that I'd know anything about that.

Share this post


Link to post
Share on other sites
Thanks, for the replies. I wasn't sure if you needed more information or if the visual was enough. But yes, it is the the background coming through that I am seeing.

I'm attempting to see if turning the patches into meshes make a difference as that way I can test the code the book I'm learning from is using instead of my old code I used before in an old project.

I'll hook out the offending geometry code which might help. And replacing the original image with one that should be more close up.


This is from the Terrain class file

void CDXTerrain::GeneratePatches(int nPXSize, int nPZSize)
{
// Make enough room to store patch details
Resize(nPXSize * nPZSize);

// Make sure that the patches can be made
if (m_nXSize % nPXSize != 0) return;
if (m_nZSize % nPZSize != 0) return;

// Now that we know it is fully divisible work out the patch sizes
m_nXPatch = (m_nXSize / nPXSize);
m_nZPatch = (m_nZSize / nPZSize);

// Should make this a member variable but sets the terrain RECT for patches
RECT rTerrainData;
rTerrainData.top = 0;
rTerrainData.left = 0;
rTerrainData.bottom = rTerrainData.top + m_nZSize;
rTerrainData.right = rTerrainData.left + m_nXSize;

// variable to store RECT data for each patch (will be section of rTerrain
RECT rPatchData;

int index = 0;
for (int z = 0; z < m_nZSize; z+= m_nZPatch)
{
for (int x = 0; x < m_nXSize; x+= m_nXPatch)
{
// Create Patch Data from Terrain Data
rPatchData.top = z;
rPatchData.left = x;
rPatchData.bottom = z + m_nZPatch;
rPatchData.right = x + m_nXPatch;
m_vPatches[index] = new CDXPatch(m_pDevice);
m_vPatches[index]->Create(index,rPatchData,m_Heights,rTerrainData);
index++;
}
}
return;
}



This is from the Patch Class

void CDXPatch::Create(int nID, int nXPatches, int nZPatches,CString sFile, float fScale)
{
m_nID = nID;
m_VertsPerRow = nXPatches;
m_VertsPerCol = nZPatches;
m_CellsPerRow = m_VertsPerRow - 1;
m_CellsPerCol = m_VertsPerCol - 1;
m_VertsPerGrid = m_VertsPerRow * m_VertsPerCol;
m_IndicesPerGrid = (m_VertsPerRow * 2) * (m_VertsPerCol -1) + (m_VertsPerCol - 2);
m_halfWidth = ((float)m_VertsPerRow - 1.0f) / 2.0f;
m_halfLength = ((float)m_VertsPerCol - 1.0f) / 2.0f;

m_pVertices = new CDXVertices(m_pDevice);
m_pVertices->ReserveSpace(m_VertsPerGrid);
m_pVertices->HasPosition(false,false);
m_pVertices->HasTexture(1);

for (int z = 0; z < m_VertsPerCol; z++)
{
for (int x = 0; x < m_VertsPerRow; x++)
{
int index = (z * m_VertsPerCol + x);
m_pVertices->InsertPosition(index,stCoords((float)(x - m_halfWidth),(float)m_Heights.GetDataAt(index),(float)((z - m_halfLength))));
m_pVertices->InsertTexture(index,stTextures((float)x / (m_VertsPerRow - 1),(float)z / (m_VertsPerCol - 1)));
}
}

int i = 0;
for (int z = 0; z < m_VertsPerCol - 1; z++ )
{
// Even rows move left to right, odd rows move right to left.
if ( z % 2 == 0 )
{
// Even row
for (int x = 0; x < m_VertsPerRow; x++ )
{
m_pVertices->AddIndex( x + (z * m_VertsPerRow) + 0 );
m_pVertices->AddIndex( x + (z * m_VertsPerRow) + m_VertsPerRow);
}
// Insert degenerate vertex if this isn't the last row
if ( z != m_VertsPerCol - 2)
{
m_pVertices->AddIndex( --x + (z * m_VertsPerRow) + 0 );
}
}
else
{
// Odd row
for (int x = m_VertsPerRow - 1; x >= 0; x-- )
{
m_pVertices->AddIndex( x + (z * m_VertsPerRow) + 0 );
m_pVertices->AddIndex( x + (z * m_VertsPerRow) + m_VertsPerRow);
}
// Insert degenerate vertex if this isn't the last row
if ( z != m_VertsPerCol - 2)
{
m_pVertices->AddIndex( ++x + (z * m_VertsPerRow) + 0 );
}
}
}
m_pVertices->CreateVertexDeclaration();
m_pVertices->CreateVertexBuffer(m_VertsPerGrid,NULL,NULL);
m_pVertices->CreateIndexBuffer(m_IndicesPerGrid,NULL,NULL);
m_pVertices->UseMaterial(new CDXMaterial(m_pDevice));
m_pVertices->Material()->SetColor(true,true,true,false,0.5f,0.0f,0.5f,0.0f);
}



The Code to generate the terrain in this function was taken from another book or website example. I can't see anything wrong with it per-se so if you see something that I may have overlooked when converting variable names please point it out. Admittedly my TriangleStrip knowledge is not that great. I try to use Triangle Lists myself.

I hope this code and the new picture helps somewhat in confirming your suspicions.

I'll be sure to update the thread if the problem resolves itself by converting each patch to a mesh but for learning purposes I would like to know what may have caused the glitch.

Thanks again.

Share this post


Link to post
Share on other sites
Thats a possibility Matt, thanks. Scaling the patches were one of the next steps I needed to take but didn't want to do too much before I got a standard display working.

Will have to work that into the code and see if it worked.

Share this post


Link to post
Share on other sites
Quote:
Original post by Xrystal
Thats a possibility Matt, thanks. Scaling the patches were one of the next steps I needed to take but didn't want to do too much before I got a standard display working.

Will have to work that into the code and see if it worked.

Another possible approach is to just render "skirts" around the edges of the patches which are of a higher detail level than their neighbors. The implementation of this is, actually, just about what it sounds like it should be. You just render a vertical patch of triangles which takes the vertices of the higher-detail patch and make them whatever height would be necessary to cover up the patch. The texture is just stretched along this patch and, unless the crack is absolutely enormous, would be almost invisible.

Of the crack-fixing techniques that I remember relying on for my terrain implementations, this was always the quickest and easiest solution to implement.

Share this post


Link to post
Share on other sites
Just wanted to thank all you guys for your suggestions. Looks like the problem was how I was positioning or splitting the terrain up or the heightmap I was using in the test.

I've finally managed to incorporate the ability to convert vertex data into a mesh and display a terrain mesh in segments by adjusting the attribute value to reflect what segment ID to tie a face to. I haven't been able to repeat the problem now but then alot of the code I used before is not in play at present.

Share this post


Link to post
Share on other sites

This topic is 3795 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this