Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Transparent RenderTextures

Discussion in 'Graphics Experimental Previews' started by garryjnewman, Jun 18, 2019.

  1. garryjnewman

    garryjnewman

    Joined:
    Sep 11, 2015
    Posts:
    30
    We render to a render texture to get the player model rendered over the UI. This worked in the old pipeline by setting the clear colour to fully transparent.

    In the new pipeline this doesn't see to work:

    ef303f43-25fe-4a49-ba23-b91be884c4bc.jpg

    Is there a hidden setting to do this?
     
  2. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    490
    Just set the alpha of background color of the camera to 0
     
  3. garryjnewman

    garryjnewman

    Joined:
    Sep 11, 2015
    Posts:
    30
    I am doing that
     
  4. Zipe92

    Zipe92

    Joined:
    Mar 5, 2015
    Posts:
    26
    Setting the alpha of the background color to 0 worked until Unity 2018.3, in the HDRP for Unity 2019.1 it doesn't work (or at least it didn't work last time I tried it, 2 months ago).

    I thought it was a bug and I sent a bug report to Unity, they answered me: "we plan to use the alpha channel of the color buffer for future features, we cannot support the output of alpha channel in a render texture. For now, the issue will be present but you can expect new features that will account for the desired behavior in this case"

    You can also find my bug report in the issue tracker: https://issuetracker.unity3d.com/is...ble-is-ignored-when-using-hdrp-5-dot-10-dot-0

    If someone has a fast workaround would be fantastic, currently I'm stuck with Unity 2018.3 for this problem.
     
    PixelJ and garryjnewman like this.
  5. garryjnewman

    garryjnewman

    Joined:
    Sep 11, 2015
    Posts:
    30
    I've managed to hack it for now, it's not ideal but I wrote a greenscreen shader which sets alpha to 0 if it's bright green. It's not ideal but it's a stop gap until there's a real solution.

    c9d9f721-1b45-4373-9484-ec471847015a.png
     
  6. DGordon

    DGordon

    Joined:
    Dec 8, 2013
    Posts:
    445
    We're creating prerendered images, so I'm rendering the camera twice: once with black and once with white. Then I compare the pixels ... if the black background has a pixel == to black and the white background == white, then I know its pure transparent. If both black and white textures have the same pixel color, I know its pure opaque. Im faking alpha value by just taking the difference from the grayscale values. Its good enough to make my textures work.

    But yes. This is absolutely stupid. Really ... there should be a better way of handling this. Considering Unity is moving to doing more things than just games, this feels like a step backwards ... hopefully they actually give us a built in way to get the real alpha values per pixel for a transparent background. I don't care how, it should just be an option somewhere, some how.
     
  7. PixelJ

    PixelJ

    Unity Technologies

    Joined:
    Nov 1, 2018
    Posts:
    196
    I just ran into this. Using universal it looks fine in the editor but doesn't work in a build... sigh
     
    Zipe92 likes this.
  8. PixelJ

    PixelJ

    Unity Technologies

    Joined:
    Nov 1, 2018
    Posts:
    196
    Could you share the shader and what you're attaching it to?
     
    salmanhayat16 and Zipe92 like this.
  9. garryjnewman

    garryjnewman

    Joined:
    Sep 11, 2015
    Posts:
    30
    I render to a RT with a fixed colour background, then render that RT via the UI system using a custom shader that draws transparent if matches that colour.
     
  10. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,727
    Yeah that's the general advice I've been dishing out too, it's cos HDRP just reserves camera alpha if I'm not mistaken, assuming you're on HDRP that is and not builtin or other.
     
  11. PixelJ

    PixelJ

    Unity Technologies

    Joined:
    Nov 1, 2018
    Posts:
    196
    That's exactly what I ended up doing! Thanks!
     
  12. karl_kent

    karl_kent

    Joined:
    Feb 1, 2018
    Posts:
    10
  13. ventzs

    ventzs

    Joined:
    Oct 30, 2012
    Posts:
    2
    Any update here? The issuetracker is closed for this one, but i still can't find a solution from unity in the final 19.3 release.
    My list of roadblocks for HDRP is not getting any shorter. I don't want workarounds for what were standard features for years.
     
  14. Grimreaper358

    Grimreaper358

    Joined:
    Apr 8, 2013
    Posts:
    698
    @garryjnewman @karl_kent @ventzs

    To use alpha with render texture you need to be using a version of HDRP with 2019.3. So HDRP 7.x.x then you go to the HDRP asset and change the Color Buffer Format to R16, By default all projects are using R11.

    Unity_2020-01-12_10-47-31.png
     
    zoooom likes this.
  15. Bartosz-Bieszka

    Bartosz-Bieszka

    Joined:
    Sep 12, 2015
    Posts:
    9
    and do not using Antialiasing and bloom post process, will work fine :)
     
  16. salmanhayat16

    salmanhayat16

    Joined:
    Nov 19, 2018
    Posts:
    2
    Could you tell how did you do thst?
     
unityunity