HomeNewsFeaturesLicensingDownloadsScreenshotsFAQRoadmap Contact Us
Search:
8 Online

Community

Discussion Topics Recent Postings User Contributions General Articles Example Documentation Credits

Licensed Developer

Programmer's Manual Artists Manual Tutorials and Articles

Programming: Game Code

Game Code Overview Server Side Game Code Client Side Game Code

Programming: System

Alphabetical Function List Renderer File System Collision & Ray Casting Low Level Audio Game Audio The Console Console Variable List Multiplayer Localisation Maths Library Memory Manager Model File Formats Texture Formats

Art: Overviews

Specifications Shaders Particle Systems Lens Flares Cipher console Cipher file types Tutorials Reference

Art: Tools

Shader Designer Particle Designer 3dsmax tools Model Conversion Font Generator

Cipher Engine
Game Development Search Engine
GameDev.net
You are not signed in - [sign in] [register]

Toon Shading example

Submitted by: rikh
Date Submitted: 2003-11-09 18:12:03
Downloads: textures.zip

Shader Script

textures/toonshade
{
    {
        tex map textures/colourgrad
        rgbsrc white
        texsrc toon
        tex clamp
        tex no_mipmap
    }
}


textures/toonink
{
    vertexmod pulse square 0.010 0.000 0.000 1.000
    cull front
    sort 9.000
    {
        tex map white
        rgbsrc constant 0.000 0.000 0.000
    }
}



Screenshot

Toon Shading example

Description

This effect makes use of 2 shaders to create a cartoon rendering effect. The first shader deals with the coloured interior of the model and the second shader deals with the black inking for the outline of the model.

The interior is rendered using the toon texture coordinate generation function and a special texture. If you want to be able to colour different parts of your model differently, you might want to consider changing the texture to contain a greyscale gradient and set the model vertex colours to what you want (you should also change the rgbsrc command to one that selects the vertex colours in the model). The clamp command is needed to stop the dark side of the model appearing to get brighter again.

The outline is created using a second shader (so you would need to draw the model twice, using the shader override feature in cipher). The first thing it does is to expand the model outwards a little. This will make it slightly bigger than the original model. If you drew this bigger version of the model first, and then draw the slightly smaller coloured version of the model over the top of it, you will be left with a thin outline. You may need to adjust the amount that the model is expanded by to something appropriate to your coordinate system.
Because of the Z buffer, there is no need to draw this version first and then draw the coloured version of the top though. In this example, we only draw the triangles that are facing away from the camera (ie, those faces around the back of the model). The sort command has been added to ensure it is rendered after the main model, but this is only to increase performance (most of this outline model won't be visible in the final image, so we can take advantage of the z buffer here to speed things up a bit).
Finally we get to the bit that controls how to draw the model. This is very simple. We just draw the entire thing in solid black.

When the two effects are combined, the result in a toon shaded model, with a black outline.

Note: It is also possible to create an outline using a second pass on the first shader using a different method, though I don't feel it looks as good.

[Recent Contributions] [Recent Shaders]

User Contributed Comments

the_cX 15th December, 2003 09:48
i love it


CrossFire 26th September, 2004 13:09
Awsome, that would look cool in an "anime" type game : )


tobyallen 18th November, 2004 02:59
I was playing around with this.. shoulnd't there be an environment map for the colour, so it always faces the camera despite the model rotating.. because then it's not true cel shading..

textures/celshading/colourgrad
{
{
tex map textures/celshading/colourgrad
rgbsrc white
texsrc toon
tex clamp
tex no_mipmap
texsrc envmap
}
}


tobyallen 18th November, 2004 03:05
Actually looking at models in animation, it does produce some interesting results with the environment map.. not sure this is the right way really.

Comments?
Toby.




Register and Sign In to discuss this article