Mostly Harmless

Legacy:Alpha Channel

From Unreal Wiki, The Unreal Engine Documentation Site
Revision as of 04:48, 17 September 2006 by Tarquin (Talk | contribs)

Jump to: navigation, search

An alpha channel, also sometimes called a mask, controls the transparency of an image. In programs like Lightwave and 3D Studio, the image and its alpha channel can be separate image files, but most image formats store the alpha channel information within the main image file. For importing to UnrealEd, it's best to use 32 bit Wikipedia:TGA (Targa) files.

Alpha channels use black for transparent areas, and white for opaque areas. Files that are only black and white are sometimes called masks. An example might be an image of a tree where the trunk, branches, and leaves are visible but everything else is "invisible" or transparent.

They can also be used to make gradual shifts in transparency such as with the simulated glow of coronas and particles. Since black is transparent, a dark grey (eg, RGB 10,10,10) is mostly transparent but not completely.

Alpha channels are used to simulate 3D geometry without increasing the number of physical polygons. For example, a picket fence would require modeling individual boards and nails while an alpha channel image fence would simply contain and image of a fence and its alpha channel; transparent areas around the top and between individual fence boards.

About the .TGA file format

  • It is designed for high quality, raster images
  • They can be very large files because 1 byte is used for each color
  • TGAs support greyscale transparency, and so store the mask within the TGA
  • A TGA with an alpha channel (transparency information) are typically 32 bit files
  • TGA files can be run length encoded to save space; RLE compression is directly proportional to the complexity of the image. "Noisy" images don't compress well, while bands of the same color do compress well.
  • TGAs are sometimes called Targas or Targavision, or Truevision Targa

Adding An Alpha Channel to an Image

Adobe Photoshop

  1. Using the various laso tools, magic wand and the pen tool make your selection. If you don't already know how great the pen tool can be for making your selections try this tutorial.
  2. Go to the channels tab (next where the layers tab is usualy).
  3. Press the button "Save selection as channel" and a channel named Alpha1 should appear.
  4. N ow check if what you want to be visible is white. If it's the opposite, click on the Alpha1 channel (should be under the blue) deselect (Ctrl+D) and invert (Ctrl+I). There you have it!

Note: that in Photoshop 7.0 there is a bug that makes it imposible to save alpha channels in Targas. To fix this either update to 7.01 or download a small fix for the Adobe web site.

http://www.adobe.com/support/downloads/detail.jsp?ftpID=1544

Make sure you follow the instructions given there.

Also if you're using Photoshop you can save textures with alpha channels in DXT3 format. It only has a 4-bit alpha, instead of the 8-bit TGA alpha channel, but compression with DXT is much better and in most cases quality isn't much of an issue with alpha channels.

Paint Shop Pro

  1. Do Main menu->Selections->Select All, and press CTRL-C to copy the image to the clipboard.
  2. Press CTRL-V to paste it as a new image (you will be working on the cloned image first).
  3. Select the parts of the image you want to make transparent. The Wand selection tool is useful for this. Hold down the shift key to select multiple parts of the image.
  4. Take your floodfill tool and select a dark colour (the darker the colour, the more transparent the pixel will be). Floodfill within the selected areas.
  5. In the menu, do Selections->Invert. This will invert your selection.
  6. Whatever you do not want transparent is now selected. Take your floodfill tool and select a light colour (the lighter the colour, the less transparent the pixel will be). Floodfill within the selected areas.
  7. In the menu, do 'Layers->Load/Save Mask->Save Mask to Disk'. Type in a filename and hit Save.
  8. In the menu, click on 'Selections->Select None' to deselect everything.
  9. Reopen your original image.
  10. In the menu, click on 'Selections->Select All'.
  11. In the menu, click on 'Layers->Load/Save Mask->Load Mask from Disk'and look in the menu bar at the top of screen for Mask. Select Mask->New->From Image. In this dialogue box, for the source window, the pulldown box, 'blank' and select your masked texture's filename, and press ok.
  12. Select Masks->Save to Alpha channel from the menu. Just agree with the next two windows (hit 'OK'), and save your new masked image. Make sure you choose .TGA file format (it will be listed as Truevision TARGA (.TGA)).

DJPaul: Did some more work on this. Fell through when I released the Beta 8 of PSP menu-wise is much different from PSP7, so i'm stuck. Plus my art sk1lls about suitable for MS Paint. I will try find someone who knows to finish it.

The GIMP

  1. Select the parts of the image you want to be visible. (Or select what you want to be transparent, and do Select->Invert.)
  2. Do Layer->Mask->Add Layer Mask
    1. In the dialog, set Initialize Layer Mark to 'Selection'
  3. You can make further changes by painting directly on the layer mask. The layermask is just a grayscale image; black means fully transparent and white fully opaque.
  4. The new mask is selected in the layer list. Before you save, click on the original layer to select it. (Otherwise, saving will only export the grayscale mask.)
  5. When saving as TGA, the export procedure will tell you it needs to "Apply layer mask". Click 'Export'.

Another way to do is it right click on the layer and select "Add alpha channel" and use the Erase tool or Edit->Clear to erase the parts you want transparent.

Related Topics

Discussion

Birelli: Make sure you check the "Alpha" checkbox when you import your texture.

EricBlade: I have a "Masked" checkbox on the Import box, and that's about it. Seems like there's some important step missing here, since I can't get transparency to work at all in this thing.

Wormbo: You should still be able to set bAlphaTexture to True in the Texture Properties window.

EricBlade: awesome, that does it. Didn't know about that setting. Very, very handy.

DJPaul: Did some more work on this. Fell through when I released the Beta 8 of PSP menu-wise is much different from PSP7, so i'm stuck. Plus my art sk1lls about suitable for MS Paint. I will try find someone who knows to finish it.

Foxpaw: Is there a way to make a add a mask to a texture within UnrealEd? IE Set a texture as the alpha mask for another material?

Wormbo: I'm sure this is possible through extensive use of texture modifiers, e.g. you can use a Combiner to combine the colors of one texture with the alpha map of a different texture. With a FinalBlend modifier you can create an alpha channel based on a texture's brightness (like the render style STY_Translucent in UT) and use it in a Combiner to combine texture 1 and alpha channel of that FinalBlend. In both cases you have to apply another FinalBlend to the Combiner to make it actually use its alpha channel.

Foxpaw: I haven't been successful in using the finalblend to make an alpha channel like that, but that is basically what I was aiming for.. can you explain the process in greater detail, or maybe make a tutorial page on how to do it?

LegalAssassin: If you want an anti-aliased edge in PS you might experience (Geforce 2 GTS at least) that at distances this edge will turn white (!) in UEd. This is because of the the alpha color being white in PS. This looks bad when making, for instance, leaves on a branch. To fix this I use PSP 7 and open a .psd-version of the texture with the transparency as you want it. Now, make a new background layer, fill it with a more appropriate color (for leaves, some green would be nice) and save it as a .tga in PSP. The AA'd edge should now look good.

I'm sure there's a better way, but I'm learning PS by trial-and-error.

Tarquin: Discussion needs cleaning... Category:Legacy Refactor Me