Jump to content
  • Advertisement
Sign in to follow this  
Alundra

Terrain Heightmap Intersection

This topic is 1327 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 all,

I'm searching the good way to compute intersection of ray and a heightmap.

I have the ray origin, the ray direction and the height on x/z of the terrain and the cell spacing (64 cells by patch).

I have searched a lot on google and I saw bresenham algo can be used but doesn't work good.

The second solution I saw is to use quad tree to intersect each patch and compute intersection inside it.

The question is for the second part of the algorithm, when you have the patch, what is the good way to find the intersection ?

Is it correct to compute each triangle of each cell (2 triangles per cell) and compute ray-triangle intersection like for a mesh ?

Thanks for the help

Edited by Alundra

Share this post


Link to post
Share on other sites
Advertisement

I'm not sure what's most commonly used, but your problem seems very similar to the problems encountered when doing real-time displacement mapping in shaders. The basic problem those algorithms solve is finding the nearest intersection between a ray and a heightmap tiled on an infinite plane, within some error tolerances. There would be some differences, e.g. your terrain wouldn't tile infinitely, so would also be restricted to some bounding box. Your ray may come from directions that wouldn't be encountered for a texture, e.g. inside the bounding box. You may also have tighter error tolerances than they allow. But it may be a useful start.

 

http://http.developer.nvidia.com/GPUGems3/gpugems3_ch18.html

Share this post


Link to post
Share on other sites


The question is for the second part of the algorithm, when you have the patch, what is the good way to find the intersection ?
Is it correct to compute each triangle of each cell (2 triangles per cell) and compute ray-triangle intersection like for a mesh ?

 

so you want to find the point of intersection between your ray and the ground mesh, where the ground mesh is defined by a heightmap.

 

the simple way is to compare ray y to heightmap y at a given x,z.

 

for pixel precise, you'd want to go with ray vs triangle intersection against the 2 tris making up the quad of intersection.  dirxectx sdk includes a raypick sample that does ray vs triangle intersections on a mesh, which should get you the second half of your algo.  the sample may only be available in older sdk's such as june 2010 (dx9.0c).

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!