cross-sections with overlap

The title kind of says it all; i need to show a sliced cross section of my geometry.

So far i’m using the clip plane and stencil buffer (with GL_INVERT) together for this. That generates the right cross section, and looks pretty good, as long as nothing overlaps.

When things do overlap, it of course double-inverts, causing the overlapped areas to be turned off. So far i can’t fix this without it getting messed up by various solids that are not clipped (ie not part of the desired cross section)

Does anyone here know some stencil buffer magic (or any approach i guess) to ignore anything not cut by the clip plane, but also properly handle overlapping geometry?

Not sure how exactly the “invert” method works, but have you had a look at what the ATI demo does?

Seems to be:

  • Enable clip plane

  • Draw all front faces

  • Draw all back faces setting stencil = 1 where rendered

  • Draw a quad on the cutting plane where stencil == 1

  • Reset stencil

(of course I don’t really understand what you are doing, so this may not be useful to you)