Wednesday, December 26, 2012

How to Create an Alpha/UV Mask for a Piece of Clothing

Sometimes you can have the following problem: A piece of clothing is letting your skin show through from underneath it.  One solution is to keep editing the clothing mesh so that it does not let any skin show through anyplace, but this can be a laborious process, and you will still come across animations that will stretch the clothing in an unusual way and your skin will still show through.

A second solution, one that we will cover here, is to make an alpha mask (also called a UV mask) which makes the parts of your body underneath the clothing transparent, so they can't show through the cloth.  (This is exactly the same way that a mesh piece of clothing is constructed in Second Life; there is a transparency layer added to the skin under the article of mesh clothing to hide the body underneath.)

So, how does one make such a mask?  well, you have to start from the Avatar Development Kit, the moswt recent version of which can be found here:

This is a zip file which you download to your computer and unzip.  The two files in which we are interested are:
  • the male body layout in a square: Male/texture/M_body_d
  • the female body layout in a square: Female/texture/F_body_d
What you need to do is to use a graphics program (any graphics program will do, like PhotoShop or Gimp) to

  1. create a new, transparent layer over top of the body layout layer; 
  2. colour that layer in black for any part of the body which you want to make transparent;
  3. leave any part of the layer white for any part of the body you want to be visible;
  4. save that layer as a separate image file (I use TARGA or TGA format, but you can use PNG or any other image format);
  5. upload the TGA file as a mask (not as a regular image);
  6. apply the mask to the article of mesh clothing;
  7. wear the article of mesh clothing to check that the mask worked;
  8. repeat steps 1 through 7 until you are satisfied with your mask.
That's the brief description.  Now I am going to go through this process step-by-step with an alpha mask for a woman's full-body leotard.  Here is what the leotard looks like without a mask:

Notice that the underarm area is particular has skin showing through as the avatar goes through the animations.  And here is what the leotard looks like with the alpha/UV mask:

Step 1: I will be using PhotoShop for this tutorial as I am most familiar with it.  I load the female body layout (Female/texture/F_body_d from the Avatar Development Kit) into PhotoShop, and then I use the Layers menu to create a new, transparent layer.

Steps 2 and 3: Then, I use a black paintbrush to color those parts of the body (the trunk, arms, and legs) in black:

Do NOT color the hands or feet in black or they will also be transparent!  Note that if you did not want a turtleneck on the leotard, you could also have left the neck part of the female body layout white as well.

In actuality the alpha/UV mask is a greyscale image: black for transparent areas, white for visible areas, and greys for anything in-between (although it can be hard to think of a reason for something to be partially transparent).

Step 4: Then save that transparent layer (and ONLY that layer) as a TARGA (*.tga) format file.

Step 5: To upload the mask, go into Build mode by selecting Build from the cell phone icon menu or by hitting the B key.  Select Library, then press the Upload button.  VERY IMPORTANT:  when uploading an alpha/UV mask, you must go to the Contents pull-down menu next to the field and select mask:

Step 6: To apply the mask to the leotard, you assign it to the Body Alpha Mask field (when you click on the empty field, a display of masks is shown.  CLick th eone you want to highlight it in orange, and click the Select button):

Steps 7 and 8:  Don't be too surprised if you find that the mask is not perfect and that you need to readjust it in PhotoShop.  Until there is a clear grid for the making of such masks, it is always going to be a bit of a guessing game (now THIS is something useful you could release, Cloud Party: the grid layouts for the female and male body layouts).  The female one would look something like this:

No comments:

Post a Comment