1 of 37

CelShading

By:Lifeng Wang, Zhuowen Fang, Zirui Huang, Zhengyu Weng

2 of 37

What is Cel-Shading?

Non-Photorealistic Rendering(NPR) encompasses any rendering technique that does not strive for photorealism. Instead, it aims to create visually expressive or stylistic renders that evoke artistic styles such as painting, drawing, or cartooning.

Non-Photorealistic Rendering

Cel-shading is a subset of Non-Photorealistic Rendering (NPR), also known as toon shading or cell shading, is a rendering technique that makes 3D graphics appear as if they are 2D cartoons.

Cel-Shading

Our Final Project

Understanding the concept of Cel-Shading. Analyse the algorithms used to process Cel-shading, simulate these algorithms to the Utah Teapot and try to create a cartoon-like effect.

Searching for more advanced algorithms, using image processing software to apply a Comicize process to a specific 3D humanoid model.

3 of 37

Example of Cel-Shading

Anime

Games

Legend of Zelda:

Tears of Kingdom

Neo:

The World Ends with you

Genshin Impact

Dragon Ball Super:

Super Hero

The First Slam Dunk

4 of 37

Features of Cel-Shading

Color Quantization

Edge Enhancement

Customized lighting

The process of reducing the number of colors used in the image to create a more simplified and stylized appearance

  1. Reduce color palette.
  2. High contrast and saturation

Accentuate the outlines or borders of objects.

  1. Depth Map, Normal Map
  2. BackFacing

Crucial for achieving its distinctive, stylized look that resembles hand-drawn art or cartoons.

  1. Stepped diffuse light
  2. Omitted, simplified, or specialized Highlight
  3. Specialized shadow

Original Model

Cel

Shading

5 of 37

Modification of Utah Teapot

Color/Lighting Model Quantization

Output of HW4

To achieve Cel shading, we need to simplify the lighting model to reduce the number of colors in the image. And use Edge detection algorithm to outline the silhouette of the model.

6 of 37

Modification of Utah Teapot

Color/Lighting Model Quantization

Output of HW4

  1. Simplify specular reflection: Remove the specular highlight

(Ks ∑[Ie (RᐧE)^s]) + (Kd ∑[Ie (NᐧL)]) + (Ka Ia)

→ (Kd∑ [Ie (NᐧL)]) + (Ka Ia)

2. Color quantization: Establish thresholds to different terms to get several lighting levels.

Method 1: Set threshold for light Intensity

if (lightIntensity > Threshold) {

lightIntensity = Bright;�} else {

lightIntensity = Dim;

}

7 of 37

Modification of Utah Teapot

Color/Lighting Model Quantization

Output of HW4

  • Simplify specular reflection: Remove the specular highlight

(Ks [Ie (RᐧE)^s]) + (Kd [Ie (NᐧL)]) + (Ka Ia)

→ (Kd [Ie (NᐧL)]) + (Ka Ia)

2. Color quantization: Establish thresholds for several lighting levels.

Method 2: Set threshold for NdotL

if (NdotL> Threshold) {

NdotL = BrightLevel;�} else {

NdotL = DimLevel;

}

8 of 37

Code Segment

9 of 37

Modification of Utah Teapot

Edge Enhancement

Output of 1st Implemenetation

Post Processing: Traverse the image after the model has been rendered to image space.

Simple Implementation: by comparing the color with surrounding pixels.

  1. Set up a EdgeThreshold
  2. Get the color of surrounding pixels, calculate the average
  3. If color difference greater than threshold, make the pixel black.

10 of 37

Modification of Utah Teapot

Edge Enhancement

Simple Implementation: by comparing the color with surrounding pixels.

  • Set up a EdgeThreshold
  • Get the color of surrounding pixels, calculate the average
  • If color difference greater than threshold, make the pixel black.
  • Check if the pixel is a boundary. (Depth Detection)

Output after

Depth detection

Output before

Depth detection

11 of 37

Digging into more advanced Model and Algorithms

12 of 37

Modification of Lighting Model

ShaderGraph

Key Properties:

  • Smoothness: Sharpness of highlights
  • RampTex: Color transitions for lighting
  • SpecColor: Hue of highlights
  • Color Tex & SpecMap: Base color and reflection details

Shader Graph Flow

  • Texture sampling and light calculation
  • Ramp texture for stylized shadows
  • Specular highlights for depth
  • Final color output for Cel Shading effect

Visual Impact

  • Achieves a distinctive, comic book-style rendering.

13 of 37

Modification of Lighting Model

ShaderGraph

Key Properties:

  • Smoothness: Sharpness of highlights
  • RampTex: Color transitions for lighting
  • SpecColor: Hue of highlights
  • Color Tex & SpecMap: Base color and reflection details

Shader Graph Flow

  • Texture sampling and light calculation
  • Ramp texture for stylized shadows
  • Specular highlights for depth
  • Final color output for Cel Shading effect

Visual Impact

  • Achieves a distinctive, comic book-style rendering.

14 of 37

Edge Enhancement

BackFacing

