   Heightfield-Plane intersection
  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.   
  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.   ;Quote:Original post by ZipsterOn 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)   ;  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 linefloat soften = 0.01;//how much to fade out at the edgesfloat 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 edgesfloat alpha  = 1-smoothstep( 0.5-soften, 0.5+soften, distance );