Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[SOLVED] Detect when Texture has alpha channel

Discussion in 'Editor & General Support' started by kjuanlu, Jun 20, 2012.

  1. kjuanlu

    kjuanlu

    Joined:
    Dec 4, 2011
    Posts:
    100
    Hello all!

    I´m working on each gpu type on Android plaftorm, so I´m using a custom OnPreprocessTexture like this:

    Code (csharp):
    1. class MyTexturePostprocessor extends AssetPostprocessor {
    2.  
    3.  
    4.     function OnPreprocessTexture () {
    5.    
    6.  
    7.             var importer : TextureImporter = assetImporter;
    8.  
    9.             var textformat : TextureImporterFormat;
    10.             var textSize : int;
    11.            
    12.             if ( importer.GetPlatformTextureSettings("Android",textSize,textformat) == false ){
    13.            
    14.                 importer.SetPlatformTextureSettings("Android", importer.maxTextureSize, TextureImporterFormat.ATC_RGBA8);
    15.                
    16.             }
    17.            
    18.            
    19.     }
    20.    
    21.    
    22.    
    23.    
    24. }
    I want to set a ATC_RGBA8 format for textures that it has alpha channel, but I want to use ATC_RGB4 to textures that it has no alpha channel.

    How can I detect the presence of alpha channel on a texture?


    Thanks
     
    Last edited: Jun 20, 2012
  2. kjuanlu

    kjuanlu

    Joined:
    Dec 4, 2011
    Posts:
    100
    TextureImporter.DoesSourceTextureHaveAlpha :)

    Thanks
     
  3. cedw032

    cedw032

    Joined:
    May 31, 2013
    Posts:
    4
    Does this detect if there is an unesed alpha channel? For instance, the case where every pixel has 0xFF alpha?
     
  4. pweeks

    pweeks

    Joined:
    Mar 29, 2011
    Posts:
    104
    i'd also like to know this