Search Unity

Transparency issue with RawImage + Render Target

Discussion in 'Unity UI (uGUI) & TextMesh Pro' started by lozfight, Sep 4, 2019.

  1. lozfight

    lozfight

    Joined:
    Sep 2, 2012
    Posts:
    5
    Hi! I'm rendering a preview of a character with a dedicated 3d camera to a render target and present it in the UI with a RawImage component. The camera has a color background with alpha 0 so it doesn't appear in the UI. It works fine in the editor but doesn't on a build (neither in windows or android).

    I'm using the lightweight rendering pipeline.

    This is how it looks when playing from the editor vs playing from a build:

    Capture.PNG Capture2.PNG

    The background alpha is gone! Any thoughts on my would that happen?


    Lets follow the configuration step by step:

    The render target:

    upload_2019-9-4_12-29-9.png

    The camera:

    upload_2019-9-4_12-29-48.png

    The Image:

    upload_2019-9-4_12-31-6.png

    (That material is set to use the UI/Default shader)
     
  2. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    692
    did you try different color formats for the render texture? like ARGB32?
     
  3. lozfight

    lozfight

    Joined:
    Sep 2, 2012
    Posts:
    5
    Hi! Thanks for your response!

    Yes, I tried but I got the same result: working as expected on editor, showing the background as solid color on build.
     
  4. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    692
  5. lozfight

    lozfight

    Joined:
    Sep 2, 2012
    Posts:
    5
    Thank you Hosnkobf but none of those worked. My guess is that this behavior is specific of the LWRP.

    Using renderDoc I spotted that in the final blit pass of my character camera the input is correct and the alpha is 0, but the output is incorrect, with alpha 1. For this Draw call it's using the shader "Hidden/Lightweight Render Pipeline/Blit".
    Knowing this I tried to use instead a Custom Render Target with a transparent material, but the result is exactly the same.

    I will try this in a new clean project LWRP based and test again to report a bug if its still happening.
     
  6. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    692
    I guess you need to switch to standard Render Pipeline or make a custom RP based on LWRP.
     
  7. lozfight

    lozfight

    Joined:
    Sep 2, 2012
    Posts:
    5
    I tracked down the issue from an empty project:

    Same configuration (this time I turned off the "Opaque texture" option in the character camera, that was causing this issue).
    I'm using a LightweightRenderPipelineAsset to configure the render. As long as I keep "Renderer Type" to "ForwardRenderer" or use an empty custom forward renderer the raw image keeps the alpha.

    As soon as I add a default render feature to the custom forward renderer the alpha is gone. (keep in mind: this only happens on a build and not in the editor)

    upload_2019-9-11_11-54-53.png

    Why is this happening? Do I need to include a special Renderer feature to keep the alpha on that rawImage? Which configuration should that have?

    Can I upload here the test project to ilustrate the issue?