Sign in to follow this  

cel shading help

Recommended Posts

jimdaddy    122
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: <- normal cel shading <- 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[i][0], cIndex[i][1], cIndex[i][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
Bounds    150
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
jimdaddy    122
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: <- Here it is zoomed with culling disabled <- 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. ( 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[i][0];
tmpNormal[1] = normalIndex[i][1];
tmpNormal[2] = normalIndex[i][2];

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

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

gl.glVertex3f(cIndex[i][0], cIndex[i][1], cIndex[i][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
jimdaddy    122
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this