• Popular Now

• 12
• 9
• 9
• 13
• 10

Archived

This topic is now archived and is closed to further replies.

Terrain texturing problems

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

Recommended Posts

Ok, either I'm not thinking clearly or just not "getting" it. I have this terrain engine and it renders nice and spiffy. It loads up a .raw file for the heightmap and the like. My question is how should I approach the algorithm to texture the terrain so that I will not get mirrored textures? Check this screen:
Notice how the texture is mirrored (it's an M). If I have [1] at texture coordinate (0,0) and [4] at (1,1), then the next quad left and down will have the starting texture coordinate of [4]. Damn, does this makes sense? 1---2 |....| (one quad) 3---4 1---2---? |....|....| 3---4---? (four quads) |....|....| ?---?---? What should I fill the [?] with? [edited by - Ðragun on April 2, 2003 2:37:36 AM]

Share on other sites

If you are using regular quads, you redefine texture coordinates for each quad- at least that''s how I do it

1---2,1---2
|.a..|..c.|
|.b..|.c..|
3---4,3---4

for quads defined in order a,b,c,d. ie each one has
1---2
3---4

If you are using quad strips:

1---2,1---2
|.a.|.d.|
|.b..|..c.|
1---2,1---2

ie down a,b up c,d

Share on other sites
If you''re using DirectX you should turn on tiling (might be called wrapping) for textures. This means that you can use texture coordinates < 0 and > 1 and they will refer to a texture map consisting of tiled copies of your texture without any mirroring.

Share on other sites
I''m using triangle strips where it''s just a plain grid defined as quads (all quads share vertices with another quad). How should I approach this? Redefine my U,V coordinates?

Share on other sites
Set your texture coord mode to WRAP, then you can do:

0,0---0,1---0,2
|......|......|
|......|......|
2,0---2,1---2,2

Share on other sites
For my engine, and I'm not sure why exactly this works (I use OpenGL), but it tiles the textures nicely per quad with no mirroring and you can use efficiently vertex arrays because the texture coords are per vertex. Here is the code:

          int width, length;  //width and length of the terrain in verticesTEXCOORD texCoords[width*length];  //TEXCOORD is just a struct with a float u,v;//this loop isn't optimizedfor(int z=0 ; z < width ; z++){   for(int x=0 ; x < length ; x++)   {      texCoords[z * width + x].u = (float)x;      texCoords[z * width + x].v = (float)z;   }}

And that should give you texcoords per vertex to tile without mirroring and be able to use vertex arrays. When you go to render, just make sure texcoord[0] corresponds to vertice[0], and texcoord[1] corresponds to vertce[1] . . . texcoord[n] corresponds to vertice[n].

Hope that helps!

-------------------
Realm Games Company

[edited by - greatone on April 2, 2003 5:41:19 PM]