{"id":341,"date":"2020-08-27T10:38:38","date_gmt":"2020-08-27T10:38:38","guid":{"rendered":"http:\/\/half4.xyz\/?p=341"},"modified":"2026-02-16T16:21:12","modified_gmt":"2026-02-16T16:21:12","slug":"part-5-extending-the-shader","status":"publish","type":"post","link":"https:\/\/half4.xyz\/index.php\/2020\/08\/27\/part-5-extending-the-shader\/","title":{"rendered":"Part 5: Extending the Shader"},"content":{"rendered":"\n<p><em><sup>NSFW warning for further down this page<\/sup><\/em><\/p>\n\n\n\n<p>Let\u2019s take our shader and add in some new features: melanin and hemoglobin masks.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img fetchpriority=\"high\" decoding=\"async\" width=\"320\" height=\"378\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-62.png\" alt=\"\" class=\"wp-image-343\" srcset=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-62.png 320w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-62-254x300.png 254w\" sizes=\"(max-width: 320px) 100vw, 320px\" \/><figcaption class=\"wp-element-caption\">Tan goals.<\/figcaption><\/figure>\n\n\n\n<p>Using these masks will enable us to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Add in tan lines (farmers\u2019 tan, swimsuit tans)<\/li>\n\n\n\n<li>Mask areas for less melanin pigmentation, such as palms and soles of feet<\/li>\n\n\n\n<li>Add in support for vitiligo to increase diversity in your project further<\/li>\n\n\n\n<li>Add in blushing areas to expressions, which we can drive through blend shapes.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Melanin Masks<\/h2>\n\n\n\n<p>Melanin masks are the most straightforward. We need a greyscale mask that defines area of darker skin, and areas of lighter skin. We then sample a second set of fracitonal and blend values \u2013 so we have a skin colour for lighter areas and a skin colour for darker areas. <\/p>\n\n\n\n<p>We first need to define what we\u2019re masking<\/p>\n\n\n\n<p>We <em>could<\/em> have a single mask for all tan types, i.e. you either have a mask for natural pigmentation (palms, soles of feet) or your mask contains areas for tan lines. It is unlikely you want both, as a higher natural melanin fraction lends itself less to tan lines.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>For the purposes of this tutorial, we\u2019ll use a single mask for some tan lines, but you can expand this further if you want.<\/p>\n\n\n\n<p>We\u2019ll therefore need a one-channel mask \u2013 one for natural pigmentation and one for tan lines. I have prepared some content for you here:<\/p>\n\n\n\n<p><strong>Direct Download:<\/strong><\/p>\n\n\n\n<p>&lt;todo: retrieve link&#8230; lost in a wordpress upgrade&gt;<\/p>\n\n\n\n<p>Import it into our Digital Human project. In here, find open up the level <em>Female_Tan<\/em>. You will find some materials already set up with our pigmentation work from earlier.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>In the content I have provided, you will also see a few materials, and the following mask for tan lines:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"369\" height=\"273\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/08\/image.png\" alt=\"\" class=\"wp-image-384\" srcset=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/08\/image.png 369w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/08\/image-300x222.png 300w\" sizes=\"(max-width: 369px) 100vw, 369px\" \/><\/figure>\n\n\n\n<p>Open up the <em>M_Female_Tan<\/em> material. This is our Master Material that the different body sections inherit from, so changes here propagate to all the skin parts. It should look like this:<\/p>\n\n\n\n<p> <img loading=\"lazy\" decoding=\"async\" height=\"1018\" loading=\"lazy\" sizes=\"(max-width: 1024px) 100vw, 1024px\" srcset=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/08\/image-1-1024x1018.png 1024w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/08\/image-1-300x298.png 300w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/08\/image-1-150x150.png 150w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/08\/image-1-768x763.png 768w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/08\/image-1.png 1325w\" width=\"1024\" class=\"wp-image-385\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/08\/image-1-1024x1018.png\" alt=\"\"><\/p>\n\n\n\n<p><br> Duplicate the recolor section in the Albedo area, double up the Input variables and rename the input scalar parameters as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"1024\" height=\"453\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/08\/image-2-1024x453.png\" alt=\"\" class=\"wp-image-386\" srcset=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/08\/image-2-1024x453.png 1024w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/08\/image-2-300x133.png 300w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/08\/image-2-768x340.png 768w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/08\/image-2.png 1340w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Next, drop in our a Texture Variable, use the T_Black_Linear texture here as most body parts don\u2019t need a texture here, and this is our default. Take the R (red) channel and drag this into a lerp node as input Alpha. <br>We\u2019ll set the Tan values to be input A (as tanned areas are black on our mask) and the base values to be Input B (as these are white):<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"680\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/08\/image-4-1024x680.png\" alt=\"\" class=\"wp-image-388\" srcset=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/08\/image-4-1024x680.png 1024w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/08\/image-4-300x199.png 300w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/08\/image-4-768x510.png 768w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/08\/image-4-1536x1019.png 1536w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/08\/image-4-2048x1359.png 2048w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/08\/image-4-360x240.png 360w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Now test your results on M_Female_Tan_Body by assigning our T_Melanin_Mask into the appropriate texture input:<\/p>\n\n\n\n<p><video controls=\"\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/08\/TanTests.mp4\"><\/video><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Hemoglobin Masks<\/h2>\n\n\n\n<p>I <em>wanted<\/em> to use UE4 for this page, to keep things consistent. Unfortunately, I\u2019ve been unable to source assets I can share that are high-quality, contain an ability to create facial expressions easily and are <em>free<\/em>. This is currently a one-person outfit and I don\u2019t have the resources to make such assets in a reasonable time frame. This principles in UE4 remain the same, however.<\/p>\n\n\n\n<p>As such, of this part, we\u2019ll be using the Digital Human Asset from the Unity Asset Store and Unity 2019.3+. Apologies for the switch, but it is necessary here (for my sanity) and never hurts to learn multiple engines for new techniques!<\/p>\n\n\n\n<p>You can get it here:<br>&lt;todo: again, need to get these links back&gt;<\/p>\n\n\n\n<p>For this, we want to generate some masks that are associated with different emotions or expressions. <\/p>\n\n\n\n<p>The digital human pack provided by Unity allows for a variety of facial expressions. Unfortunately, its implementation is rather obtuse for our needs, so directly driving hemoglobin levels, while possible, will add pages to this already lengthy tutorial. <\/p>\n\n\n\n<p>Instead, we\u2019ll use sliders to drive a couple of hemoglobin masks to demonstrate how we can use them.<\/p>\n\n\n\n<p>I have already got our basic implementation from the previous page included. Grab these files and add them to the Digital Human project mentioned above:<\/p>\n\n\n\n<p><strong>Direct Download:<\/strong><br>\n<\/p>\n\n\n\n<p>To start off, you can find this texture in the assets I have provided:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"399\" height=\"1024\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-66-399x1024.png\" alt=\"\" class=\"wp-image-373\" srcset=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-66-399x1024.png 399w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-66-117x300.png 117w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-66-768x1971.png 768w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-66-598x1536.png 598w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-66.png 780w\" sizes=\"(max-width: 399px) 100vw, 399px\" \/><\/figure>\n\n\n\n<p>The red and green channels contain slightly different hemoglobin masks for the face.<\/p>\n\n\n\n<p>The first step is to add these varibales to the DigitalHuman_Skin_LUT shader graph:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"879\" height=\"735\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-67.png\" alt=\"\" class=\"wp-image-374\" srcset=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-67.png 879w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-67-300x251.png 300w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-67-768x642.png 768w\" sizes=\"(max-width: 879px) 100vw, 879px\" \/><\/figure>\n\n\n\n<p>Then add this logic the Hemoglobin Fraction value:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"442\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-68-1024x442.png\" alt=\"\" class=\"wp-image-375\" srcset=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-68-1024x442.png 1024w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-68-300x130.png 300w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-68-768x332.png 768w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-68.png 1450w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Compile, then make sure you add the Hemoglobin Mask to the Gawain_Skin material.<\/p>\n\n\n\n<p>Select a pale skin tone and overdo the hemoglobin to see it:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"555\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-70-1024x555.png\" alt=\"\" class=\"wp-image-378\" srcset=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-70-1024x555.png 1024w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-70-300x163.png 300w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-70-768x417.png 768w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-70-1536x833.png 1536w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-70-2048x1111.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Now, you can play with the expressions to get some more results:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"804\" height=\"1024\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/Examples_Unity_Hemoglobin-804x1024.png\" alt=\"\" class=\"wp-image-379\" srcset=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/Examples_Unity_Hemoglobin-804x1024.png 804w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/Examples_Unity_Hemoglobin-236x300.png 236w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/Examples_Unity_Hemoglobin-768x978.png 768w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/Examples_Unity_Hemoglobin-1206x1536.png 1206w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/Examples_Unity_Hemoglobin-1608x2048.png 1608w\" sizes=\"(max-width: 804px) 100vw, 804px\" \/><\/figure>\n\n\n\n<p>You can grab both projects, in their entirety, here:<br>&lt;todo: come back and fix&gt;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>NSFW warning for further down this page Let\u2019s take our shader and add in some new features: melanin and hemoglobin masks. Using these masks will enable us to: Melanin Masks Melanin masks are the most straightforward. We need a greyscale mask that defines area of darker skin, and areas of lighter skin. We then sample a second set of fracitonal and blend values \u2013 so we have a skin colour for lighter areas and a skin colour for darker areas. We first need to define what we\u2019re masking We could have a single mask for all tan types, i.e. you either have a mask for natural pigmentation (palms, soles of feet) or your mask contains areas for tan lines. It is unlikely you want both, as a higher natural melanin fraction lends itself less to tan lines. For the purposes of this tutorial, we\u2019ll use a single mask for some tan lines, but you can expand this further if you want. We\u2019ll therefore need a one-channel mask \u2013 one for natural pigmentation and one for tan lines. I have prepared some content for you here: Direct Download: &lt;todo: retrieve link&#8230; lost in a wordpress upgrade&gt; Import it into our Digital Human project. In here, find open up the level Female_Tan. You will find some materials already set up with our pigmentation work from earlier. In the content I have provided, you will also see a few materials, and the following mask for tan lines: Open up the M_Female_Tan material. This is our Master Material that the different body sections inherit from, so changes here propagate to all the skin parts. It should look like this: Duplicate the recolor section in the Albedo area, double up the Input variables and rename the input scalar parameters as follows: Next, drop in our a Texture Variable, use the T_Black_Linear texture here as most body parts don\u2019t need a texture here, and this is our default. Take the R (red) channel and drag this into a lerp node as input Alpha. We\u2019ll set the Tan values to be input A (as tanned areas are black on our mask) and the base values to be Input B (as these are white): Now test your results on M_Female_Tan_Body by assigning our T_Melanin_Mask into the appropriate texture input: Hemoglobin Masks I wanted to use UE4 for this page, to keep things consistent. Unfortunately, I\u2019ve been unable to source assets I can share that are high-quality, contain an ability to create facial expressions easily and are free. This is currently a one-person outfit and I don\u2019t have the resources to make such assets in a reasonable time frame. This principles in UE4 remain the same, however. As such, of this part, we\u2019ll be using the Digital Human Asset from the Unity Asset Store and Unity 2019.3+. Apologies for the switch, but it is necessary here (for my sanity) and never hurts to learn multiple engines for new techniques! You can get it here:&lt;todo: again, need to get these links back&gt; For this, we want to generate some masks that are associated with different emotions or expressions. The digital human pack provided by Unity allows for a variety of facial expressions. Unfortunately, its implementation is rather obtuse for our needs, so directly driving hemoglobin levels, while possible, will add pages to this already lengthy tutorial. Instead, we\u2019ll use sliders to drive a couple of hemoglobin masks to demonstrate how we can use them. I have already got our basic implementation from the previous page included. Grab these files and add them to the Digital Human project mentioned above: Direct Download: To start off, you can find this texture in the assets I have provided: The red and green channels contain slightly different hemoglobin masks for the face. The first step is to add these varibales to the DigitalHuman_Skin_LUT shader graph: Then add this logic the Hemoglobin Fraction value: Compile, then make sure you add the Hemoglobin Mask to the Gawain_Skin material. Select a pale skin tone and overdo the hemoglobin to see it: Now, you can play with the expressions to get some more results: You can grab both projects, in their entirety, here:&lt;todo: come back and fix&gt;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[8,7],"class_list":["post-341","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-lut","tag-skin"],"_links":{"self":[{"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/posts\/341"}],"collection":[{"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=341"}],"version-history":[{"count":22,"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/posts\/341\/revisions"}],"predecessor-version":[{"id":1477,"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/posts\/341\/revisions\/1477"}],"wp:attachment":[{"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=341"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}