{"id":35,"date":"2020-12-25T09:57:03","date_gmt":"2020-12-25T09:57:03","guid":{"rendered":"https:\/\/noirccc.net\/blog\/?p=35"},"modified":"2025-03-04T22:20:33","modified_gmt":"2025-03-04T22:20:33","slug":"urp-%e5%8d%a1%e9%80%9a%e9%9d%a2%e9%83%a8%e6%b8%b2%e6%9f%93%e6%b5%8b%e8%af%95","status":"publish","type":"post","link":"https:\/\/noirccc.net\/blog\/zh\/posts\/35","title":{"rendered":"URP \u5361\u901a\u9762\u90e8\u6e32\u67d3\u6d4b\u8bd5"},"content":{"rendered":"\n<p>This is an extremely primitive test of how the face shader is achieved in Genshin Impact.<\/p>\n\n\n\n<p>A dynamic facial shadow map texture (referred to as \u2018shadow map\u2019, or \u2018lightmap\u2019 in the code) is used to define how facial shadows respond to main light directions. This shadow map could be created by drawing a couple of characteristic shadow textures under some lighting angles, then combining the results of their SDF interpolations. @\u6a58\u5b50\u732b shared a solution for automated creation of such shadow maps:&nbsp;<a href=\"https:\/\/zhuanlan.zhihu.com\/p\/356185096\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/zhuanlan.zhihu.com\/p\/356185096<\/a>.<\/p>\n\n\n\n<p>This shadow map feature can be integrated into&nbsp;<a href=\"https:\/\/github.com\/NoiRC256\/UnityURPToonLitShaderExample\"><\/a><a href=\"https:\/\/github.com\/ColinLeung-NiloCat\/UnityURPToonLitShaderExample\">UnityURPToonLitShaderExample<\/a>&nbsp;by&nbsp;<a href=\"https:\/\/github.com\/ColinLeung-NiloCat\">ColinLeung-NiloCat<\/a>. This is the resulting shader:<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/NoiRC256\/UnityURPToonLitShaderExample\"><\/a><a href=\"https:\/\/github.com\/NoiRC256\/UnityURPToonLitShaderExample\">repo<\/a><\/p>\n\n\n\n<p>\u76ee\u524d\u6709\u4e9b\u9650\u5236\uff0c\u4f46\u914d\u7f6e\u597d\u4ee5\u540e\u8fd8\u662f\u53ef\u4ee5\u7528\u7528\u7684\uff0c\u80fd\u8fbe\u5230\u8fd1\u4f3c\u6e38\u620f\u5185\u7684\u6548\u679c\u3002<\/p>\n\n\n\n<p>\u9650\u5236\uff1a<\/p>\n\n\n\n<ul>\n<li>\u5b8c\u5168\u8986\u76d6\u4e86\u539f\u672c\u7684\u5361\u901a\u9634\u5f71\u5b9e\u73b0\u65b9\u6cd5\uff0c\u5fc5\u987b\u8d4b\u4e88 _LightMap \uff08\u5373\u9762\u90e8\u52a8\u6001\u9634\u5f71\u8d34\u56fe\uff0c\u672c\u6587\u7edf\u79f0\u9634\u5f71\u8d34\u56fe\uff09 \u624d\u6709\u9634\u5f71<\/li>\n\n\n\n<li>\u4e0d\u53d7\u5149\u7167\u5f3a\u5ea6\u6216\u5149\u7167\u989c\u8272\u5f71\u54cd<\/li>\n<\/ul>\n\n\n\n<ol>\n<li>\u83b7\u53d6 Forward &amp; Right vectors<sup>(2)<\/sup><\/li>\n\n\n\n<li>\u6839\u636e\u5149\u7167\u65b9\u5411\u9009\u62e9\u539f\u59cb\u6216\u7ffb\u8f6c<sup>(1)<\/sup>\u7684\u9634\u5f71\u8d34\u56fe<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Use r value from the original lightmap\uff08left part in shadow) or flipped lightmap (right part in shadow) depending on normalized light direction;\nfloat LightMap = RightLight &gt; 0 ? surfaceData._lightMapR.r : surfaceData._lightMapL.r;<\/code><\/pre>\n\n\n\n<p>\u5373\u4f7f\u89d2\u8272\u80cc\u5bf9\u5149\u6e90\u4e5f\u8981\u6709\u9f3b\u7ffc\u5149\uff0c\u53ef\u4ee5\u770b\u60c5\u51b5\u7528 dirThreshold \u5ef6\u5c55\u9634\u5f71\u8d34\u56fe\uff08\u5dee\u4e0d\u591a0.1~0.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>float lightAttenuation_temp = (FrontLight &gt; 0\n    min((LightMap &gt; dirThreshold * RightLight), (LightMap &gt; dirThreshold * -RightLight)) :\n    min((LightMap &gt; (1 - dirThreshold * 2)* FrontLight - dirThreshold), (LightMap &gt; (1 - dirThreshold * 2)* -FrontLight + dirThreshold));&lt;\/pre&gt;<\/code><\/pre>\n\n\n\n<p>\u6700\u540e\u7cca\u4e0a\u9634\u5f71\u989c\u8272\uff08\uff08\u4e0d\u77e5\u9053\u4e00\u822c\u600e\u4e48\u505a\u6682\u65f6\u5148\u8fd9\u6837\u5427<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>half3 shadowColor = lerp(1 * surfaceData._shadowColor, 1, faceShadowMask);\nhalf3 rawLightSum = max(indirectResult*shadowColor, mainLightResult + additionalLightSumResult); \/\/ pick the highest between indirect and direct light<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u53c2\u8003\uff1a<\/p>\n\n\n\n<p>(1) ruofeng133\uff0c<a href=\"https:\/\/blog.csdn.net\/A13155283231\/article\/details\/109705794\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/blog.csdn.net\/A13155283231\/article\/details\/109705794<\/a><br>(2) \u9ed1\u9b54\u59ec\uff0c<a href=\"https:\/\/zhuanlan.zhihu.com\/p\/279334552\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/zhuanlan.zhihu.com\/p\/279334552<\/a><br>(3) xibanya\uff0c<a href=\"https:\/\/answers.unity.com\/questions\/1686727\/is-there-a-way-to-change-the-shadows-to-blue.html\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/answers.unity.com\/questions\/1686727\/is-there-a-way-to-change-the-shadows-to-blue.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is an extremely primitive test of how the face shader is achieved in Genshin Impact. A dynamic facial shadow map texture (referred to as \u2018shadow map\u2019, or \u2018lightmap\u2019 in the code) is used to define how facial shadows respond to main light directions. This shadow map could be created by drawing a couple of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":134,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[47],"tags":[60,63,69],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/noirccc.net\/blog\/wp-json\/wp\/v2\/posts\/35"}],"collection":[{"href":"https:\/\/noirccc.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/noirccc.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/noirccc.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/noirccc.net\/blog\/wp-json\/wp\/v2\/comments?post=35"}],"version-history":[{"count":2,"href":"https:\/\/noirccc.net\/blog\/wp-json\/wp\/v2\/posts\/35\/revisions"}],"predecessor-version":[{"id":1278,"href":"https:\/\/noirccc.net\/blog\/wp-json\/wp\/v2\/posts\/35\/revisions\/1278"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/noirccc.net\/blog\/wp-json\/wp\/v2\/media\/134"}],"wp:attachment":[{"href":"https:\/\/noirccc.net\/blog\/wp-json\/wp\/v2\/media?parent=35"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/noirccc.net\/blog\/wp-json\/wp\/v2\/categories?post=35"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/noirccc.net\/blog\/wp-json\/wp\/v2\/tags?post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}