Drawing intersections between surfaces and planes

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!

Calbuq

Hmmmm.

Have you though of doing this:

  1. Draw first NURB
  2. Draw second NURB
  3. Call glDepthFunc(GL_EQUAL)
  4. Change colour, and draw either NURB again

This should work, but wether it looks any good is another thing altogether

Actually, having said that, I’ve just realised that it won’t work (the depths aren’t going to be exactly the same at any position for the two NURB surfaces.)

Doh!!

Maybe I’ll figure it out later…

Have you thought about using OpenGL’s automatic texcoord generation facility?

Build a 1D texture, which is all set to your base colour except for 1 pixel, which is set to the “intersection” colour.

Now use glTexGen to generate texcoords for this texture based on linear distance from the plane. What you’re doing sounds like contouring with one contour line, and there’s example code in the Red Book on using texgen for this.

Haven’t tried this so I can’t guarantee it would work, but it’s the first thing that sprang to mind.

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
glDepthFunc(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);
glDisable(GL_DEPTH_TEST);
// 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!

Calbuq[/b]

One trick that has worked for me in this situation is to use the two clipping planes, with some extra tricks:

Draw everything, as usual.
Set a polygon offset, as if you’re drawing lines ontop of the polygons.
Set wireframe mode.
Set line width to be thick. (maybe 2 pixels
or more)
Set blending mode for lines.
Setup the two planes.
Draw the nurbs again.

I’m not 100% clear that this is what worked for me in the past, but it’s worth trying, I think.

Have fun.

Aha…is what I’m trying to do also, someone can help me, because I didn’t understand nothing about it, I can send a picture to you see my problem.

Tnks
Best RGDS
Kurt

Hmm…can someone help ???

I’m no OpenGL expert, but would it be too slow to compute the intersection on the CPU and then just draw a segmented line across the nurb? Then you won’t have to draw the nurbs more than once.