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. Dismiss Notice

Question Can ImageConversion.EncodeToPng() do 16 bits per channel

Discussion in 'General Graphics' started by Addie, Jan 31, 2022.

  1. Addie

    Addie

    Joined:
    Jan 24, 2015
    Posts:
    8
    Just wondering if anyone knows if textures created from scripts can be saved with more bits per channel than RGBA32. I tried using ImageConversion.EncodeToPng() with both RGBA32 and RGBAHalf, after saving to disk and then checking the file explorer the file size was the same for both formats.

    I know ReadPixels works for both RGBA32 and RGBAHalf but can unity encode the result with ImageConversion.EncodeToPng() to a 16bpc format if the texture is RGBAHalf.
     
  2. jonaskhalil

    jonaskhalil

    Unity Technologies

    Joined:
    Apr 6, 2019
    Posts:
    30
    Hi Addie, I had a quick look at our source code and it looks like this is indeed not supported. Double-checked our docs and it looks like these could be a little more explicit as well ...

    But, just to confirm, encoding to PNG will store the results in 8bpc RGB or RGBA depending on the presence of an alpha channel. The only exception: single-channel input will be stored in grayscale mode, and GraphicsFormat kFormatR16_UNorm will actually store it's result in 16bpc grayscale.

    JPEG and TGA do not support 16bpc at all; does EXR's 16- and 32-bit support help you in any way (with EXRFlags.OutputAsFloat to go to 32-bit)?
     
    Addie and bgolus like this.
  3. Addie

    Addie

    Joined:
    Jan 24, 2015
    Posts:
    8
    Hi thanks for the reply, i am aware of EXR supporting 16bpc and 32bpc, i was just wondering if unity's ImageConversion.EncodeToPng() could do 16bpc with the graphics format RGBAHalf or equivalent GraphicsFormat.R16G16B16A16, but as you said it doesn't. Again thanks for the info.