Skip to main content
GameDev.net gamedev.net
🔒 Locked

Cel shading [SOLVED]

Started by sjf Jan 20, 2006 at 10:52 PM 4 replies 1.2k views
Original Post
sjf
sjf
I’ve almost implemented cel shading using a vertex program. And while I am pleased with the results, when I applied a model outline, I lost all the nice cel shaded lighting. To better explain my issue, see the rendering and code snippet below: The knight closest to the center has nice cel shading and lighting. The knight near the bottom edge has the outline applied and has lost all nice cel shading.

/* Stencil one set of the checked tiles. */
...
/* Render the Reflections. */
...
/* Stencil all tiles. */
...
/* Render the checked floor. */
...
/* Render the shadows. */
...
...
/* Use the inverse model matrix to convert light position into model space. */
   vector_ model_space_light_position = inverse_model_matrix * light_position;

/* Render the chess pieces. */
   glBindTexture(GL_TEXTURE_1D, cel_brightness);
   glEnable(GL_TEXTURE_1D);
   glColor4f(0.75f, 0.95f, 1.0f, 1.0f);
   vp->Bind();
   vp->Enable();
   vp->EnvParameter(0, model_space_light_position[x], model_space_light_position[y], model_space_light_position[z], model_space_light_position[w]);
   RenderKnight(knight_x1, knight_z1, false);
   RenderKnight(knight_x2, knight_z2, true);
   glDisable(GL_TEXTURE_1D);
/* Outline the model. */
   glLineWidth(3.0f);
   glCullFace(GL_FRONT);
   glColor4f(0.0f, 0.0f, 0.0f, 0.0f);
   glPolygonMode(GL_BACK, GL_LINE);
   RenderKnight(knight_x1, knight_z1, false);
   glPolygonMode(GL_BACK, GL_FILL);
   glCullFace(GL_BACK);
   vp->Disable();
...


Any ideas? If you require more code or additional information to resolve the issue, just ask. Thanks in advance. [Edited by - sjf on January 21, 2006 4:27:34 PM]
sjf
sjf
Thanks, I think. But that did not help.
Dorvo
Dorvo
Only thing I can think of is that the lighting is thinking that it needs to apply the black outline in its shading process. Maybe try rendering the object first, then render the outline afterwards. You know, that multipass render technique. ;)

Oh! When you render the outline, disable lighting. That might help.
sjf
sjf
Thanks, that makes good sense. After a good night's sleep, I relised that I had one of my inverse_model_matrix's 180 degrees out of phase.

Here's the result:



Thanks to everyone who helped.
Dorvo
Dorvo
Glad I could be of some help. :)
Looks really nice. Good job.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.