Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
xhonzi's avatar
xhonzi
Honored Guest
11 years ago

Draw 2D GUI Texture onto Quad Mesh?

viewtopic.php?f=41&t=7724

This is perhaps a repeat of my question in this other thread. I'm having trouble building a 2D texture (not material) to place on a plane or quad mesh. This is to draw some of the UI, but not on the Rift cameras themselves.

This is possible, right? Why is it so hard?

I can go more into what I've tried and what doesn't work, but I'm hoping someone can point to a short procedure on how it's done.

2 Replies

Replies have been turned off for this discussion
  • xhonzi's avatar
    xhonzi
    Honored Guest
    Alright.

    I've got this almost working.

    My biggest problem now is GUI.layer. I've got several different scripts making ONGUI calls writing to the same render.texture. since I was calling GL.clear before each one, only the top most layer ends up showing.

    If I remove the GL.clear, then I get a "burn-in" effect since the old layers never go away (thought they get drawn on top of). But all of the layers appear!

    So I need to call GL.clear once per frame- before all of the ONGUI calls. I thought making a script that makes a single GUIDraw call at GUI.layer 2000 (further out than all of my other GUI layers) and having it draw almost nothing- paired with a single GUI.clear after it would work... but so far no dice.
  • xhonzi's avatar
    xhonzi
    Honored Guest
    "xhonzi" wrote:
    So I need to call GL.clear once per frame- before all of the ONGUI calls. I thought making a script that makes a single GUI.draw call at GUI.layer 2000 (further out than all of my other GUI layers) and having it draw almost nothing- paired with a single GL.clear after it would work... but so far no dice.


    Still struggling with this. I stumbled upon WaitForEndOfFramehttps://docs.unity3d.com/Documentation/ScriptReference/WaitForEndOfFrame.html, and tried setting a bool that would cause the next OnGUI call (presumably the first of the next frame) to GL.clear before it drew anything else. I couldn't get it to work. I don't understand iEnumerators, so that's probably why.

    What sort of worked was setting that bool in the update() method on my mesh. I'm not sure when the mesh's update is called in relation to the GUI.draws... but it works- sort of. I have also tried lateupdate() and PreRender() (on a camera) to set the bool, but they all have the same "works- sort of" effect.

    What works- with a single rendertexture receiving several layers from several OnGui calls- I seem to be getting all of my layers. I might be missing some, but I haven't notitced anything yet.

    What doesn't work- in a scene with two rendertextures (a cutscene mesh with a texture and a GUI mesh with a seperate texture) the GUI texture's GL.clear isn't working correctly. The whole texture is black and opaque (instead of black and transparent) when nothing is drawn to the GUI texture. When GUI elements with transparent parts are drawn to the texture, those parts are transparent, but not the rest of the texture. When the cutscene is over and the cutscene mesh is disabled, then the GUI layer goes transparent.

    On a lark, I tried tying my GL.clear to the depth of the GUI elements instead, which also sort of worked, but ended up culling a lot of layers I needed. But that's the most successfull version of everything I've tried- though I suspect it's the most hacky.