cel shading help

Started by
3 comments, last by jimdaddy 18 years, 1 month ago
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
            gl.glColor3fv(outlineColor);                    
    
            gl.glBegin(GL.GL_TRIANGLES);
            
              for (int i = 0; i < cIndex.length; i++)
              {
                gl.glVertex3f(cIndex[0], cIndex[1], cIndex[2]);
              }            
            
        gl.glEnd();
                    
            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
            gl.glDisable(GL.GL_BLEND); 
Anyone have any ideas how i can fix this ? I really appreciate any help :) Cheers,
Advertisement
Well, your code definitely looks correct... Is it possible you forgot the glEnable(GL_CULL_FACE); ?
-Tom BlindGame Design and Developmenthttp://tomblind.squad-seven.comtomblind@squad-seven.com
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?
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 Filteringgl.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);gl.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);// Uploadgl.glTexImage1D(GL.GL_TEXTURE_1D, 0, GL.GL_RGB, 32, 0, GL.GL_RGB, GL.GL_FLOAT, shaderData);	    // Normalize the direction of our lightNormalize(lightDirection);			      	      // Use The Good Calculations (Enables Anti-Aliasing)gl.glHint(GL.GL_LINE_SMOOTH_HINT,GL.GL_NICEST);           gl.glEnable(GL.GL_LINE_SMOOTH);	    // Enable OpenGL Face Cullinggl.glEnable (GL.GL_CULL_FACE);							// Disable OpenGL Lightinggl.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 Matrixgl.glGetFloatv(GL.GL_MODELVIEW_MATRIX, m); 		gl.glBegin(GL.GL_TRIANGLES);		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);  Normalize(tmpVector);  tmpShade = DotProduct(tmpVector, lightDirection);		          if(tmpShade < 0.0f)    tmpShade = 0.0f; 					      			      gl.glTexCoord1f(tmpShade);									  gl.glVertex3f(cIndex[0], cIndex[1], cIndex[2]);	}					gl.glEnd();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!

Cheers.
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]

This topic is closed to new replies.

Advertisement