![Image](https://steamcdn-a.akamaihd.net/steamcommunity/public/images/clans/11544764/0fb49bfcb1d273c202c6146d638f8fc1beaf1830.png)
Art Blog: Let's Talk About Face Shaders
Hello! My name is Ian McConville, and I'm the Principle Artist at Monomi Park.
For Slime Rancher's 1.4.0 update, I rebuilt nearly all of the slime related shaders from the ground up! One of the most notable of these changes is that the slime faces are now more detailed and, at the same time take up less memory.
Let's take a look at how the new shaders work!
![Image](https://steamcdn-a.akamaihd.net/steamcommunity/public/images/clans/11544764/a30356f5e47d409d7cf5c97610588162a20fcf11.jpg)
Texture - Changing the Channel!
The first thing we do when building a slime is we start with a special, custom RGBA texture. A single RGBA texture file actually contains 4 grayscale images, and each image is used as a special mask that will dictate where artist defined colors will go on the face.
- The R (red) channel is used for the eyes.
- The G (green) channel is a highlight color for the eyes.
- The B (blue) channel is a secondary eye color, but not used in this case.
- The A (alpha) is used for the Mouth.
![Image](https://steamcdn-a.akamaihd.net/steamcommunity/public/images/clans/11544764/889f96ac335a750256479c48fa99479a0f5a99b9.jpg)
Now you're probably wondering why the mask is so FUZZY. Well, the reason is that the mask is actually a Distance Field.
These fuzzy masks will allow for much higher detail than a standard rasterized texture could, even at larger resolutions! (The texture itself is only 64x64 pixels in size, which is roughly 1/4th the size of the face textures from Slime Rancher 1.3.0's faces).
![Image](https://steamcdn-a.akamaihd.net/steamcommunity/public/images/clans/11544764/2647dd77a9133f21217d803a769e1e728b97f7b6.jpg)
This is done by applying a very simple layer style to a high resolution mask of the mouth:
![Image](https://steamcdn-a.akamaihd.net/steamcommunity/public/images/clans/11544764/9b46b66d03cdefdf571519faa97264bbf05d6602.png)
And then in the shader, we use a process called Smooth Step to sharpen the mask. Using the fuzzy values of the image we can find clean, crisp edges hidden in the texture.
This process costs a little performance at run time, but is actually cheaper on texture memory. It also has the added bonus of being extremely sharp, even when the slime is very very close to the player!
![Image](https://steamcdn-a.akamaihd.net/steamcommunity/public/images/clans/11544764/8341a5e56e72e6d67621311cc2fad80b3a397e1f.gif)
![Image](https://steamcdn-a.akamaihd.net/steamcommunity/public/images/clans/11544764/a8887ba1d3aeb61422d2b991f2fc14b31abc7080.gif)
![Image](https://steamcdn-a.akamaihd.net/steamcommunity/public/images/clans/11544764/7f7c320d4336e781407bab77ef687188d05504e2.gif)
A regular texture, at the same resolution, without distance fields would look no where near as good. Even when using the Smooth Step process.
Eyes - Adding some Sparkle!
So now we have a super clean, crisp mask to work with for our eyes and mouth! It looks even sharper than the original high resolution version of the mask we started with.
![Image](https://steamcdn-a.akamaihd.net/steamcommunity/public/images/clans/11544764/79477728fb06aefab17842bea3079140f352261f.jpg)
Before we get to the mouth, we'll begin with the eyes. The eyes make use of the RGB channels, but again, in this case we won't be using B.
1) In the first image, we see the original texture file masked by the Eye Mask.
2) If we take only the R channel and multiply that by a dark color (color1) we'll get a flat, black eye.
3) Then we'll do the same with the G channel and add that to the colored R channel.
![Image](https://steamcdn-a.akamaihd.net/steamcommunity/public/images/clans/11544764/af113f586c5899a4735adc02ea10393cfe48131f.png)
Then, using a simple node setup in the shader, some glints are generated. A UV offset is applied to the glints so that they move with the player's view.
Once we have this, it's added to the rest of the eyes.
![Image](https://steamcdn-a.akamaihd.net/steamcommunity/public/images/clans/11544764/1aeb5fcacf370b5ce3f78a28e891334e53e27bd1.png)
![Image](https://steamcdn-a.akamaihd.net/steamcommunity/public/images/clans/11544764/df07911f1b10bb83ff354b91c67d9425a401d33d.jpg)
The results: A nice (fake) glint is applied to the eye!
![Image](https://steamcdn-a.akamaihd.net/steamcommunity/public/images/clans/11544764/bf7e7349d897dd8e3bc1527acd5f1e47f883f0de.gif)
It's super cheap as it doesn't actually take the lighting information in to consideration, but it's very satisfying to look at!
There's a lot more that goes into the eyes, but that was the main parts. Here's a quick glance at what the entire Eye section of the shader graph looks like.
![Image](https://steamcdn-a.akamaihd.net/steamcommunity/public/images/clans/11544764/725a6911161b04720fcc67b9a5fc307028de84b1.png)
Now then, it's time to move on to the mouth.
Mouth - Wide Smile!
The mouth is just a sticker applied to the slime's body, but we still want it to feel like a 3D hole in the surface.
To start, we need the back of the mouth. The warm red tones! This is simply a gradient with a severe depth offset.
![Image](https://steamcdn-a.akamaihd.net/steamcommunity/public/images/clans/11544764/0a6b5df471da9c689f6e64765aa30475c1a32416.jpg)
An extra visual treat, new to 1.4.0, is that slimes finally have visible tongues! This is achieved with a little shader trickery to make a circle and then a depth offset to set it in the back of the mouth.
This is added to the previous gradient before it gets colorized. Subtle, but it makes a big difference in believing that the mouth has depth :D
![Image](https://steamcdn-a.akamaihd.net/steamcommunity/public/images/clans/11544764/a4907a28e4281a88c105007b01dcb13f69cad3f7.gif)
The nice thing about using the distance fields for the mouth mask is that we can adjust the smoothstep and get different sizes for the mouth. By layering various sizes of the mouth with different depths, we can get a pretty believable mask.
Then we multiply the mask over our big red gradient + tongue.
![Image](https://steamcdn-a.akamaihd.net/steamcommunity/public/images/clans/11544764/bcaef6b329ce0997506ebc74666ed7d3c7533e2a.gif)
And that's the mouth!
Again, same with the eyes, there's a lot more subtly that goes into the effect. Here's a glance at the full mouth shader:
![Image](https://steamcdn-a.akamaihd.net/steamcommunity/public/images/clans/11544764/f07efa80031c42cb352fe312e10627a9ee443846.png)
Get Wiggly - Final Touches?
It's time to put everything together. This is almost done, but we're missing a little something to make the face feel gooey-wiggly-wobbly.
![Image](https://steamcdn-a.akamaihd.net/steamcommunity/public/images/clans/11544764/435b144f87e0189071adf8656091d51891c94975.gif)
The eye and mouth texture has a UV input that we can modify for some extra noise. With a little adjusting of the wobbly values, we can make the static face warble-wander all over the place!
![Image](https://steamcdn-a.akamaihd.net/steamcommunity/public/images/clans/11544764/dfd83dce3871f744aa9182457f01682b7390f7be.gif)
![Image](https://steamcdn-a.akamaihd.net/steamcommunity/public/images/clans/11544764/dbcc1e5c037a11b9f2583407bb057fc247464ac2.gif)
And there you have it!
By swapping out our original face texture into this shader we can make all sorts of slime faces with nice, clean edges and plenty of fake depth.
Thank you, and I hope you enjoy this and other improvements with the Slime Rancher 1.4.0 release!
Stay wiggly :D