Contouring in OpenGL

Hi,

I Need to display contours for a given grid. The grid what I have is triangulated. I also have an algorithm for generating contours for a given range. Now one option is to use this generated contour values to display the contour lines using VBOs. I want to know whether there is more easier way to do the same using opengl shaders? I guess it is possible after reading this thread. I didn’t completely understand that. Is it that algorithm what I have written should be written in the shader itself?

Please guide me.

Thanks

Regards
Rakesh Patil

A relatively easy way is to write to a buffer the contour level of each pixel based on it’s world height value as you render the terrain. Then do an edge detection algorithm on this texture buffer and overlay it on your terrain. You can also use this to display solid filled contour regions.

OMG! I am confused :confused: Well, I did understand the first half. But how can I change the number of contour lines? Will Edge detection algorithm help me in displaying 100 contour lines next time, if the current number of contour lines is say 20? I mean user is provided with an interface to change the number of contour lines. So every time the contouring must go through this procedure what you mentioned? The overlaying over terrain is not compulsory for me right now.

You collect the contour values for a pixel when ever you render the screen (the overhead on the shader is trival but you do need any extra texture buffer). The number of contours if effective unlimited since you simple divide the height (minus a contour base if you want) by the contour step size and store the floor of the result. If the user changes the step size you just refresh the view.

If the step is say 10 meters, any height between 0 < 10 will store 0, 10 < 20 will store 1 etc.

Now every pixel belongs to exactly 1 contour level. Using an edge detection algorithm you can draw the contours. I use a simple algorithm which gives me a contour line 2 pixels wide. I use different colours for major and minor contours.

I don’t use this for contouring when different line thickness are required or contours have to be labels but you can probably extend it to work in these cases.

what do i do to get labels along with the contour lines? can you share ur algorithm for more reference?

Thanks

I brute force mine. Look at the triangle, see what contours cross it, save them - now I have poly lines and I can label along the length of the poly line. There are probably better methods but it is usually for plotting where speed is not an issue