Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Looking to make textures for Unity3d, and I'm stuck at what seems to be a simple stage. My goal is to create an RGBA image, with color information for every pixel, and a separate alpha channel. These two components get fed into Unity as base color and reflection strength, respectively. (Using "Reflective/Bumped Diffuse" material.)

If I use masking tools in Photoshop, I can erase parts of the output image (transparency). However, I would like to keep the original RBG color information when output, and not just have "blank" areas. Also, it would be nice if I could do it non-destructively, ie. the final alpha channel is dependent on a standard layer, or built from a path object, etc.

I have the same problem with The Gimp.

Any help on this would be greatly appreciated.

(If Photoshop/Gimp are not the tools for the job, can someone please recommend a better one?)

share|improve this question

5 Answers 5

up vote 4 down vote accepted

Photoshop Solution

Deleting a section of the image is only effecting that layer. What you want to do is create a separate channel which stores your alpha information.

  1. In the tool panel with Layers/Channels/Paths choose the Channels Tab. Here you will see RGB, Red, Green, and Blue.
  2. Create a new channel using the button at the bottom of the panel, this is your alpha channel. This is an 8-bit greyscale channel giving you 256 levels of transparency.
  3. You can use the little "eye" icons to toggle this channel on/off.
  4. Draw or copy/paste your information into the channel.

Note: When saving you need to be careful about file formats. Things like .Tiff & .TGA save the full alpha channel independent of color information. However Photoshop doesn't allow this with PNG, much to many developers annoyance. It will not properly save alpha channel images and tends to strip out color information for fully transparent areas to compress file size.

share|improve this answer
    
This was exactly what my problem was. I was outputting to PNG and not seeing any of the "alpha" channel goodness. Thanks, this is perfect. Does anyone have instructions for using the Gimp similarly? –  eli Aug 3 '10 at 19:01
1  
It's frustrating because back around version 5.0 or 5.5 Photoshop would actually save the full channel on PNGs. Adobe changed the way they handled them for subsequent versions of the software. Sigh... –  wkerslake Aug 3 '10 at 19:28

I find the best way to do this in The GIMP is to use a layer mask (right click on a layer and create mask).

The layer will then have two "images" associated with it - the RGBA image and a grayscale layer mask which acts as an extra (multiplicative) alpha channel. You can click either of these images to select which one will be edited.

If you hold CTRL and click the layer mask, you will see just the RGBA image (this disables the mask). If you hold down ALT and click the layer mask, you will see just the layer mask.

When you export an image with an active layer mask, the exported image will retain the colour information even from areas that the mask makes fully transparent.

For your purposes, you may find it effective to compose your alpha channel on a separate (RGBA) layer - then when you are done you can just copy this layer into the layer mask of the original layer.

share|improve this answer
    
This is closer to what I need. But it only affects the top layer! I have multiple layers in my image, and I would like to be able to do this without flattening it. Thanks for answering. –  eli Aug 3 '10 at 7:58
    
Add a mask layer to each layer of your image. –  deft_code Aug 3 '10 at 20:02

To write your own content processor (as suggested by @Andrew Russell) specific to Unity3D, place this script in your Assets/Editor folder will combine any image *-Base.* with a similarly-named *-Alpha.* file and modify the original texture:

class AlphaCombinerPostprocessor extends AssetPostprocessor {
    function OnPostprocessTexture(texture : Texture2D)
    {
        if (assetPath.Contains("-Base.")) {
            var fn = assetPath.Replace("-Base.","-Alpha.");
            var alpha = AssetDatabase.LoadAssetAtPath(fn,Texture2D);
            if (alpha) {
                Debug.Log("Adding alpha from "+fn);
                var c : Color[] = texture.GetPixels();
                var a : Color[] = alpha.GetPixels();
                if (c.Length != a.Length) {
                    Debug.LogError(fn+" is different size to "+assetPath);
                    return;
                }
                for (var i=0; i<c.Length; i++)
                    c[i].a = a[i].a;
                texture.SetPixels(c);
                texture.Apply(true);
            }
        }
    }
}

Adapt to your own asset file naming conventions.

share|improve this answer

In the GIMP, one way would be to split the image into layers for each channel. Select "Colors->Components->Decompose" and choose RGBA or whatever channels you want to break into layers. Then edit your individual alpha and color channels as you see fit (they should be greyscale), then go "Colors->Components->Compose" choose your desired channel layout and choose your layers to use for each channel.

Also, you can use the "Channels" dialogue. It should be a part of the default toolbox things, but if not you can select "Windows->Dockable Dialogues->Channels". You can toggle visibility of each color channel, and by clicking and highlighting the channel names you can choose which ones to edit individually (it looks like it preserves color with alpha, although I don't see a way to "hide" the alpha while editing without hiding the entire image...).

share|improve this answer
    
it looks like I have to flatten the image first, then decompose, then edit, and then recompose. Thanks for the tip! But I'm looking for a non-destructive way. –  eli Aug 3 '10 at 7:11
    
Ahh, I assumed you were working with a single layer image so flattening wouldn't be necessary, but nevermind then. Good luck! –  Riley Adams Aug 3 '10 at 7:42

One alternative is to write your own content processor to perform the operation you want. That way you could simply give your "reflectivity" layer (or even multiple reflectivity layers) a special name, and have the content processor put that data in the alpha channel for you. (Or indeed implement any kind of process that you like.)

If you were using XNA and The GIMP (this is what I use and am familiar with), then it would be very easy for you to add this XCF importer to your content pipeline and make the necessary modifications to process specially named layers.

As you are using Unity, not XNA, I am not familiar with what content pipeline options you have available. But perhaps you can adapt the linked code so that it works within your content process.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.