Jump to content
  • Advertisement

Archived

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

Jederas

Height maps and texture mapping

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

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 this post


Link to post
Share on other sites
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 :-)

Share this post


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


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


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


Link to post
Share on other sites
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)));

Share this post


Link to post
Share on other sites

  • 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!