Example study: HoYoverse toon (hoyo_toon)
How the hoyo_toon pack works for official Genshin Impact, Honkai: Star Rail and Zenless Zone Zero models, including its SDF face shadow technique and real HLSL code.
Introducing the hoyo_toon pack
hoyo_toon is the official educational surface shader MMDX Effect bundled with MMDX12. It provides anime cel
shading tuned for the official MMD models of Genshin Impact, Honkai: Star Rail and Zenless Zone Zero. The pack ships
pt_surface.hlsl alongside surface.hlsl, so it keeps the same look in path tracing and offline GI
(PT / GI).
It covers all three core techniques an MMDX Effects developer should know:
- Wiring user-adjustable sliders through
PackParam - Branching per body part based on
s.materialClass(face, eyes, skin, hair, clothes) - Head-bone relative lighting using
headPos,headRightandheadForward
Why not normal-based shading?
A typical 3D renderer computes shading from the surface normal and the light angle ($N \cdot L$). Applying that to a carefully hand-drawn 2D anime model causes problems:
- Dirty triangular shadows under the nose and around the eyes
- The face warping like a lumpy sculpture because of slight cheek curvature
- Ambient occlusion (AO) leaving grubby blotches on the face
The original games use 2D SDF (signed distance field) textures painted by artists so the shadow sweeps cleanly across the face as the head turns. But the officially distributed PMX models do not include the game’s dedicated SDF textures.
hoyo_toon solves this with a geometric SDF stand-in built from the head bone’s rotation frame.
Core technique: head-bone relative face shadow (FaceLight)
The light vector is projected onto the head bone’s horizontal plane to get the light’s azimuth (theta), and the
shadow boundary is swept smoothly across the face’s width (side):
float FaceLight(PackSurface s) {
if (!s.hasHead) return 1.0;
// Project the light onto the head bone's right (+X) and forward (-Z)
float lx = dot(s.L, s.headRight);
float lz = dot(s.L, s.headForward);
float theta = atan2(abs(lx), lz); // 0 (front) .. pi (back)
// Shadow boundary position for the light angle
float boundary = lerp(-1.15, 1.15, theta / 3.14159265);
// How far the pixel is from the face centre, left to right (-1 .. 1)
float side = dot(s.worldPos - s.headPos, s.headRight) / (P_FACE_WIDTH * s.headScale);
side = clamp(side, -1.0, 1.0) * (lx >= 0.0 ? 1.0 : -1.0);
return smoothstep(boundary - P_FACE_SOFTNESS, boundary + P_FACE_SOFTNESS, side);
}
The pixel normal plays no part in this calculation. Lit from the front, the whole face brightens cleanly; lit from the side, exactly half is covered; lit from behind, everything darkens naturally.
Per-part material branching
Inside PackShade in surface.hlsl, the lighting method branches on s.materialClass:
PackResult r;
r.alpha = s.alpha;
r.reflectivity = 0.0;
r.noAo = false;
float term; // 0: shadow .. 1: lit
float flatFill; // 1: the light ignores the normal and fills flat
float warmth = 0.0;
if (s.materialClass == PACK_FACE || s.materialClass == PACK_EYE) {
term = FaceLight(s) * lerp(1.0, s.shadow, P_FACE_CAST);
flatFill = 1.0;
warmth = 0.15;
r.noAo = true; // important: turn off SSAO/RTAO to keep the face clean
if (s.materialClass == PACK_EYE) {
term = lerp(term, 1.0, 0.6); // keep the pupils readable even in shadow
}
} else {
// Body and clothes: a two-step half-Lambert ramp
float halfLambert = dot(s.N, s.L) * 0.5 + 0.5;
float soft = P_RAMP_SOFTNESS * (s.materialClass == PACK_SKIN ? 2.0 : 1.0);
term = smoothstep(P_RAMP_THRESHOLD - soft, P_RAMP_THRESHOLD + soft, halfLambert) * s.shadow;
flatFill = 0.0;
if (s.materialClass == PACK_SKIN) warmth = 0.2;
}
MMD toon textures and shadow tinting
Treating shadow colour as plain black looks muddy. hoyo_toon takes the dark end of the model’s original MMD toon
texture (PackSampleToon(1.0)) and blends in a warm rosy tint (P_SHADOW_WARMTH) to make the shadows lively:
float3 ShadowColour(float3 lit, float extraWarmth) {
float3 toonDark = PackSampleToon(1.0);
float3 warm = lerp(float3(1, 1, 1), float3(1.0, 0.82, 0.84), saturate(P_SHADOW_WARMTH + extraWarmth));
return lit * lerp(float3(1, 1, 1), toonDark * warm, P_SHADOW_DARKNESS);
}
Stepped highlights and rim light
- Hair highlight (angel ring): the smooth specular gradient is stepped with
smoothstep(0.45, 0.55, spec)into a crisp cartoon band. - Silhouette rim light: Fresnel reflection adds a thin, sharp edge light around the model’s outline, but it is
skipped on the face (
PACK_FACE,PACK_EYE) to keep the clean impression.