how to calculate the texture coordinates (heightmap)

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

Recommended Posts

Hello,
I create a terrain from a heightmap, I would like to correctly calculate the texture coordinates for this terrain. At the moment I apply this formula:

[source lang="cpp"]tu.x = vertex.x/terrainWidth;
tu.y = vertex.z/terrainHeight;[/source]

but I get this:

how to calculate the texture coordinates?

thx. Edited by arkerone

Share on other sites
That looks correct to me.

what you have is a pixel for every vertex in the grid, and stretching is probably one aspect you have to deal with in some way.
My solution would be to have a regular grid size (i assume you already have that) and from there create a height map that is actualy valid, not going from 0->255 in adjacent pixels.

Yould you render the terrain with only the uv´s as the output color? that would help your debugging!
rendering in wireframe might find you unregular triangles aswell!

Another solution to this is a two set uv space.
one uv set that handles the height map (all vertexes raingin from 0->1 in all)
and one uv set that handles tiling. to uv map small texture like, rock, sand and grass to apply on as a final color texture. You will ofcourse need a splatmap beside to get the correct tiling.

Share on other sites
Hello,

there is no easy solution to calculate texture coordinates for terrains which have high height variation. The result you get is correct to the texture coordinate calculation formula you use.

You could try to implement tri-planar texture mapping, check here for details : http://memoirsofatexel.blogspot.ca/2010/08/terrain-triplanar-uv-mapping.html
It works better in the case you have presented.

Cheers!

Share on other sites
Thanks kauna it works fine ;)!

1. 1
2. 2
Rutin
20
3. 3
4. 4
A4L
15
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 9
• Forum Statistics

• Total Topics
633738
• Total Posts
3013617
×