#### Archived

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

# Height maps and texture mapping

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

## Recommended Posts

Hi everyone, I''ve been messing with lesson 34 from the nehe page (the one on height map based landscapes), and can''t seem to get my textures to work perfectly on them. I''ve tried giving static uv coords to each poly, but results in stretching in some places, and other weird little side effects. I''ve tried using the pythagorean theorom to get uv''s, but that hasn''t worked in any logical form (doesn''t seem to take y into account, even though y is properly set AND used in the equation). Was just wondering if any of you could help me out on this.

##### Share on other sites
the simplest way to texture a height map is to simply use the x,y coords of your verticies as u/v texture coords (assuming z is height) - but this will stretch on steep slopes... Getting perfect texturing accross the entire mesh would be pretty much impossible.

<-- smile :-)

##### Share on other sites
I''ve done that, and it''s not sufficient. Getting it to map perfectly can''t be impossible. There should be a way to do it by calculating length from connecting vertices.

##### Share on other sites
Didn''t you just almost answer your own question? Calculate the lengths of interconnecting vertices, add up these lengths along each row and column, and divide every length by the total. You will be left with texture coords between 0 and 1, with more texels dedicated to slopes etc. Might be a bit slow to calculate, but you only need to do it once.

##### Share on other sites

  HeightMap->Value((1.0f / Width) * X, (1.0f / Height) * Y));

gives you a value in the height map within the range [0.0f; 1.0f]. take it from here...

Crispy

##### Share on other sites
quote:
Original post by bazee

This is what I''ve been trying to do, it works to an extent, it just doesn''t seem to be taking height into account.

for every vertex in the array, x and z are assigned values directly from the two loops. So the only real variable is y, which you can see being set below by the height function. Clearly, if y wasn''t being set, everything would be flat, which it isn''t. After that, I get the length, and use that raw value. It works flawlessly on flat surfaces, but not on slopes. Crt stands for cube root, by the way.
x = X;
y = Height(pHeightMap, X, Y );
z = z;
u = float(crt((x * x) + (y * y) + (z * z)));
v = float(crt((z * z) + (y * y) + (z * z)));

• 17
• 11
• 15
• 9
• 49
• ### Forum Statistics

• Total Topics
631393
• Total Posts
2999765
×