PDA

View Full Version : Cartoon shading



Phoenix
08-07-2002, 10:10 AM
Hi!

I have a trouble with my cartoon-style shading algorithm...I just draw the object as it is and then I add a black contour line with the following steps:

draw_the_object();
glCullFace(GL_FRONT);
glPolygonMode(GL_LINE);
glLineWidth(4.0);
draw_the_object();

..the problem is: IF the object is transparent I will see all the the wireframe lines of the back polygons, and not only the contour lines...it is obviuos, but how can I avoid this in an efficient way?

AdrianD
08-07-2002, 10:27 AM
stencil!
draw your transparent object with stencil writes enabled - no testing, just replacing when depthtest ist passed, and then draw your outlines with stencil test enabled.

for more details about stencil, just take a look at the tutorials & faqs on www.opengl.org. (http://www.opengl.org.)

(btw. you can accomplish the same effect with alphatesting)

Phoenix
08-08-2002, 12:39 AM
Thanx! http://www.opengl.org/discussion_boards/ubb/wink.gif
That's the right solution!

Phoenix
08-08-2002, 06:30 AM
Just to know...I haven't understood how you would solve this problem with ALPHA_TEST...immagine you have to render in cartoon-style a transparent cube:
1- fist, you draw the transparent cube.
2- you enable front-face-culling
3- you set glPolygonMode(GL_BACK, GL_LINE)
4- .....and now ??????? ......

if you enable alhpa-testing you will discard everything!....

vincoof
08-08-2002, 06:48 AM
He didn't mention Alpha Testing, he did mention Stencil Testing.

Though, I would rather recommend simple Depth Testing if you can.
But if your transparent object does not write the depth buffer, well... use the stencil buffer http://www.opengl.org/discussion_boards/ubb/smile.gif

AdrianD
08-08-2002, 08:27 AM
i meant alphaBLENDING(you can use the alphabuffer as a mask as well). but this would only work with opaque objects. so it's not a solution for your problem...