PDA

View Full Version : 2D cross section of a triangle mesh (problems on ATI cards)



tenchi
02-21-2005, 06:01 PM
I've got an application that lets the user position a cutting plane along a triangle mesh in one OpenGL window and in another window it displays a 2D cross section of the mesh in the specified plane.

Currenty this is done in OpenGL with two clip planes (glClipPlane) very close to each other. Rendering is done with glPolygonMode(GL_FRONT_AND_BACK,GL_LINE). This ensures that everything is drawn correctly when projecting orthogonally.

This works very well on Nvidia cards and also works with the software renderer.

However on ATI cards (tested on ATI Radeon 9600XT) there are problems. In the 2D cross section window, all I get is a couple of dots on the screen. The problem could be because the ATI card does not draw the lines where the plane intersects the triangles when using the GL_LINE polygon mode. This seems to go against what the OpenGL specs say.

Is there are more robust way to do this in OpenGL, so that it will work on all graphics cards?

Note that I only want to draw the lines where the plane intersects the triangles mesh, and NOT the capped cross-section as can be produced byusing stencil buffer capping.

tenchi
02-23-2005, 08:09 PM
The only other option that I have at the moment is to do this geometrically. That is, intersect the plane with each triangle in the mesh, calculate the lines of intersection and draw them. This would also require some sort of space partitioning in order to keep the number of intersection tests low.

However this seems like a lot of work to do, so if anyone has any better ideas of how to achieve this in OpenGL please let me know.

jwatte
02-24-2005, 04:48 AM
To fake a far plane, you can turn off color writes, and render the plane as geometry to the Z buffer. Turn back on color writes, and render your geometry.

To do the same thing with near, you can do some tricks with stencil, similar to stencil shadows. (Can be done for far, too)

Humus
02-26-2005, 05:27 PM
I'm not sure I'm getting a good picture of the problem. Do you have a screenshot?

If you're seeing a difference between ATI and nVidia with clip planes it could be because ATI supports geometric clipping while nVidia does not (emulated by discarding fragments in the shader I believe). This means that you'll have to use a depth bias in some cases as clipped geometry won't generate exactly the same depths as unclipped geometry.

tenchi
03-02-2005, 02:06 PM
I've posted a photo of the problem at:

http://public.fotki.com/tenchi/opengl/clip.html

As you can see I am positioning the clipping plane (in blue) along a cylinder.

From there you can see the differnces in clipping between ATI and NVIDIA.

First thing to note is the difference when doing the wireframe rendering (GL_LINE) with clip plane turned on. NVIDIA and software renderers create and draw the edges where the plane intersects the triangle mesh. No such thing on the ATI, the edges are not drawn. I've circled this in red in both pictures.

The next thing is the actual 2D cross section view. As I explained before this is achived by having two clipping planes positioned very close to each other. The view uses orthogonal projection and everything is draw using glPolygonMode(GL_FRONT_AND_BACK,GL_LINE).

In case of NVIDIA and software renderer the cross section is a circle, as expected. On the ATI card only a small number of dots can be seen which do resemble a circle, but this is far from what I am after.

I believe that the problem goes back to the wireframe images that I presented earlier. Since I am using the GL_LINE mode for drawing the 2D cross section view and the ATI card does not draw the edges of intersection between the clipping plane and the triangle mesh, obviously I won't see the desired cross section.

V-man
03-03-2005, 06:37 AM
From reading the spec, it seems nvidia and the software renderer are correct.

It could be that the lines generated are getting clipped. Maybe try to apply an offset. You will need glEnable(GL_POLYGON_OFFSET_LINE) and glPolygonOffset.
If that not it, then maybe there is another solution.

I have noticed a long time ago that polygons rendered as lines don't get properly culled. Some edges become visible depending the the modelview matrix. I don't know if they have fixed them.