Avatar SDK Local Compute Unity plugin  3.1.0
Realistic avatar generation toolset for Unity3D
How To Use body_visibility_mask Texture

Sometimes a skin mesh can intersect with an outfit mesh. It causes artifacts like on the picture below when skin is visible above an outfit.

artifacts.jpg
Skin appears above an outfit

To get rid of it the body_visibility_mask texture should be used. It indicates which parts of a body are hidden under an outfit. This texture is generated for each outfit and should be used as an alpha channel for a body texture.

Use body_visibility_mask for avatars generated at runtime

Avatar SDK Unity plugin allows to load avatars in GLTF format at runtime. FullbodyAvatarLoader object is used for it. It automatically applies body_visibility_mask texture if it exists. So, you need:
1. Specify an outfit and body_visibility_mask texture in computation parameters. The texture is enabled by default.

private FullbodyAvatarComputationParameters GetComputationParameters()
{
FullbodyAvatarComputationParameters computationParameters = new FullbodyAvatarComputationParameters();
computationParameters.outfits.names.Add("outfit_meta_1");
computationParameters.outfits.embed = false;
if (!computationParameters.outfits.additionalTextures.Contains("body_visibility_mask"))
{
Debug.LogErrorFormat("There is no body_visibility_mask");
computationParameters.outfits.additionalTextures.Add("body_visibility_mask");
}
return computationParameters;
}

2. Call ShowOutfitAsync method to load an outfit.

private IEnumerator LoadAvatar(string avatarCode, string haircutName, string outfitName)
{
FullbodyAvatarLoader avatarLoader = new FullbodyAvatarLoader(AvatarSdkMgr.GetFullbodyAvatarProvider());
yield return avatarLoader.LoadAvatarAsync(avatarCode);
yield return avatarLoader.ShowHaircutAsync(haircutName);
// Load an outfit. body_visibility_mask texture will be applied automatically if it exists.
yield return avatarLoader.ShowOutfitAsync(outfitName);
}

Use body_visibility_mask for imported FBX models

If you need to import FBX with a full body model into a unity project, the body_visibility_mask can be used as follow:
1. Import FBX model then extract texture and materials.

extract_textures_and_materials.jpg

2. Select Read/Write Enabled for the body_visibility_mask texture. Do the same for the model texture.

enable_read_write.jpg

3. Set Rendering Mode to Cutout for the body material and Alpha Cutoff to 0.01.

body_material_properties.jpg

4. Open "Window -> Avatar SDK -> Tools -> Apply Body Visibility Mask".
5. Assign model.jpg texture as Body Texture and body_visibility_mask.jpg as Visibility Mask Texture. Press Merge button.

apply_body_visibility_mask.jpg

6. model_with_transparency.png texture will be generated. You need to set it as a main texture for your body material.

Also you can merge the model texture with the body_visibility_mask with the following code:

private Texture2D MergeBodyTextureWithVisibilityMask(Texture2D bodyTexture, Texture2D bodyVisibilityMask)
{
Texture2D transparentBodyTexture = new Texture2D(bodyTexture.width, bodyTexture.height);
Color32[] visibilityMaskColors = bodyVisibilityMask.GetPixels32();
Color32[] bodyTexColors = bodyTexture.GetPixels32();
for (int i = 0; i < bodyTexColors.Length; i++)
bodyTexColors[i].a = visibilityMaskColors[i].r;
transparentBodyTexture.SetPixels32(bodyTexColors);
transparentBodyTexture.Apply();
return transparentBodyTexture;
}

And replace the current body texture:

private void ReplaceBodyTexture(SkinnedMeshRenderer bodyMeshRenderer, Texture2D bodyTexture, Texture2D bodyVisibilityMask)
{
Texture2D transparentBodyTexture = MergeBodyTextureWithVisibilityMask(bodyTexture, bodyVisibilityMask);
bodyMeshRenderer.sharedMaterial.mainTexture = transparentBodyTexture;
}

Contact us if you have any issues or questions: suppo.nosp@m.rt@a.nosp@m.vatar.nosp@m.sdk..nosp@m.com.