Jump to content
  • Advertisement
Sign in to follow this  
nullsquared

Heightfield-Plane intersection

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

If I have an image-based representation of a heightfield, how can I find all of its intersections with a given plane? Essentially, I want to draw an "imprint" on the plane that shows exactly where the heightfield hit it.

Share this post


Link to post
Share on other sites
Advertisement
On the CPU, you'd probably have to analyze each "pixel" in heightmap and detect when two adjacent pixels are on different sides of the plane, hence an intersection through the plane between them.

On the GPU, you could render the heightmap image as depth (with a solid color) and the plane over it as a different color, and let the depth buffer do a lot of the work. If you then run an edge filter over that, you'll get a contour image.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zipster
On the CPU, you'd probably have to analyze each "pixel" in heightmap and detect when two adjacent pixels are on different sides of the plane, hence an intersection through the plane between them.


Indeed, I'm doing this on the CPU. Thanks for the suggestion. (I forgot to mention that the plane is aligned with the heightmap)

Share this post


Link to post
Share on other sites
If the heightmap / plane are the same size, then for each vertex (i.e. texel) in the heightmap, measure it's distance from the plane. Use positive distances for verts on the positive side of the plane, and negative distances for verts on the other side of the plane.
Now you've got a distance field representing the intersection of the plane. If you want to render this on the GPU, you can encode the distances by scaling them by some factor and adding 128 (e.g. outByte = inFloat * scale + 128). Now you've got the distance field in an 8-bit greyscale texture.
In a pixel shader, you can use their 'dist-field-value' to generate an alpha value.

e.g. for an outline of the intersection:
float distance = ...get value from texture...
float width = 0.1;//thickness of the line
float soften = 0.01;//how much to fade out at the edges
float alpha = smoothstep( 0.5-width-soften, 0.5-width, distance );
alpha *= 1-smoothstep( 0.5+width, 0.5+width+soften, distance );
or for the areas below the plane:
float distance = ...get value from texture...
float soften = 0.01;//how much to fade out at the edges
float alpha = 1-smoothstep( 0.5-soften, 0.5+soften, distance );

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!