{"id":54,"date":"2022-02-23T10:14:55","date_gmt":"2022-02-23T10:14:55","guid":{"rendered":"https:\/\/noirccc.net\/blog\/?p=54"},"modified":"2023-05-18T00:27:43","modified_gmt":"2023-05-18T00:27:43","slug":"genshin-facial-shader-real-time-demo-workflow","status":"publish","type":"post","link":"https:\/\/noirccc.net\/blog\/posts\/54","title":{"rendered":"Genshin Face Shader &#038; Real-Time Rendering Demo Workflow"},"content":{"rendered":"\n<p>The previous demo has officially hit 1 million views on Bilibili (yay \u30fe(\u2267\u25bd\u2266*)o). <a href=\"https:\/\/www.bilibili.com\/video\/BV1ZA411s7Tx\" target=\"_blank\" rel=\"noopener\" title=\"\">Demo 1 (Bilibili)<\/a><\/p>\n\n\n\n<p>Being a very primitive test, it does have some limitations. For instance, not much work was put into the hair and clothes, these parts are largely just plain npr shading.<\/p>\n\n\n\n<p>Recently I&#8217;ve made another demo for stylized character rendering similar to Genshin Impact. This addresses some of the problems in the previous demo.<\/p>\n\n\n\n<p><a href=\"https:\/\/www.bilibili.com\/video\/BV1iR4y1V7ze\" target=\"_blank\" rel=\"noreferrer noopener\">Demo 2 (Bilibili)<\/a><\/p>\n\n\n\n<p>Environment\uff1aUnity 2020.3.22f1\uff0cURP 10.7.0<\/p>\n\n\n\n<p>Features:<\/p>\n\n\n\n<p>\u25c7 Utilizes facial dynamic shadow map for smooth shadow attenuation w\/o normal edit<\/p>\n\n\n\n<p>\u25c7 Ramp texture-based colour blending on shadow edges.<\/p>\n\n\n\n<p>\u25c7 Common NPR effects such as smoothed normals outlines, stylized specular, rim light, etc.<\/p>\n\n\n\n<p>\u25c7 Magica Cloth integration for some nice wind effects.<\/p>\n\n\n\n<p>We now have a quite polished stylized shading on the entire avatar rather than just the face. The facial shader has also received some fixes &#8212; the lightmap calculation no longer overcomplicates things.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Choose original lightmap L (light from left) or flipped lightmap R (light from right).\nfloat LightMap = lerp(surfaceData._lightMapR.r, surfaceData._lightMapL.r, step(RdotL, 0));\n\n\/\/ Calculate result.\nfloat litOrShadow = step((-FdotL + 1)) \/ 2, LightMap);<\/code><\/pre>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>For more info check out this video: <a href=\"https:\/\/www.bilibili.com\/video\/BV15t4y1V76U\" target=\"_blank\" rel=\"noopener\" title=\"\">https:\/\/www.bilibili.com\/video\/BV15t4y1V76U<\/a><\/p>\n\n\n\n<p>Facial shader is based on UnityURPToonLitShaderExample, and has added support for facial dynamic shadow map &amp; custom shadow colour.<\/p>\n\n\n\n<p>Repository for the shader\uff1a<a href=\"https:\/\/github.com\/NoiRC256\/UnityURPToonLitShaderExample\" target=\"_blank\" rel=\"noreferrer noopener\">repo (Github)<\/a><\/p>\n\n\n\n<div class=\"wp-block-argon-github github-info-card card shadow-sm github-info-card-full\" data-author=\"NoiRC256\" data-project=\"URPSimpleGenshinShaders\"><div class=\"github-info-card-header\"><a href=\"https:\/\/github.com\/\" target=\"_blank\" title=\"Github\" rel=\"noopener\"><span><i class=\"fa fa-github\"><\/i>\u00a0GitHub<\/span><\/a><\/div><div class=\"github-info-card-body\"><div class=\"github-info-card-name-a\"><a href=\"https:\/\/github.com\/NoiRC256\/URPSimpleGenshinShaders\" target=\"_blank\" rel=\"noopener\"><span class=\"github-info-card-name\">NoiRC256\/URPSimpleGenshinShaders<\/span><\/a><\/div><div class=\"github-info-card-description\"><\/div><\/div><div class=\"github-info-card-bottom\"><span class=\"github-info-card-meta github-info-card-meta-stars\"><i class=\"fa fa-star\"><\/i>\u00a0<span class=\"github-info-card-stars\"><\/span><\/span><span class=\"github-info-card-meta github-info-card-meta-forks\"><i class=\"fa fa-code-fork\"><\/i>\u00a0<span class=\"github-info-card-forks\"><\/span><\/span><\/div><\/div>\n\n\n\n<p>Update: Currently supports single Directional Light (i.e. correct light color &amp; intensity blending).<\/p>\n\n\n\n<p>TCP2 is also used here. TCP2 has a group of robust stylized shaders that can achieve common anime npr looks.<\/p>\n\n\n\n<h2>Animation Workflow<\/h2>\n\n\n\n<p>\u2013 Character animation migration:<\/p>\n\n\n\n<p>Use FaceAndLips to create facial animations \u2192 In MMD, compose animations, create eye animations\uff0cexport vmd \u2192 In blender2.9 (with Cats plugin) import pmx and vmd\uff0cbuild and bake physics\uff0cexport fbx \u2192 import fbx to Unity.<\/p>\n\n\n\n<p>For Unity Humanoid animations, use blender2.9 (with Cats plugin) to convert MMD pmx models to fbx\uff0cimport to Unity and set Rig to be Humanoid. Realtime physics can be created with Magica Cloth.<\/p>\n\n\n\n<p>\u2013 Camera animation:<\/p>\n\n\n\n<p>Camera animations can be directly created in Timeline.<\/p>\n\n\n\n<p>These methods can be useful:<\/p>\n\n\n\n<p>1. Cinemachine vcams<\/p>\n\n\n\n<p>2. Keyframing in record mode<\/p>\n\n\n\n<p>Align With View (Ctrl + Shift + F) can align camera to scene view.<\/p>\n\n\n\n<p>Align View to Selected (Custom hotkey) can align scene view with camera.<\/p>\n\n\n\n<h2>Scene<\/h2>\n\n\n\n<p>Screencap video is used as background. This is achieved by material with render texture that receives input from Video Player.<br>Unity&nbsp;<a href=\"https:\/\/assetstore.unity.\/\" target=\"_blank\" rel=\"noreferrer noopener\">Default Playables<\/a>&nbsp;allows Timeline to handle Video Player tracks.<\/p>\n\n\n\n<p><a href=\"https:\/\/assetstore.unity.com\/packages\/3d\/curved-plane-87846\" target=\"_blank\" rel=\"noreferrer noopener\">Curved Plane<\/a>&nbsp;helps give a 3D feeling to the background, but it is only visible in play mode.<\/p>\n\n\n\n<p>When using media as background, shadows on transparent ground can be achieved using&nbsp;<a href=\"https:\/\/forum.unity.com\/threads\/water-shader-graph-transparency-and-shadows-universal-render-pipeline-order.748142\/#post-5518747\" target=\"_blank\" rel=\"noreferrer noopener\">this shader<\/a>\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A URP real-time demo for Genshin Impact stylized character rendering, featuring custom shader and scene workflow.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[43],"tags":[58,71,53],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/noirccc.net\/blog\/wp-json\/wp\/v2\/posts\/54"}],"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=54"}],"version-history":[{"count":17,"href":"https:\/\/noirccc.net\/blog\/wp-json\/wp\/v2\/posts\/54\/revisions"}],"predecessor-version":[{"id":621,"href":"https:\/\/noirccc.net\/blog\/wp-json\/wp\/v2\/posts\/54\/revisions\/621"}],"wp:attachment":[{"href":"https:\/\/noirccc.net\/blog\/wp-json\/wp\/v2\/media?parent=54"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/noirccc.net\/blog\/wp-json\/wp\/v2\/categories?post=54"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/noirccc.net\/blog\/wp-json\/wp\/v2\/tags?post=54"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}