1
\$\begingroup\$

Unity has both TextureFormat.ARGB32 and TextureFormat.RGBA32.The document says it's 8bit each channel in [0..1] range. But what are these formats exactly? 8bit is usually [0..255]. Do they just represent [0..255] divided by 255?

Also why are there both ARGB32 and RGBA32? When should I use which?

\$\endgroup\$
5
  • \$\begingroup\$ It seems like the documentation pages you linked explain the difference pretty explicitly: one is laid out in memory with alpha first, then red, green, blue. The other is laid out with red first, then green, blue, and alpha last. They also recommend using RGBA since that memory layout better matches what graphics APIs expect. You've also reasoned for yourself how to interpret 8 bits as a number in the [0, 1] range. So what specifically do you need from answers that's not explicitly stated in the docs or already explained in your question? \$\endgroup\$
    – DMGregory
    Dec 1, 2022 at 19:34
  • 1
    \$\begingroup\$ @DMGregory I mean if RGBA32 is the "more efficient" one, why ARGB32 exists? Not only it exists, but it's the default format when creating a RenderTexture. So there must be some reason ARGB32 is better than RGBA32 in some cases, right? If the only difference is "RGBA32 is more efficient", then the only logical conclusion is Unity is specifically defaulted to be not efficient. \$\endgroup\$
    – Kodra
    Dec 1, 2022 at 21:21
  • 1
    \$\begingroup\$ It exists because some tools and pipelines output or expect it, so to be able to inter-operate with this existing tech, you want to be able to produce and consume data in that format. "Why is ARGB32 the default" is not a question that appears in your post above. Generally questions about "why is the API implemented this way" need to be directed to the API developers themselves. Users of the API can usually only speculate about the reasons why certain design decisions were taken. \$\endgroup\$
    – DMGregory
    Dec 1, 2022 at 21:50
  • \$\begingroup\$ To be fair the docs say "RGBA32 format might be slightly more efficient". And that difference wasn't always called out in the docs, so it may have arose over time as both Unity & graphics hardware evolved. \$\endgroup\$
    – Pikalek
    Dec 1, 2022 at 22:05
  • \$\begingroup\$ Also, despite RenderTextureFormat.Default's documentation saying "Typically this is ARGB32 format", in a quick test I've just done the default I got on Windows was R8G8B8A8_SRGB (ie. RGBA order). So it could simply be that this "typically" line is misleading, not that there's any real pessimization in the API. Maybe what the doc-writer meant was "this will be a format with R G B and A channels at 8 bits per channel", and didn't mean to specify ordering, since RenderTextureFormat has no RGBA32 member to link to. \$\endgroup\$
    – DMGregory
    Dec 1, 2022 at 22:14

0

You must log in to answer this question.

Browse other questions tagged .