Search Unity

Render Texture alpha channel ignored on iOS devices

Discussion in 'Image Effects' started by country_dragon, Mar 6, 2019.

  1. country_dragon

    country_dragon

    Joined:
    Jun 26, 2014
    Posts:
    7
    Hi

    I'm rendering a UI canvas to a render texture (via manually calling myCamera.Render) where the canvas render mode is set to 'Screen Space - Camera'. The camera clear flags are set to 'Solid Color' with a background color of transparent black i.e. (0,0,0,0). The camera also has a custom image effect (which uses a shader that preserves the alpha channel of _MainTex and is set to Blend SrcAlpha OneMinusSrcAlpha). The render texture is set to RenderTextureFormat.ARGB32 with 32 bit depth (I've also tried 24 and 16 depth). In the editor this works as intended - my UI elements are rendered to the texture with a transparent background, which I can then blit over other render textures to composite my final image. However, on iOS devices (with Metal) the alpha channel appears to be ignored and the background is opaque black.

    I've only recently upgraded to 2018.3.6f1 and this used to work fine back in 5.5.4f1. Has anyone else been having similar problems with the alpha channel being ignored? I've come across the same problem in older forum posts but it sounds like this was a problem people were having even when running in the editor and it was solved by simply setting the render texture format to RenderTextureFormat.ARGB32. This is not working for me on iOS devices. I've even tried manually clearing the render texture alpha channel using GL.Clear(bClearDepth, bClearColor, Color.clear) but to no avail.

    Any help appreciated as this is preventing me from releasing an update of my app on the app store.

    Thanks
     
  2. country_dragon

    country_dragon

    Joined:
    Jun 26, 2014
    Posts:
    7
    Still broken in 2018 3.8f1. Why has this stopped working? Has 32 bit color buffer been disabled for iOS in latest Unity versions?
     
  3. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,791
    It is working for me. I don’t know if it was my posts you saw, but in my case the issue was that I was using RemderTexture.Default and that at some point changed to mean BGR101010_XR.

    After manually changing it to ARGB32 it does work properly for me. I am not using a canvas though, maybe that’s he culprit?

    Please do a bug report.
     
  4. TheGraficalOne

    TheGraficalOne

    Joined:
    Feb 14, 2014
    Posts:
    50
    Was this ever solved?
     
  5. Vaibhav_77

    Vaibhav_77

    Joined:
    Feb 5, 2019
    Posts:
    2
    any solution?
     
  6. country_dragon

    country_dragon

    Joined:
    Jun 26, 2014
    Posts:
    7
    Unfortunately not. The alpha channel is ignored when rendering to a texture. This change in behaviour appears to be intentional - most likely an optimisation for mobile platforms. I ended up working around the limitation by adjusting how my UI effects were achieved thereby allowing me to just draw the UI directly on top of the rendered scene without the need for intermediate render textures.
     
  7. country_dragon

    country_dragon

    Joined:
    Jun 26, 2014
    Posts:
    7
    Afraid not. I just worked around the limitation to achieve the same result without rendering to intermediate render textures.
     
  8. martin_mws

    martin_mws

    Joined:
    Jan 8, 2020
    Posts:
    5
    In case anybody still has this issue:
    On iOS using 2018.4.22: If the camera with a render texture has Allow HDR checked, then using ARGB32 on will discard alpha (and probably use the 10 bit RGB format).
    Switching to ARGBFloat or unchecking Allow HDR will render the alpha properly.
     
    IgorAherneBusiness likes this.
  9. asa989

    asa989

    Joined:
    Dec 18, 2015
    Posts:
    52
    Changing color format from 32 to 16bit fixed it for me. it works with HDR when using URP!
     
    IgorAherneBusiness likes this.
  10. sycori

    sycori

    Joined:
    Oct 3, 2020
    Posts:
    1
    Took me a whole day to figure it out, on IOS the background didn't have the alpha channel, FINALLY SOLVED!
    Graphics -> IOS -> HDR mode = FP16. I hope I helped.