Skip to main content

Lips, blush, and decal

✍ Last Updated : September 5, 2022

🚪 Prequisite Knowledge (Optional)

Working with unity’s shader

❓ Key Question / Problem / Issue

How to change character make up color and decal

✅ Expected Output/Definition of Done

User can change character make up color as well as change decal

🎁 Resulting Solution

Prerequisite (Optional)

For easier editing, both blush and lips, and decal should have different uv set.

Skin UV map

Skin UV map

Makeup UV map

Makeup UV map

Decal UV map

Decal UV map

Lips and Blush Color

To minimize texture usage, the shader uses blendmask for lips, blush and brows in the red, green, and blue channel to blend the lips, blush, and brows color. Each channel then combined into a single texture.

Untitled

Then the shader, will take each channel value and interpolate between skinColor and skinColor x _LipsColor based on blendMask red channel. Then interpolate between the previous result and blushColor using blendMask blue channel. The green channel (for brows) are not used anymore, since the brows color is decided to use another texture channel to make it easier to swap texture.

Base skin color

Base skin color

lips channel * lipColor(red)

lips channel * lipColor(red)

blush channel * blushColor(red)

blush channel * blushColor(red)

float4 skinCol = lerp(_Skin2, _Skin1, pow(skinMask.r, 2.2));

float4 lips    = lerp(skinCol, _Lips * skinCol, blushMask.r);
float4 blush   = lerp(lips, _Blush * skinCol, blushMask.g);

Final result

Final result

Then adding the result above with some red hue to give some fake subsurface scattering to get the base skin color

without red hue

without red hue

with red hue

with red hue

float4 baseSkin = blush * saturate((1-pow(skinMask.g, 2.2)) + float4(0.48,0.011,0.015,0));

Decal Texture and Color

Decals are second layer in the skin with replaceable texture, and some of the decal color can be changed. The white colored decal color can be changed but non white decal color cant, even if the _DecalColor is modified, the non white colored decal must maintain their original color.

This is done by comparing the average rgb value with 0.9, then interpolating between white color (1) and decalColor using the comparison value.

Next is to blend/interpolate between base skin color and decal using decal’s alpha channel

float4 decal = tex2D(_DecalTex, i.uv3);
float  decalValue = step(0.9, (decal.r + decal.g + decal.b) * 0.3333);
decal = decal * lerp(1 ,_DecalColor, decalValue) * _DecalPower;
baseSkin = lerp(baseSkin, decal, decal.a); 
float4 col = (baseSkin * matcap * lighting);//final Color

Base skin color

Base skin color

White decal with blue color

White decal with blue color

Non-white decal even blue color

Non-white decal even blue color

Then multiply the result above with lighting value (nDotL * lightingColor) to have the final result.