This calls for a stencil algorithm.
I would do something like this:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// Setup everything for your standard NURBS drawing and draw it. (Don’t daw into stencil though, or clear it afterwards.)
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // Don’t draw into color buffer.
glDepthMask(GL_FALSE); // Don’t draw into depth buffer, only necessary for comparision.
// Setup the stencil func and op to write somthing into the stencil buffer only if the depth comparison passes for GL_EQUAL
glStencilFunc(GL_ALWAYS, 1, ~0);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glDisable(GL_FACE_CULL); // you won’t bother for normal direction here
// Now draw your plane, big enough to slice through the whole NURB.
// Now you have ones in the stencil buffer on all pixels that have the same z-coordinate on the NURB and the plane.
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glStencilFunc(GL_NOTEQUAL, 0, ~0);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
// Now draw the same plane again with the desired color, but only set pixels which are selected through the stencil value
Voila! You should have some band effect.
Haven’t tried this myself, but I expect some aliasing effects, which get worse the more orthogonal the plane normal gets to the viewing direction.
If so, you could enhance the algorithm above with a second pass to catch the pixels between two planes like you did with the clipping. Thy have to span two half spaces and the stencil operation has to increment for the pixels in between.
Hope that helps.
Originally posted by calbuq:
[b]My models consist of bunch NURBS surfaces glued together. I would like that when I render the surfaces the points that belong to a given plane to be drawn with a different color, thus outlining the intersection of the surfaces with the plane.
I tried an approach using two parallel clipping planes very close to each other, but the results were visually poor.
Is there a way to set the renderer such that when it draws a point to the screen that belongs to a plane then it uses another color?
I was also thinking about using that function that maps the screen coordinates into the space coordinates, changing the color of the point if it belongs to a given plane. But then I would have to test each point of the screen, and I don’t know if that would be a good approach.
Any ideas are welcome!