Implementation: involves two rendering passes: the first pass renders the character, and the second pass renders the outline. During the outline rendering, the vertices are displaced in the direction of their normals within the vertex shader. This displacement enlarges the model's silhouette, which is then rendered to create the outline.

Problem: When Camera Zoom in, the Edge become wider

Solution: Use normal from NDC instead of Model Space

15 of 37

Shading

How to make 3D model look cartoonish

  1. Reduce the number of color levels

  • Control the hand-drawn light and dark areas

  • Separate cool tones and warm tones

16 of 37

Shading

Reduce the number of color levels

  • Express depth by reducing the number of color levels

  • Simplify the boundary between light and shadow

17 of 37

Shading

Separate cool tones and warm tones

18 of 37

Shading

Control the hand-drawn light and dark areas

  • Half-Lambert
    • Avoid complete darkness in unlit areas
    • I = max(dot(n, l) * 0.5 + 0.5, 0)

  • Shadow range (Threshold)

19 of 37

Shading

Bicolor Implementation

  • Based on the art theory, we first implemented a simple shading with two color levels
    • Create a clear distinction between light and shadow
    • Separate cool tones and warm tones
      • Use warm tone for light face, cool tone for shadow face

20 of 37

Shading

  • Based on the art theory, we first implemented a simple shading with two color levels
    • Create a clear distinction between light and shadow

    • Separate cool tones and warm tones

Bicolor Implementation

21 of 37

Adding more details

Lightmap

  • Lightmap is the texture map that stores lighting information

  • Each color channel (R, G, B) can be used to store different information

22 of 37

RGB Channels

R channel: Control which parts have highlight

G channel: Control the intensity of shadow

B channel: Control the intensity of highlight

23 of 37

Shadow map

G channel

  • G channel of light map is the shadow map
    • useful for expressing rich shadow details on low polygon models

  • The shadow map typically uses three grayscale values
    • base color
    • soft shadow
    • pitch-black shadow

24 of 37

Shadows

Base color: The base color that fills the entire layer

Soft shadows: represents shadows of clothing folds and simulates details on flat models

Pitch-black shadows: commonly used in areas like groin, neck where it meets the head

25 of 37

Implementation

Based on the theory, the main idea is to implement two types of shadows

  1. Shallow Shadow
    1. change with real-time lighting
    2. controlled by _FirstShadowMulColor
  2. Dark Shadow
    • not affected by real-time lighting
    • darker than shallow shadow
    • controlled by _SecondShadowMulColor

Algorithm

  • Shadow weight
    • control the intensity of shadow

  • Shadow factor
    • control if the shadow exists
    • affected by shadow range

Shadow factors to control under current lighting,

and output corresponding color

26 of 37

Lightmap Result

27 of 37

Lightmap Result

28 of 37

Face Shadow

  • Right face shadow does not change with the real-time lighting

Although the face already had anime-like face effect after lightmaps are applied, there are still several issues remaining

Light source is on the right side of the model, but the right face still has shadow

  • In some certain angles, the face shadow appears to be very weird and ugly

29 of 37

Face Lightmap

  • Threshold
    • use threshold to control face lightmap output
    • step function
      • >= threshold, return 1
      • < threshold, return 0
    • greater threshold, more shadow

  • Need a way to control threshold

30 of 37

Face Lightmap

Control threshold through dot product between vectors

  • Front direction of the model

  • Left direction of the model

  • Light direction

Left

Front

Back

Light

31 of 37

Face Lightmap

Dot product between front direction and the light direction controls which part of lightmap to be displayed

  • Control threshold by light direction
    • Light direction is in front of the model,

threshold = 0 (fully lit), dot product = 1

    • Light direction is behind the model,

threshold = 1 (completely dark), dot product = 0

  • Map from dot product to threshold
    • range of dot product is [1, -1]
    • range of threshold [0, 1]
    • - (dotProduct + 1.0) / 2.0

Left

Front

Back

Light

32 of 37

Face Lightmap

Face lightmap only contains the shadow information of 0° - 90°

Use dot product between left direction and the light direction to check light position

  • When angle between left direction and light < 90°,

dot product > 0, light source is on the left

  • Otherwise, light source is on the right
    • flip the lightmap

Left

Front

Back

Light

Light

33 of 37

Face Lightmap Demo

34 of 37

Final Adjustment

  • Color Edge
    • vertex color
    • texture color
  • Shadow Color
  • Shadow Range
    • Shallow shadow range
    • Dark shadow range
  • Face Shadow Map Function

35 of 37

Demonstration

36 of 37

37 of 37

Reference

Hertzmann, Aaron. "Introduction to 3D Non-Photorealistic Rendering: Silhouettes and Outlines." https://mrl.cs.nyu.edu/publications/npr-course1999/hertzmann-intro3d.pdf

Tone-based Shading of Matte Objects (northwestern.edu)

The Evolution of Cel-Shading: A Detailed Exploration of the History, Techniques and Applications, https://sam-hedges.github.io/2023/01/31/cel-shading.html

Re:Zero − Starting Cel Shading, https://zhuanlan.zhihu.com/p/109101851

Analysis of Genshin shader, https://zhuanlan.zhihu.com/p/435005339