Toon rendering

Ideas, enhancements, feature requests and development related discussion.

Toon rendering

Postby sascha » Fri Jul 30, 2010 3:37 pm

Just read an OpenGL tutorial, and it mentioned a surprisingly simple way to do toon shading:
Every edge is (by definition) adjacent to two faces. If one of these faces faces towards the camera and the other one away, the edge is part of the silhouette.
It's so simple you don't even need a shader, and it should work well in real time. I think it should even be possible to create 2D vector objects directly from 3D models with this technique.
sascha
Site Admin
 
Posts: 2792
Joined: Thu May 20, 2004 9:16 am
Location: Austria

Re: Toon rendering

Postby dcuny » Sat Jul 31, 2010 4:45 am

Yes, the only problem with it is that it draws attention to the edges, which tend to be flat. But with high enough tessellation, it's not an issue.
dcuny
 
Posts: 2902
Joined: Fri May 21, 2004 6:07 am

Re: Toon rendering

Postby sascha » Sat Jul 31, 2010 8:11 am

You're right. I thought about dicing it to almost pixel-level (like REYES does).
On the other hand, you'll get a vector representation of the silhouette. Theoretically you could flatten it (i.e. treat it as 2D) and then apply smoothing to it (by subdivision or by treating it as a spline). I guess this would work pretty well for illustrations, but maybe not in animations.
sascha
Site Admin
 
Posts: 2792
Joined: Thu May 20, 2004 9:16 am
Location: Austria

Re: Toon rendering

Postby John VanSickle » Sat Jul 31, 2010 11:15 am

sascha wrote:You're right. I thought about dicing it to almost pixel-level (like REYES does).
On the other hand, you'll get a vector representation of the silhouette. Theoretically you could flatten it (i.e. treat it as 2D) and then apply smoothing to it (by subdivision or by treating it as a spline). I guess this would work pretty well for illustrations, but maybe not in animations.

Except for orthographic views, every rendering involves a non-linear projection. Any attempt to get rid of one of the three dimensions will result in some distortion. For many scenes this distortion will be small, but there will always be some.

To get the right silhouette vector, you'll need to find those points where the normal of the object is perpendicular to the vector from the camera to the same point, and then take the cross-product of that normal and the camera vector. This will give a vector that traces along that portion of the object's silhouette.

The good news is that faces which face entirely towards the camera, or entirely away from the camera, are much easier to process. Of those faces which bend in both directions, many of the child faces that are produced in by subdivision will face entirely one way, and can be sent down the quicker pipeline.
John VanSickle
 
Posts: 189
Joined: Sat Feb 16, 2008 2:17 am

Re: Toon rendering

Postby sascha » Thu Aug 05, 2010 8:46 pm

You're right, and I think this is how most RenderMan toon-shaders work. The approach with the edges just looks so beautifully simple that I'll have to try it out :wink:
sascha
Site Admin
 
Posts: 2792
Joined: Thu May 20, 2004 9:16 am
Location: Austria

Re: Toon rendering

Postby John VanSickle » Tue Aug 10, 2010 2:55 pm

If you subdivide (or dice) down to the pixel/sub-pixel level, then any micropolygon that has both front and back-facing corners can simply be colored as a border.

If this does not produce a strong enough border, then perhaps you should simply shade based on the dot product of the micropolygon's normal with the camera vector (and assume that the micro-p is flat). To get good results, you will need to adjust the tolerance for the curvature of the surface at the micropolygon, or else shallow curves (representing a larger curve radius) will have a broader border than the tighter curves.

Sharp edges (as usual) present some difficulty, specifically those edges which are only drawn when they are part of the silhouette. You will need to check the geometry on both sides of the edge, and if the geometry faces in opposite directions, that edge will need to be drawn. You may find it easier to subdivide/dice these edges to a certain point, and then treat the resulting micro-edges as the diagonals of micro-polygons that face the camera.

Also for cartoon rendering, you may still want a small amount of diffuse shading. Fully light those micropolygons that face the light source, and light those facing away at .50 to .75.

I also recommend assigning a color component outside the (0,1) range for border samples, so that averaging with nearby non-border samples will not drown out the border. If all of your borders will be black, then assigning a negative number with high absolute value will, after clamping the weighted sum of the samples, yield a dark pixel (and a black one in most cases). Assigning the appropriate high positive values will result in white borders, and a mixture of high-positive and high-negative component values can be used to make red, green, blue, yellow, cyan, and magenta borders.
John VanSickle
 
Posts: 189
Joined: Sat Feb 16, 2008 2:17 am


Return to Development

Who is online

Users browsing this forum: No registered users and 2 guests

cron