Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Questions About ASTC Format

Discussion in 'General Graphics' started by flyingSnowhu, Sep 18, 2019.

  1. flyingSnowhu

    flyingSnowhu

    Joined:
    Feb 19, 2019
    Posts:
    7
    As OpenGL Wiki says:
    https://www.khronos.org/opengl/wiki/ASTC_Texture_Compression
    ASTC provides different color channel configures. It seems all 4 channels are correlated in Unity.
    So How can I switch to another, RGB+A or even R only?

    And, How Can call SetPixels() to an ASTC Texture2DArray? It always complains that "Unsupported TextureFormat(48) for SetPixel operations."
     
  2. Shane_Michael

    Shane_Michael

    Joined:
    Jul 8, 2013
    Posts:
    158
    I remember this coming up in another thread, and a Unity employee responded that it was basically a limitation of the UI right now--ASTC has so many options it would clobber everything else in the drop-down. Unity should auto-select between RGB and RGBA if you disable alpha in the texture settings, but I would also appreciate a bit more control. Adding a second or even third drop-down menu shouldn't be too difficult.

    To copy one into a Texture2DArray, Graphics.CopyTexture() should do the trick.
     
  3. flyingSnowhu

    flyingSnowhu

    Joined:
    Feb 19, 2019
    Posts:
    7
    Thank you. That's so funny, they can put a few options on GUI and more details in API. We need four uncorrelated channels for metallic+smooth+normal, but now the normals are rendered badly.

    And for the latter, Graphics.CopyTexture() can only copy between similar formats, such as RGBA32 and ARGB32. I couldn't find any such way to copy a png/tga asset to an ASTC formatted Texture2DArray.
     
  4. Shane_Michael

    Shane_Michael

    Joined:
    Jul 8, 2013
    Posts:
    158
    It operates directly on the GPU memory so I was under the impression it should work as long as the source and destination are using the exact same format including any block-based compression (as long as you don't try copying partial blocks).

    Though it's been a while since I dealt with the actual code for this so it may be easier to simply copy over uncompressed data and compress the texture array after the fact.

    I've been using "Texture Array Inspector" which is just a few asset that makes dealing with texture arrays a bit more convenient. Comes with an api and an inspector so you can see what your texture array actually looks like in the editor.

    One of ASTC's greatest strengths is its flexibility so it is a real shame they don't expose more of it in the API.
     
  5. flyingSnowhu

    flyingSnowhu

    Joined:
    Feb 19, 2019
    Posts:
    7
    I've got the solution for the 2nd problem:
    pixels in Color[] ->
    RGBA32 format texture by SetPixels->
    get ASTC format texture by EditorUtility.CompressTexture ->
    copy to TextureArray by Graphics.CopyTexture

    Thank you @CaptainScience !
     
  6. MatL

    MatL

    Joined:
    Jan 29, 2014
    Posts:
    43
    There is no disable alpha for the Altases, I can't make the Atlases without the alpha channel.
     
  7. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,366
    The ASTC format doesn't differentiate between RGB and RGBA textures. All ASTC textures are RGBA. Each block within the texture deciding whether to encode itself as RGB+A, RGBA, RGB, X+Y, or L component layout based on the content within the block rather than chosen by the user. However the image sampled in the shader will always return a full RGBA value (as is true for any GPU image format). Some image encoders allow you to choose profile hint that prefers a specific layout mode, but it's still up to the encoder to make the decision. I don't know of any that let you force an explicit component layout for all blocks.