Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

RenderTexture Alpha Issue..

Discussion in 'UGUI & TextMesh Pro' started by guy_rabiller, May 28, 2018.

  1. guy_rabiller

    guy_rabiller

    Joined:
    Mar 22, 2018
    Posts:
    8
    Hi,

    I have a Canvas (Screen Space - Camera) and some Sprites, so most of the Canvas space is empty, ie, transparent. Then from the Render Camera, I render to a RenderTexture.

    Clear flags is a Solid black Color, with Alpha set to 0.

    Now, when I try to use this RenderTexture in another Canvas (Screen Space - Overlay) through a RawImage, there is no transparency what so ever, I only get my original sprites with a black background. I can't see through. I've tried to use the "Sprite-Default" material with the RawImage component but that does not help which makes me think there is no alpha in the RenderTexture, or the 0 Alpha set from the Camera solid color is not taken into account.

    What am I doing wrong ?

    Thanks,
    Guy.
     
  2. guy_rabiller

    guy_rabiller

    Joined:
    Mar 22, 2018
    Posts:
    8
    Anyone ? I can't believe being the only one having this issue, it is so easy to reproduce.
    It is a showstopper for me, can move forward in my project because of this.
    Is this a known bug ? Is there a workaround ?
     
  3. cleonsucks

    cleonsucks

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    6
    100% Opacity:



    50% Opacity:



    0% Opacity:

     
  4. cleonsucks

    cleonsucks

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    6
    Render Texture Settings:

     
  5. guy_rabiller

    guy_rabiller

    Joined:
    Mar 22, 2018
    Posts:
    8
    Thanks a lot for your input.

    I've checked my settings and I have exactly the same as yours, and it still does not work.

    Then I just realized I'm also using the "Post Processing Behavior" script on the UI Camera, the one that renders the texture. And for some reason, it destroys the alpha information. If I disable the "Post Processing Behavior" script then everything works correctly.

    Not sure if it is by design or if it is a bug.
     
  6. cleonsucks

    cleonsucks

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    6
    Hi Guy,

    It depends on which post processing effect you have active.
    The following ones will look correct with transparency: Fog, Ambient Occlusion, Screen Space Reflection and Motion Blur. The others operate on the entire texture.
    A way to get what I think you're after would be to clear the UI Camera to Skybox instead. Then the effect will also be applied to the portion of the Skybox shown in the Render Texture though.
    This is by design.
     
  7. guy_rabiller

    guy_rabiller

    Joined:
    Mar 22, 2018
    Posts:
    8
    Thanks again for the info.
    Perhaps a solution would be to have a script that "record" the alpha channel at some point of the stack then reapply it as the last step of the filter stack, overriding whatever has been done to the alpha channel. That would solve the issue.
    By any chance, do you know if such a script exist ?
     
  8. cleonsucks

    cleonsucks

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    6
    Hi Guy,

    I'm not aware of that, but the development of the Post Processing stack is open source on GitHub.
    You can follow it here and play around with it.
     
  9. guy_rabiller

    guy_rabiller

    Joined:
    Mar 22, 2018
    Posts:
    8
    Right, indeed.

    Thanks again.
     
  10. alfa1993

    alfa1993

    Joined:
    Aug 20, 2015
    Posts:
    26
    Sorry for waking up this thread.
    I am having problems when setting clear flag color alpha to 0. Other objects are not showing. I am using it on RawImage
     
  11. briancknapp

    briancknapp

    Joined:
    May 6, 2019
    Posts:
    1
    still having this issue. cannot render to texture with a camera that has post processing otherwise the render texture just gets a black background and then cannot overlay.
     
  12. conceptfac

    conceptfac

    Joined:
    Feb 15, 2018
    Posts:
    23
    ARGB3 doesn't exist in 2019.3 and alpha color doesn't have any effect
     
  13. Full_Tilt

    Full_Tilt

    Joined:
    Apr 25, 2018
    Posts:
    18
    Thank you, Guy, for your hint about post processing destroying the alpha information; that appears to have been the problem I was seeing. I can now render my camera 2 to a minimap over top of another raw image, via a render texture asset; and the render texture is now producing a transparent background. In this way, I can render (in my case) some labels over top of the minimap image by specifying a culling layer in the camera 2 settings. My minimap is a generated raw image as well because the world is huge and only part of the world is rendered according to the view.

    So, to summarize, in Unity 2019.2, I can render a transparent background from a rendertexture via a second camera if I set the rendertexture as RGBA (R8G8B8A8_UNORM), the camera clear flag as "Background" and set that background color as RGBA = 0000 "black with no alpha". The target raw image for the rendertexture is RGBA = FFFF "white with full alpha" with material "none". Finally, do not set a post processing effect on your camera unless you're sure it's one that will not affect your alpha, as discussed above. This last point was my final issue.

    Thanks to all here for the discussion.
     
    adamgryu and bearcoree like this.
  14. turen1234

    turen1234

    Joined:
    Apr 2, 2019
    Posts:
    2
    I was also having this problem, i upgraded to Universal Render Pipeline, then for the Render Texture's shader i set:
    Surface Type: Transparent,
    Blending Mode: Alpha

    Set the Camera output to Render Texture with solid colour black 0 alpha.
    and ensured that the object i was rendering also had a URP material assigned to it.
    that last step is that was causing the issue for me
     
  15. bcsquared

    bcsquared

    Joined:
    Jul 24, 2020
    Posts:
    4
    I'm running into this issue as well with 2021.3.18 where I cannot render a transparent background in my rendertexture.
    Did you create a new material, like URP/Unlit, then apply that material with the above settings to a RawImage in the Canvas? If so, I've followed the same steps after installing URP and updating materials to be URP compliant, but still have the issue of an opaque background.
     
  16. bcsquared

    bcsquared

    Joined:
    Jul 24, 2020
    Posts:
    4
    Never mind. I ended up finding that I had an image as a background on a panel that I was not accounting for. Dumb mistake SMH.
     
  17. CRISTALSONIC

    CRISTALSONIC

    Joined:
    Sep 22, 2016
    Posts:
    136
    what shader did you use ?
    that might be my problem but none of my options are working
     
  18. CRISTALSONIC

    CRISTALSONIC

    Joined:
    Sep 22, 2016
    Posts:
    136
    mine was working in 2019
    Screenshot 2023-06-14 195042.png

    but with 2022 is not
    Screenshot 2023-06-14 001539.png Screenshot 2023-06-14 195205.png

    not sure what else to change
     
    DrZwieback likes this.
  19. DrZwieback

    DrZwieback

    Joined:
    Mar 8, 2015
    Posts:
    6
  20. d1ke

    d1ke

    Joined:
    Apr 1, 2014
    Posts:
    5
    I faced same issue. In my case the problem was that I created a render texture with
    RenderTextureFormat.ARGBFloat. After I changed it to
    RenderTextureFormat.ARGB32, alpha became renderered correctly.
    Btw in Editor everything worked good even with ARGBFloat texture format. But not on my Android device.
     
    DrZwieback likes this.