In anime-style rendering, facial shadows are often a unique and crucial element. However, in the default rendering of game engines, shadows are computed based on the model's normals and the light source, which can lead to significant differences between the rendered shadows and the desired anime-style shadows for facial features.

Abandoning the default shadow calculations and transitioning to using fixed shadow textures can greatly enhance the control and customization of facial shadows in the anime-style rendering.

Shadowmap

Shadow map is a gradient texture generated through SDF algorithm using N fixed shadow shape textures. It represents the shading transition from frontal light to back light, capturing the shadow behavior. The creation process for this texture can be referred to here: https://zhuanlan.zhihu.com/p/356185096

Fixed shadow shapes

Fixed shadow shapes

Shadow map generated using SDF algorithm

Shadow map generated using SDF algorithm

Relationship with Face UVs

Shadow maps are created based on the UV mapping of the face, essentially rendering shadow information onto the face model using its UV coordinates.

You can start by trying to apply the SDF texture from the asset package onto your own model to see if the UVs match. If they don't align properly, consider trying the following two approaches:

  1. Adjust the SDF shadow map to match the UV mapping of the face model.
  2. Modify the UV mapping of the face model to align with the SDF shadow map.

Untitled

Overlay the face UV texture with the SDF shadow map

Overlay the face UV texture with the SDF shadow map

Handling of asymmetric UVs on the face (New feature in Version 1.3)

For some models, the UVs on the face may not be centered or symmetrical. In such cases, applying the SDF texture directly may result in anomalies. Here's a step-by-step adjustment process:

  1. Use Photoshop or other software to overlay the SDF shadow map onto the face UV map.

    Untitled

  2. Add a black background layer and re-export the SDF texture. Upon import, ensure that the Compression Setting is changed to Grayscale, and uncheck SRGB.

    Untitled

  3. Assign the SDF texture to the face material. When rotating the light source, you may notice that the shadows become entirely black at specific angles. Adjust the "InvertSDFOffsetX" parameter in the face material until the facial shadows appear normal.

    https://youtu.be/czLeouUW3dk

Since the SDF provides single-sided light source information in shadows, handling light from the opposite direction will flip the SDF horizontally. Asymmetric UVs can lead to incorrect positioning after the flip. The value of "InvertSDFOffsetX" helps offset the SDF sampling flip to align with the original face UV position.

Runtime updating of SDF direction (New feature in version 1.3f2)