URP Genshin Face Shader Test

URP Genshin Face Shader Test

repo

This is an extremely primitive test of how the face shader is achieved in Genshin Impact.

A ramp texture “lightmap” is used to define how shadows respond to main light directions. This “lightmap” can be created by drawing a couple of characteristic shadow textures under some lighting angles, then combining the results of their SDF interpolations.

(1). The “lightmap” feature can be integrated into UnityURPToonLitShaderExample by ColinLeung-NiloCat


// Use r value from the original lightmap(left part in shadow) or flipped lightmap (right part in shadow) depending on normalized light direction;
float LightMap = RightLight > 0 ? surfaceData._lightMapR.r : surfaceData._lightMapL.r;

(2). A dirThreshold value can be used to stretch the lightmap for small tweaking. This is set to around 0.1~0.5.

(Outdated: see the Update section)


float lightAttenuation_temp = (FrontLight > 0) ?
    min((LightMap > dirThreshold * RightLight), (LightMap > dirThreshold * -RightLight)) :
    min((LightMap > (1 - dirThreshold * 2)* FrontLight - dirThreshold), (LightMap > (1 - dirThreshold * 2)* -FrontLight + dirThreshold));

(3). Implement shadow color.

half3 shadowColor = lerp(1 * surfaceData._shadowColor, 1, faceShadowMask);
half3 rawLightSum = max(indirectResult*shadowColor, mainLightResult + additionalLightSumResult); // pick the highest between indirect and direct light

Update: Fix

For (1) and (2), we could just do this.

// Choose original lightmap L (light from left) or flipped lightmap R (light from right).
float LightMap = lerp(surfaceData._lightMapR.r, surfaceData._lightMapL.r, step(RdotL, 0));
 
// Calculate result.
float litOrShadow = step((-FdotL + 1)) / 2, LightMap);

The SDF lightmap contains shadow distribution data covering 0~180 degrees on one side of the face, rather than 0~90 degrees. The tip of the nose will receive lighting even when directly facing away from the light. This means the lightmap should be appiled on all angles on the xz plane. All we need to do is modify FdotL (i.e. dot product of face forward direction and light direction), standardizing it to [0, 1], equal to the range of a color value.

For more info check out this video: https://www.bilibili.com/video/BV15t4y1V76U

References:

(1) ruofeng133,https://blog.csdn.net/A13155283231/article/details/109705794
(2) 黑魔姬,https://zhuanlan.zhihu.com/p/279334552
(3) xibanya,https://answers.unity.com/questions/1686727/is-there-a-way-to-change-the-shadows-to-blue.html

No Comments

Send Comment Edit Comment

|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
Source: Genshin Impact
Source: Genshin Impact
Source: Genshin Impact
Source: Genshin Impact
颜文字
Emoji
小恐龙
花!
蒙德
璃月
稻妻
须弥
Previous
Next