
Why we built it
This was our final project for CS 184, Berkeley’s computer graphics course, where each group picked any graphics topic to explore. Most of the course is about physically realistic rendering: light bouncing around a scene the way it does in the real world. We went the other way, writing non-photorealistic shaders that make 3D scenes look hand-drawn, like a cartoon, a comic book or a newspaper print.
We were inspired by the cel shading of The Legend of Zelda: Breath of the Wild and the comic-book look of Spider-Man: Into the Spider-Verse. Stylized shading isn’t just about looks, either. In games, outlines and glow can make important objects easier to see.
We were a team of four. My parts were the multi-step toon shader, hull outlining (including a two-tone outline that stays visible on any background), the halftone-with-outline shader and the comic-book shader on the Bugatti, plus the monkey lineup test scene and both of our project videos.
How it works
Every shader is written in Cg/HLSL and runs in Unity, mostly as fragment shaders that decide the color of each pixel. For each one, we exposed the important settings as sliders and color pickers in Unity’s material panel, so an artist could tune the look without touching the code.
The work falls into three groups: strokes (outlines), fills (how surfaces are colored in) and halftone (dot-pattern printing).
Strokes
Objects don’t have outlines in real life, but they almost always do in drawings. We tried three ways to draw them.
Fresnel shading adds a glow wherever a surface turns away from the camera, using the angle between the surface’s normal and the view direction. Thresholding that glow gives a hard outline, but its width varies a lot with the shape of the object.
Hull outlining gives much more even strokes. The trick is to draw the object twice:
The one thing hulls miss is sharp creases inside an object, like the fold of a door panel. For those we tried a derivative stroke, which draws a line wherever the surface normal changes quickly between neighboring pixels. It found the creases, but the lines came out jagged and picked up the polygons of the mesh, so we left it out of the final looks.
Fills
Toon shading, or cel shading, takes the smooth gradient of real lighting and snaps it to a few flat colors, the way an animator would paint it. The simplest version starts from ordinary diffuse lighting and splits it into two colors at a threshold, including Unity’s shadows.
The hard part is the edge between colors. A hard cut is jagged, and a soft blend of fixed width looks blurry wherever the lighting changes slowly. The fix was to size the blend with fwidth, a GPU built-in that measures how fast a value changes from one pixel to the next. That keeps every color edge about one pixel wide, crisp but smooth.
My multi-step toon shader builds on this with several bands of color and a specular highlight. In real lighting, a highlight is added on top of the diffuse color. In a cel-shaded drawing, the highlight is painted over it instead, so past its threshold the shader blends from the diffuse bands straight into the highlight color.
With a moving light, like the sun crossing the sky, the highlights slide across the bands of color:
Halftone
With only a couple of colors, flat thresholds lose the shape of an object. Print solved this long ago: newspapers and comic books use halftone, patterns of tiny dots that read as smooth shading from a distance, using only ink and paper.
Our halftone shader turns each pixel into a single brightness value, adds a pattern of offsets (a mix of dot patterns and noise), and thresholds the result, using the same fwidth trick for clean edges. The pattern’s scale, rotation and mix are all adjustable, including an “n-axis eggbox” dot pattern of our own invention.
Halftone makes object edges hard to see, so I added a two-tone hull outline: the outline turns white where the object behind it is dark, and black where it’s light, so it always stands out. Combined with thresholded lighting, it gave us a black-and-white comic-book style:
Bonus shaders
We also made two extras. A dissolve effect jitters where each pixel samples the image, so the whole frame looks like it’s breaking apart; it’s the image at the top of this page. And a fragment-only shader draws an entire scene with no mesh at all: the shapes are defined by a math function, found by ray marching, and shaded with three lights.
What I learned
Most of the course came with starter code and step-by-step instructions. This project didn’t, which made it the best way to really understand lighting, rasterization and aliasing: we had to take ideas from a blank page to a working look on our own. I especially enjoyed the mix of learning new tools (Unity and Cg/HLSL), digging into the algorithms, and the creative side of inventing looks like the comic-book Bugatti.
Next projectAI/ML Bootcamp →