PDA

View Full Version : Preventing Vertex colors from blending?



jerrym
04-15-2007, 06:48 AM
Hello!

I am attempting to create a cel-shading effect using OpenGL. I began experimenting with the NeHe example, which you can find here:
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=37

Soon after playing around with it, I noticed that it had a flaw.. it was providing the shading by mapping a texture.. so I edited it to load a texture, and map that instead. And instead of using the texture, it should now just use a color, based on the old 1D texture it would use.

All of that seems to work flawlessly. However, my problem is, is that the colors for the vertexes are blending in! This creates a pseudo-photo-realistic render, completely opposite of what I am looking for!

Here, you can see the textured model (not a very detailed texture though..) without glColor applied to the vertexes:
http://img151.imageshack.us/img151/2723/texshadingnoshadewy4.png

And here, you can see what happens when I am using glColor on them:
http://img180.imageshack.us/img180/1976/texshadingbadshadedv6.png

As you can see, the color blending is causing problems.. making it look more like a 3d object, than a drawing.

For clarification, glDisable(GL_BLEND) is being called, directly before glBegin...

Any help is appreciated.. Thanks!

Overmind
04-15-2007, 08:48 AM
That's exactly the reason why you normally use a texture for this kind of effect. OpenGL always interpolates everything linearly at the inside of a polygon.

You only tell OpenGL the color at the vertices, it has no way of figuring out what color you want at the inside, so it just interpolates. So you have to use a texture, to create this sharp edge.

Why do you think using a texture is a flaw in the algorithm? I don't think there is any other way to do this effect (other than really highly tesselated meshes, but that would be very slow).

jerrym
04-15-2007, 09:10 AM
Thanks for your answer.

So, in order to create a cel-shaded look, I must use textures for the lighting? That would mean that I have to implement multi-texturing I guess, if I want to have my own "skin" on the model...

In that case, could someone point me to an introduction to that?

zeoverlord
04-15-2007, 10:25 AM
Actually the best thing to use is a fragment shader, with it you can implement some pretty detailed and accurate cell shading that even accounts for ambient occlusion.