Sign in to follow this  
Xpyder

Texturing Terrain based on Height

Recommended Posts

Hey guys I am working on a 3D terrain engine, and so far it loads a wireframe, colored island onto the screen based on a heightmap. The color settings use the height by a few simple ifs:
if (CV[x + (y * WIDTH)].Z == 0) { CV[x + (y * WIDTH)].Color = Colorif0.ToArgb();}
if (CV[x + (y * WIDTH)].Z == 1) { CV[x + (y * WIDTH)].Color = Colorif1.ToArgb();}
if (CV[x + (y * WIDTH)].Z == 2) { CV[x + (y * WIDTH)].Color = Colorif2.ToArgb();}
if (CV[x + (y * WIDTH)].Z >= 3) { CV[x + (y * WIDTH)].Color = Colorif3.ToArgb();}
but now i need to texture it instead of just colour it, so i sorted out the texture coordinates etc so it would basically render the whole thing in one texture, but when i tried to do the same sort of thing by doing the following:
for (int xy = 0; xy < WIDTH * HEIGHT; xy++)
{
  if (vertices[xy].Z == 0) 
  {
   device.SetTexture(0, tWater);
   device.DrawIndexedPrimitives(PrimitiveType.TriangleList,0,0,4,0,                      indices.Length/3);
  }
  if (vertices[xy].Z == 1)
  {
    device.SetTexture(0, tSand);
    device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, indices.Length / 3);
  }
  if (vertices[xy].Z == 2) 
  {
    device.SetTexture(0, tGrass);
    device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, indices.Length / 3);
  }
  if (vertices[xy].Z >= 3) 
  {
  device.SetTexture(0, tRock);
  device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, indices.Length / 3);
  }

It will only render the top-most texture. 
I have tried changing the numVertices parameter in DrawIndexedPrimitives (currently "4") from 1, to the maximum vertices but it has the same result. 

Can anyone offer any pointers (oh god i miss pointers) on this?

             }

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Umm... Are your "vertices[xy].Z" all int/long's? Otherwise you're only doing something if it's EXACTLY on that. I would suspect your coordinates were done in floats therefore you need to take into consideration 3.0001 to 3.9999 not just 3.0000.

You gave us nearly no information. Try posting some sample data, or telling us what vertices[xy].Z is, etc. Not using these puppies, "", might be your issue...

Share this post


Link to post
Share on other sites

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