Height maps and texture mapping

Started by
4 comments, last by Jederas 21 years, 7 months ago
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.
Advertisement
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 :-)
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.
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.

  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
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
quote:Original post by bazee
Didn''t you just almost answer your own question?

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)));

This topic is closed to new replies.

Advertisement