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

cel shading lines

Started by Panzooka Oct 14, 2004 at 6:32 AM 11 replies 1.9k views
Original Post
Panzooka
Panzooka
ok i know the concept of cel shading and the lines around it, but the line doesnt look smooth when the model is low poly and line is thick. now i recently saw that they made counter strike models cel shaded look without alter the game engine. basicly, it just have a black outline on models. so i downloaded the models, milkshape it, and found out how its done. for example we create a cube in 3d. color it say in blue duplicate the cube, make it slightly bigger, and color it in black, reverse all faces for the black cube. know ingame, u cant see back of the faces, so u see throug the black cube. u will see the blue cube, and the other half of the black cube which is slightly bigger than the blue cube, and thus looks like a black outline. i think this method produces nice looking lines that are drawn by black polygons and easy to implement. this also allow much more controls over the lines, u can have different color lines for different model parts, (say u can have brown outlines for face, and black outlines for clothes) easiy to control the thickness, u can even have thiner lines for eyes/lips, and thicker lines for guns. the downside of this method is that it doubles the polycount for the model. but it shouldnt be because most back faces are ignored. drawing lines in classic cel shading method is slow too. so what u guys think? does this method will eventualy replace the method we currently use to draw lines?
Drazgal
Drazgal
The backface method's main problem is that it will only do the outer lines and leave any inner lines undefined.

As for different colours of lines you can do that in either method quite easily.
Panzooka
Panzooka
it does outline the inner lines, try it in your 3d software
M3d10n
M3d10n
Actually "this" method was the first method. That's exactly how Jet Set Radio (Jet Grind Radio in USA) - supposedly the first game to ever use cellshading - was done.

It is a good trick, but having the black outlines saved along the model have the drawback of creating twice the polygons to store and load (like anyone cares - most PC games are using whooping 3GB of HD space anyway). The major advantage is that you can store the outline colors with the model texture, and have the outline faces's UV point to a single point in the texture. That way you could draw the whole model with a single call, with a little of care.

You could also generate the outline mesh at runtime. That way you could change the thickness depending on the distance.
Cypher19
Cypher19
Medion: Wouldn't having a seperate vertex shader* be better, since you could skip having ANY textures and just use flat shaded colours?

*Output position would be the input position extended across the normal by some constant, output colour is some constant and output normal is the input normal. The benefits would be: no texture lookups or texture rasterization, only one model with no extra vertices, and the outline can have a flexible width (AND a flexible colour!). Plus, since it would have to be in a seperate render call, you can change the cull mode to remove forward facing ones (saving you one quick calc to reverse the normal).

Hmm...this thinking has me a bit interested in doing it as an experiment...
M3d10n
M3d10n
Hmm, nice ideas, really. Maybe it would also be possible to batch all models (since there'll be no textures, color and line width info could be stored at vertex-level anyway) and render them using a single call. The con is that vertex-shader-based skinning probably would work well with batching.
Panzooka
Panzooka
Quote:
Original post by Cypher19
Medion: Wouldn't having a seperate vertex shader* be better, since you could skip having ANY textures and just use flat shaded colours?

*Output position would be the input position extended across the normal by some constant, output colour is some constant and output normal is the input normal. The benefits would be: no texture lookups or texture rasterization, only one model with no extra vertices, and the outline can have a flexible width (AND a flexible colour!). Plus, since it would have to be in a seperate render call, you can change the cull mode to remove forward facing ones (saving you one quick calc to reverse the normal).

Hmm...this thinking has me a bit interested in doing it as an experiment...


very nice, cypher, rated u

also, if its a single call, how to disable lightning and other effect on that black model. so i will go with seperate call, that should speeds the rendering process up
JohnBolton
JohnBolton
One problem is that it only works for convex models. A doughnut will not render correctly (because the hole gets bigger, not smaller), for example.

It is not easy to draw outlines that look good in every case. Look up "non-photorealistic rendering" to find out about the many different techniques for drawing outlines. The best I've come across is Philippe Decaudin's technique: Cartoon-Looking Rendering of 3D-Scenes.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Panzooka
Panzooka
concave model works too mate (just need few tweaks when enlarging the original model)

i like how the terrain looks in Philippe Decaudin's technique, but it also draws "front lines"

the method i used is draw a line on edge where 2 faces meet but one of the face is facing away from view.

edit: the enlarging method that works is:
duplacate the model, select all faces, and move alone normals
Cypher19
Cypher19
Quote:
how to disable lightning and other effect on that black model.


Because the cel-outline is being done with a seperate render call, and therefore a seperate effect, things like lighting and other effects will be defined by you. I found out (the hard way...) that if you have an effect going on, regular fixed function stuff such as vertex lighting does not occur, and you have to basically reinvent the wheel (thankfully it's not too hard to do)
superpig
superpig
Quote:
Original post by JohnBolton
One problem is that it only works for convex models. A doughnut will not render correctly (because the hole gets bigger, not smaller), for example.
Surely you can just move vertices along their normals, instead of simply 'enlarging' the model? Though that does require fully welded meshes, I guess.
Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse
OrangyTang
OrangyTang
So far I've seen three basic methods for outlines:

- Draw backfaces in wireframe, with outline colour. Dead easy but does weird popping of edges as the model rotates. Not really a good idea.

- Enlarge the model along the normals, then draw backfaces with outline colour. Simple (and fast) in a vertex shader. Works with pretty much any geometry, and doesn't have any weird artifacts as it moves. Dead easy to control the outline size as a constant to the vertex shader as well.

- Image space methods that involve doing edge detection. Great quality, but needs lots of fillrate and fancy shaders.

Second one is probably your best bet (as already suggested). If you want custom outline colours I'd create a second texture for it (yet use the same uvs as the original skin, then you don't need any extra vertex data). If you want to get really fancy you could have a per-vertex attribute that would specify the outline size and let the vertex shader use that while scaling the vertices.

I'm inclined to say that any methods that involve CPU work (like running silluette detection) aren't a good idea since you can just use the same vertex data and a vertex shader. Of course you might already be calculating silluette data (Jet Set Radio uses shadow volumes for example, which gives great clean cut toon style lighting).
Panzooka
Panzooka
wirefram is ugly, because i dont want to draw line in front, and u cant control that in wirefram mode.

i guess the polygon backface method is the best.

Topic Locked

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

Sign in to reply to this topic.