Jump to content
  • Advertisement
Sign in to follow this  
arkerone

how to calculate the texture coordinates (heightmap)

This topic is 2214 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

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:

forest2012083014255114.png

how to calculate the texture coordinates?

thx. Edited by arkerone

Share this post


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


Link to post
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 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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!