Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Using Render Textures on a uGUI Image, Panel or Button?

Discussion in 'UGUI & TextMesh Pro' started by infinitypbr, Oct 5, 2014.

  1. Armageddon104

    Armageddon104

    Joined:
    Sep 14, 2014
    Posts:
    22
    Sorry to bump this but did anyone every find a solution? I tried using the fixes here:

    http://forum.unity3d.com/threads/render-textures-are-transparent.4972/

    But it didn't work, and nothing in this thread has worked either. When I encode the RT to PNG with a Texture2D I get a very very faint image that's almost entirely transparent. If I stack it a bunch it gets to looking semi-normal though.

    I've asked a question here too:

    http://answers.unity3d.com/question...esnt-capture-image-effect.html#answer-1039261
     
  2. Ferb

    Ferb

    Joined:
    Jan 4, 2014
    Posts:
    25
    I had a problem like this today - the problem for me was simply that it turned out I was drawing some transparent stuff to the camera. That problem wasn't noticeable on the Main Camera, or in most of the inspector views - you can draw a bunch of stuff in RGBA(1,0,0,0) (transparent red) to the main camera and as long as your shader isn't using alpha-blending, it will just look like opaque red (because a shader without alpha-blending will still overwrite anything else with the transparent red, making red the colour you end up seeing). Draw that color to a render-texture, and the inspector view will show both in the render-texture inspector and in the render camera preview that the image is just red. But it's still actually transparent, as you'll discover if you try to draw your rendertexture on a GUI-panel, or use it in any other shader that does use alpha-blending. The only inspector view that did show that it was actually transparent was the view at the bottom of the GUI RawImage component to which I had attached the RenderTexture.
     
  3. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    Has anyone tried that shader solution I posted on the first page?
     
    karmington2 and twobob like this.
  4. Ferb

    Ferb

    Joined:
    Jan 4, 2014
    Posts:
    25
    Yes, that works too. I think I must have accidentally overlooked it when looking for a solution because the post was so short in between all the long ones! I've applied your shader as well now, so I don't need to worry about any future stuff appearing on my render texture that has different alpha values again.
     
  5. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    nice just wondering since people were still asking.
     
    karmington2 and twobob like this.
  6. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,924
    2018/2019 and this appears to still be unfixed in core Unity.

    Reproduction:
    1. Create a Camera + RenderTexture + RawImage at runtime and display on a Canvas
    2. If the Camera is rendering objects with Standard Shader, everything works (this apparently has now been hacked by Unity, but not fixed, because..)
    3. ...If you create a Unity-provided StandardShader and enable transparency ... the editor shows 3D renders, but 2D is blocked, and nothing renders in Scene view canvas nor in Game view canvas (but it does appear in Scene view 3D)
    4. if you use the workarounds in this thread (e.g. assign a fake empty Material to your RawImage, to trigger some interanl UnityEngine hack that fixes internal bugs), the editor shows 3d renders, and 2D renders ... but the game view still fails with nothing rendered.

    Solution:

    There appear to be not one but TWO hacks in current (2018, 2019) UnityEngine, both of whcih you need to trigger to fix the bugs here:

    A. DO NOT CREATE A MATERIAL IN SCRIPT: if you do, the Unity hacks only partially fire. They render correctly in Editor, but NOT in UnityGUI (go figure...). Instead create a dummy "empty" material in your project (call it "magic unity bug material" or similar ;)) that uses a Standard Shader with all default settings. This will work, while doing the exact same thing in script will only HALF work.
    B. Assign that material at runtime to your RawImage, and the other Unity hack will fire, and you will see your texture render correctly in UnityGUI, both in Editor/Scene view, and in Game view.
     
    Zante likes this.
  7. drew55

    drew55

    Joined:
    Dec 13, 2017
    Posts:
    44
    THANK YOU for being sweet and kind to save us from that time suck.