Sunbathing Giraffe

Custom adjustable toon shader

Overview

Brown University’s CSCI 1230 Introduction to Computer Graphics is the longest running graphics course in the world. It covers fundamental concepts in both 2D and 3D computer graphics such as scan conversion, geometric transformations, and 3D rendering. All projects use C++ and the graphics library OpenGL and they incrementally build up to a geometric modeler and a recursive ray tracer. Shader programming in GPU is also introduced.

For this course’s final project, I teamed up with Xiangyu Li and Carrie Zhuang to explore non-photorealistic rendering (NPR). We decided to render a scene in which a cartoon giraffe is lying on a swimming ring floating on water. My role in this project is to write a custom toon shader in GLSL (OpenGL shading language), while Xiangyu worked on shadow mapping and Carrie on the water shader. You can find our code and more detailed explanations on how I implemented the toon shader below.


Software Engineer
Nov - Dec 2019
Jiaju Ma, Xiangyu Li, Carrie Zhuang
C++, GLSL, Qt

Toon Shading

Stylized Diffuse Illumination

The main goal of a toon shader is to mimic the style of comic books or hand-drawn cartoons. One common approach is to flatten the diffuse colors to show sharp and distinct transitions. In my implementation, I used the Blinn-Phong lighting model as the base and modified the diffuse calculation to stratify the color gradients. I added a level parameter to allow people to control the layering effect.

123_toon.png

Outlines

We often see in sketches or ink drawings the use of outlines to delineate characters and objects. A hack to achieve this effect for toon shading is to play around with face culling. In my shader, I copied the object mesh and made it a little bigger by extruding it along its normals. I then changed the face culling mode to GL_FRONT to remove the front-faces. The exposed back-faces are rendered with the outline color (in this case black) and combined with the original mesh as the last step. The trick here is to use the slightly-enlarged back-faces so that only their edges will remain visible when the original front-faces are added back, similar to how the ring of light is created during a solar eclipse.

123_outline.png