Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Big trouble in little Alpha Channel town

Discussion in 'Formats & External Tools' started by 3devils, Aug 6, 2010.

  1. 3devils

    3devils

    Joined:
    Sep 7, 2009
    Posts:
    60
    Hi,

    I am having difficulties to create smooth alpha maps for my textures.
    I followed http://unity3d.com/support/documentation/Manual/HOWTO-alphamaps.html and this of yourse works great if you have textures with *hard* alpha borders - since you create the alpha map from a selection in this tutorial, the border will always be precise, there is to my knowledge no way to have a partial selection of a pixel.

    But I would like a smoother border for my texture - I have searched for an export from the, what I would call, "Photoshop Alpha Channel" (which is the grey checker texture you have when deleting pixels and have no background layer left beneath it) - this layer is different from the "real" alpha channel that you can see in the layers tab, it's not present there.

    It would be absolutely brilliant if I could export the whole "Photoshop Alpha Channel" to a greyscale bitmap. I think all my troubles would be solved then. I could then have smooth (0-255) borders to my textures.
    I would create the Alpha Channel, then "bleed out" the original image to get rid of any white lines around them and voila.

    Is that possible? Am I missing something?

    bye,
    Thomas
     
  2. jamie

    jamie

    Joined:
    May 25, 2005
    Posts:
    178
    Sorry I have no help to offer, but thanks for reminding me of a great movie! :)
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, it works fine with anti-aliased selections.

    You always want to use a real alpha channel anyway, not the checkerboard transparency thing. You can't specify the matte color for that transparency, so you only get white, which is rarely what you actually want.

    --Eric
     
  4. sama-van

    sama-van

    Joined:
    Jun 2, 2009
    Posts:
    1,734
    To tell the truth I do not really like the tutorial from Unity you gave :( ....


    Here are some good advise :

    - Do not use PSD in your unity project since you do not control everything fro the conversion PSD to Unity.

    - Remember to work with PNG file and TGA file in Unity give 2 very different way to work with your material in the editor.

    - Example PNG :
    To create simple layer in Photoshop erasing some part to get transparency.
    If you save this as PNG it will automatically convert the empty pixel as black pixel on the alpha channel.


    - Example with TGA :
    To the same with PNG, but and this will also save the alpha channel.

    =============================================

    - But with TGA there is another way to work and this is cleaner than the Unity tutorial and the PNG method.
    It will also allow you more tricks with the shader ^_^...

    - A - to learn using Mask :

    When you create a texture used as diffuse in your asset, better on your PSD file to create a folder, to call it "Diffuse" and to attach a mask on it :



    Then all the diffuse work has to be done in the Diffuse folder.
    And if you need a to delete pixel on your diffuse to make it invisible, just paint with black and white on your layer mask!!!

    Remember : Never affect your layers if you want transparent pixel, but work with Layer Mask/

    - B -

    If you want to disable the mask, click on the mask with Alt + LMB. It will add a red cross on it.
    You can also keep active your layer mask but disable the render of the layer with Shift + LMB on your layer mask.

    This method help you to keep the full diffuse without erasing pixel from you diffuse work!!




    -C- Now to save the TGA file with a right alpha channel keep full view of diffuse with layer Mask OFF.

    ----- Disable your layer mask
    ----- ctrl + LMB on your layer mask : this will select the white zone
    ----- to go in the Channels window : if you do not have it, just go in the Windows>>> Channels menu.
    ----- to create a new layer
    ----- to choose White as main color in your brush tool
    ----- to select the Alpha 1 channel and to apply white color with Ald+Delete

    Remember : When saving as TGA file it will automatically find the layer Alpha 1 using it as alpha channel/

    Now you can select back the RGB channel, go back in your layer window and to save as TGA.



    In Unity to disable the DXT conversion and to work with the RGBA 32bits for hi quality rendering.



    EDIT : I am reading you are working with Iphone...
    always use RGB or RGBA conversion 16 0r 32 bits.
    Never work with DXT compression in Unity.
    Iphone do not know DXT conversion and will always convert your file to iphone format.
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I strongly disagree with that advice. I use PSD for all my textures; it's far more convenient than constantly exporting and dealing with two sets of textures, and works great.

    If you want your textures to be huge, sure, but typically you want to use compression if at all possible because of memory concerns. It's no problem to use DXT since that gets converted to PVRTC.

    --Eric
     
  6. sama-van

    sama-van

    Joined:
    Jun 2, 2009
    Posts:
    1,734
    if you are an experienced artist you should know there are a script functionally in Photoshop for noobs programmer to do that for the artist.
    Of if you know a little about programming you can do as I did : a Javascript tools to export your texture from your 3D project to Unity project is the right directory, using some sharpness option, to resize automaticaly your texture, etc... in one click. :)

    I also can export all thing I want from one PSD file like Diffuse, specular, normal map, etc...


    And you know what?
    To work with a 50 meg PSD under Unity is the baddest idea, since it will take about 30s to import it under Unity!!

    Also to save a texture as DXT1 is slower than RGB-16bit when you need to check you texture every 5 min in the engine.



    Then you convert your texture as DXT in Unity and unity will convert from DXT to PVRTC?
    you are great :D


    Did several test under iphone and when Unity convert a textyre from PVRTC to an uncompressed format, quality is better.


    Also one more note about PSD file : Good luck if you want to make your texture rendering better in the engine with some shader :)

    Everything I said are just advise because I already test all this kind of stuff, now I am fine, just wondering to give the best help I could to 3devils.
     
  7. 3devils

    3devils

    Joined:
    Sep 7, 2009
    Posts:
    60
    Thank you very much everyone, especially sama.van for taking so much time for his answer with this guide. I was able to reproduce all the steps and managed to get a perfect alpha transparent texture.
    My main mistake was to try a *normal* magic wand selection with a hard border to select the transparency and that obviously didn't get me very far. Using the alpha mask the way described above solved the issue.

    I documented the approach on my blog:
    http://www.3devils.com/creating-alpha-channel-textures-for-unity

    btw.: Saving the resulting texture as PSD made Unity not recognize the alpha mask, TGA and PNG both worked fine.

    @sama.van: Maybe you could write an article about texturing for unity and the compression details on different platforms for the Unity Creative magazine:
    http://3dattack.us/3DAttack/Magazine.html
    I think it's an interesting topic for a lot of artists.

    Thanks again,
    Thomas
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Or you could just hit command-S to save, and not mess around with any scripts at all. Also that way you only ever have one file to worry about, not two.

    That's simply untrue. I just tested a 118MB PSD with a stopwatch, and it took 6.3 seconds to import. (And this is on a 6-year-old computer.) Most of my files aren't nearly that big, and take a second or two at most, usually less.

    You really need to turn off "compress textures when importing" in the preferences. I can't imagine working with that on; I prefer textures to update immediately, regardless of format.

    Er, no. When you save a file in Unity, the original version is still there, untouched. When you use DXT in Unity, PVRTC is used in Unity iPhone. They are both generated from the original, uncompressed image.

    Not running out of RAM and crashing is even better still. PVRTC isn't appropriate for all textures (particular GUI textures, where it can look pretty nasty), but you should use it when you can. One of my games is about 80-90% PVRTC and doesn't suffer for it. It would be about 20MB larger if I used uncompressed textures, and wouldn't run on anything older than an iPhone 3GS.

    I can't respond to that since I can't figure out what it means.

    I'm sorry, but you're factually incorrect on several points, so I have to point out that some of it is not very good advice. Not only have I tested this, but I've produced actual games.

    --Eric
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The one quirk with PSD and alpha is that you need to make sure there's an actual background layer. Sometimes it works without one, sometimes it doesn't, so it's best to always include one.

    --Eric
     
  10. StoneFish

    StoneFish

    Joined:
    Aug 26, 2012
    Posts:
    123