Jump to content
  • Advertisement
Sign in to follow this  

cel shading help

This topic is 4510 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey everyone, Ive been doing a bit of cel shading and its worked out great :) However, like in the nehe cel shading tutorial i wanted to add thick borders to give it a more cartoony feel. But, since im drawing my model based on triangles, all of them have a border. Im using pretty much the same code as in the nehe tutorial, which also draws on triangles so im not sure what im missing or doing wrong. Here's an example: http://pingoo.dyndns.org/before.png <- normal cel shading http://pingoo.dyndns.org/after.png <- thick borders This is the code im currently using:
            gl.glEnable(GL.GL_BLEND);                                     // Enable Blending
            gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);    // Set The Blend Mode
            gl.glPolygonMode( GL.GL_BACK, GL.GL_LINE);                  // Draw Backfacing Polygons As Wireframes
            gl.glLineWidth(outlineWidth);                                 // Set The Line Width
            gl.glCullFace( GL.GL_FRONT);                                   // Don't Draw Any Front-Facing Polygons
            gl.glDepthFunc(GL.GL_LEQUAL);                                 // Change The Depth Mode
              for (int i = 0; i < cIndex.length; i++)
                gl.glVertex3f(cIndex[0], cIndex[1], cIndex[2]);
            gl.glDepthFunc(GL.GL_LESS);                               // Reset The Depth-Testing Mode
            gl.glCullFace(GL.GL_BACK);                                // Reset The Face To Be Culled
            gl.glPolygonMode(GL.GL_BACK,GL.GL_FILL);                  // Reset Back-Facing Polygon Drawing Mode
Anyone have any ideas how i can fix this ? I really appreciate any help :) Cheers,

Share this post

Link to post
Share on other sites
Are you sure the model is placing its polygons in a counter clockwise fashion? Try switching glFrontFace(GL_CW) or glFrontFace(GL_CCW) if you've specified to use clockwise...

Are you using backface culling when you draw the object without the borders?

Share this post

Link to post
Share on other sites
Hey guys cheers for the replies.

So I looked at my code, and noticed that I didn't enabled GL_CULL_FACE enabled! ;) So I enabled it, and it appears to of done something else weird now (most likely im missing something small, but cant seem to see it).

Here's a few pics:
http://pingoo.dyndns.org/noculling.png <- Here it is zoomed with culling disabled
http://pingoo.dyndns.org/culling.png <- Here it is zoomed with it enabled

As you can see it seems to of disabled my cel shading effects.. I've zoomed in because from afar the model just looks black, which incidentally is what happens to the model in the nehe tutorial if you dont turn on GL_CULL_FACE.

I also tried changing it to CCW drawing, but it didnt seem to make much difference. (http://pingoo.dyndns.org/culling_ccw.png) Likely im doing something else wrong.

The following is the code Ive used:

/****Setup code****/
gl.glGenTextures(1, shaderTexture);
gl.glBindTexture(GL.GL_TEXTURE_1D, shaderTexture[0]);

// Don't Let OpenGL Use Bi/Trilinear Filtering

// Upload
gl.glTexImage1D(GL.GL_TEXTURE_1D, 0, GL.GL_RGB, 32, 0, GL.GL_RGB, GL.GL_FLOAT, shaderData);

// Normalize the direction of our light

// Use The Good Calculations (Enables Anti-Aliasing)

// Enable OpenGL Face Culling
gl.glEnable (GL.GL_CULL_FACE);

// Disable OpenGL Lighting
gl.glDisable (GL.GL_LIGHTING);

/****Cel Shading code****/
gl.glEnable (GL.GL_TEXTURE_1D);
gl.glBindTexture (GL.GL_TEXTURE_1D, shaderTexture[0]);
gl.glColor3f (colour[0], colour[1], colour[2]);

float cIndex[][] = ifs.getCIndex();
float normalIndex[][] = ifs.getNIndex();

// Get the current Matrix
gl.glGetFloatv(GL.GL_MODELVIEW_MATRIX, m);


for (int i = 0; i < cIndex.length; i++)
// store current normals
tmpNormal[0] = normalIndex[0];
tmpNormal[1] = normalIndex[1];
tmpNormal[2] = normalIndex[2];

RotateVector(m, tmpNormal, tmpVector);
tmpShade = DotProduct(tmpVector, lightDirection);

if(tmpShade < 0.0f)
tmpShade = 0.0f;

gl.glVertex3f(cIndex[0], cIndex[1], cIndex[2]);

gl.glDisable (GL.GL_TEXTURE_1D);

/****Cartoon Border code****/

Same as code in my previous post ^^

Again I really appreciate if anyone can help spot my problem, sorry for being such a noob!


Share this post

Link to post
Share on other sites
Just a bump in the hope someone can spot my problem, I haven't had any luck yet. Any ideas are really appreciated :)

Edit: Well I've fixed it. Seems to only work if i enable culling just for when im drawing the borders. I also have a draw in a counter clockwise fashion. Buy hey it works and looks real good :)

[Edited by - jimdaddy on March 17, 2006 8:35:05 PM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!