Search Unity

Unexpected RendexTexture transparency behavior

Discussion in 'Universal Render Pipeline' started by matheus_inmotionvr, Sep 9, 2020.

  1. matheus_inmotionvr

    matheus_inmotionvr

    Joined:
    Oct 3, 2018
    Posts:
    63
    I currently use a RenderTexture to render my scene as part of the UI and I'm facing an unexpected (at least to me) behavior. My RenderTexture contains some transparency data that - in my opinion - should not be there. I created a small scene to demonstrate it.

    In the scene, there is a blue cube using an opaque material. Between the cube and a camera, there is a world space canvas with a semitransparent image. The camera's data is rendered to a RenderTexture. In another canvas (overlay), a RawImage renders the RenderTexture. The RawImage's alpha is set to 100%.

    Here's the scene:


    So in short, the Image is semitransparent, but the cube isn't. Here's the odd behavior: the Render Texture is semi transparent on the area of the image as well, even though there was an opaque object behind the image. Here's a preview of the RenderTexture's alpha channel:


    If I use this RenderTexture as a RawImage's source and there is anything behind the RawImage, I can see through it:

    That is not what I expected at all. I get it that RenderTextures can contain transparency data (alpha channel), but in my understanding, every pixel in that RenderTexture should have its alpha at 100% because there was an opaque object as a background. Therefore, my RawImage should not be transparent at all.

    I expected something like this, where objects behind the RawImage would nor be rendered:



    Am I missing something? Does anyone have any idea if this is the expected behavior and if so, why?

    Thank you in advance for the help.