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

BackBuffer ALPHA channel doesn't work on Android devices

Discussion in 'Android' started by GearedSun, Jun 22, 2014.

  1. GearedSun

    GearedSun

    Joined:
    Apr 17, 2014
    Posts:
    30
    Hi,

    After recent update from Unity 4.1.x to 4.5, I've found quite critical issue with frame buffer on Android devices.

    Repro:
    1. Set camera clear flags to solid color, as rendering path use Forward.
    2. Set the clear color ALPHA channel to something other than default 255, for example set it to 0
    3. Everything works on PC, alpha channel is cleared to 0
    4. Build an Android build and observe the alpha is cleared to default 255

    This did work on Unity 4.1.2 for sure. It's critical because it brings serious inconsistencies between editor and device builds...

    update: Looks like the alpha channel is not used at all. Even shaders can't blend with frame buffer alpha on Andorid, alpha is just always ONE.

    Using 32-bit Display buffer from build settings.
    Both devices have Android 4+

    Test devices for example Galaxy S2, Nexus 7, ...
     
    Last edited: Jun 23, 2014
  2. GearedSun

    GearedSun

    Joined:
    Apr 17, 2014
    Posts:
    30
    It seems to be even worse. If I create a full screen quad with shader, which writes zeros to FrameBuffer's alpha channel, result is the same. It even looks like Unity guys changed framebuffer format for Androids so it doesn't even use/have alpha channel anymore?

    Shaders really can't blend with frame buffer's alpha anymore. That is quite pissing. You could do very nice effects with that. And if you use it in editor, it works, so ES2 emulation doesn't work properly if that was intentional change.
     
    Last edited: Jun 23, 2014
  3. knowpixels

    knowpixels

    Joined:
    Oct 6, 2013
    Posts:
    4
    I am using MEAT5000 s amazing custom shader and have encountered similar issues.
    I have been able to test on more devices and can confirm that for the Nexus 10 pad and a Nexus phone as well as the Samsung Galaxy Note, that the Alpha is always set to 1 when the build is run on those devices where as the correct alpha value will be used fine in unity editor.
    Additionally I have also tested the same shader on the Sony Experia Z, Sony Experia Z1, Sony Experia Z Ultra and the Cubot One and these devices render the alpha channel values correctly using the exact same shader.
    My initial conclusion is that the GPUs / or Drivers in certain android devices does not or no longer supports alpha < 1 in shaders;
    I have tried allowing 24bit depth buffering as well as 32bit and that doesnt correct the issue.
    Any pointers from community members with more service level/hardware knowledge of different Android devices is probably whats required to resolve this issue :D
     
  4. GearedSun

    GearedSun

    Joined:
    Apr 17, 2014
    Posts:
    30
    Hi, I just want to point out, that it's most likely because of recent changes in Unity. My Galaxy S2 has the same Android v4.0.4 which I use for a long time. With Unity 4.1.x - 4.2.x build, alpha works correctly. With Unity 4.5.x it's always set to one. So same device, same game, different Unity version....

    It would be great if someone from Unity devs could make a statement on this.. they must know about this obvious bug. I just wanna know when is it going to be fixed.
     
  5. GearedSun

    GearedSun

    Joined:
    Apr 17, 2014
    Posts:
    30
    I did try Unity 4.5.1p4 but result is the same. How long could it possibly take to fix this....
     
  6. GearedSun

    GearedSun

    Joined:
    Apr 17, 2014
    Posts:
    30
    Still not fixed in Unity 4.5.2p1.
     
  7. GearedSun

    GearedSun

    Joined:
    Apr 17, 2014
    Posts:
    30
  8. GearedSun

    GearedSun

    Joined:
    Apr 17, 2014
    Posts:
    30
    Could somebody from Unity have a look into this? I even sent you a scene with 100% repro and very simple shader demonstrating the bug. It's all part of 620787. Or some time estimate would be nice, something.
     
  9. bitter

    bitter

    Unity Technologies

    Joined:
    Jan 11, 2012
    Posts:
    530
    Hi, sorry for the late reply. As you may already have figured out this was an intentional change - "Android: 32bit display buffer without alpha is now the default to avoid compositor bugs on android." (rel. notes 4.3)

    The thing is that a lot of devices have problems using alpha in the screen framebuffer. Prior to 4.3 alpha presence would be random depending on the device. While working on Unity 4.3 a version of JB was released that pretty much screwed up the alpha channel on all devices so at that point we decided to make it consistent/deterministic by disabling alpha in the default framebuffer.

    The only way to solve this problem right now (that I can see ) is to render to an intermediate rt and then blit to the screen as a last step. This might be something we will do behind the scenes in the future if we can find a way of detecting buggy compositors. But as of now you will have to do this yourself.

    ps. I didn't close the bug with "by design" because I would really like to find a solution to this problem.
     
  10. Sudhir-Singh2k2

    Sudhir-Singh2k2

    Joined:
    Dec 16, 2012
    Posts:
    9
    "The only way to solve this problem right now (that I can see) is to render to an intermediate rt and then blit to the screen as a last step. This might be something we will do behind the scenes in the future if we can find a way of detecting buggy compositors. But as of now you will have to do this yourself."

    Can you give example code of how to do this?
     
  11. GearedSun

    GearedSun

    Joined:
    Apr 17, 2014
    Posts:
    30
    Thank you for the reply. I mentioned the possibility it might have been "by desing" in my earlier posts. The problem is that right now there is a difference between editor and device. If it is changed by design, editor should work the same way. So you shouldn't be able to change the alpha channel in editor as well (if working on Android platform with emulation for example).

    Using separate RT is probably the first thing I would came up with as a workaround. Many users will not be able to use this because it is a PRO feature. Actually having alpha channel "free" for blending ops allowed nice effects even without PRO version. In my opinion, It's kind of step backwards, because engine should not limit users in such a basic thing as using alpha channel on back buffer. Especially if source codes are not available to public.