Forum Discussion

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

DK2 and NGUI?

I seem to miss something how to get NGUI running with DK2. The OVRCameraRig seems to be omni-dominant and it doesn't let me control it's depth value so I could put the NGUI camera on top of it z-wise.

What I want is to be able to is to run my UI over the OVR Camera Rig to be able to fade out the menu to the Rift camera view.

I've tried also the variant to use a quad mesh on the right camera and a renderTexture, but this is not a preferred solution as the mouse Input is not aligned with the quad position and it makes the input handling unnecessarily complicated.

Anyone got NGUI working with sdk 0.4.3?

Thanks
Martin

4 Replies

Replies have been turned off for this discussion
  • Found out why. The new Oculus SDK renders into a RenderTexture. So setting the RenderQueue doesn't work out unfortunately here - camera depth neither.

    It was possible to put the NGUI UI as child of the right camera in the OVR camera rig at a distance of 1, but if you have geometry in front of the camera like me (sitting in a roller coaster), the object gets rendered in between the camera and the UI plane. Not a solution.

    I had the idea then to render NGUI out directly into the render texture of the right camera. Technically works, but the UI is rendered then half of the width in the middle of the screen. And it's only rendered to the right camera of course.

    I'm now experimenting with rendering NGUI to a render texture and then copying over the render texture over both render textures of the 2 OVR cameras. Will see if that works out.
  • Anonymous's avatar
    Anonymous
    Why not just use NGUI in world space mode? You can assign UI elements a material/shader that renders on top of the other world objects if you want it to act like an overlay and not clip. If you want to have a main menu that fades away, put everything on a canvas in front of OVR camera/player, and then use the alpha value of the UI canvas to fade the UI in and out from the world view.

    If you aren't too deep in with NGUI yet, you might also consider Unity's new UI stuff available in 4.6. I'm moving my project from NGUI to UI because I found NGUI unwieldy in places. I had to do quite a few hacks to make a NGUI look-based world-space input mechanism, and each time a new NGUI version came out I would have to merge in my hacks. It became too much of a pain for me to maintain.

    In case you want a reference to some of the NGUI hacks I did for look-based input, here is a post I made a while back on it:
    viewtopic.php?f=37&t=8966#p119425

    If you are interested in jumping to new Unity UI, I made a howto post about that here, including a sample project:
    viewtopic.php?f=37&t=16710

    ccs
  • The issue I have with world space rendering is that I had unwanted geometry in between the camera of the OVR rig and the actual canvas from NGUI. I have a complete menu being shown and want to have it displayed over the actual camera view.

    What kind of shaders are you talking about? Aren't the shaders simply setting the renderqueue up to something high like 7000 or 9000? That I tried already setting the renderqueue directly in NGUI.

    Did the shader thing work for you? What shaders did you use and where did you set them up?

    Thanks!
    - Martin
  • Anonymous's avatar
    Anonymous
    Hi Martin-

    NGUI comes with a set of shaders that it uses that you can modify. While the renderqueue can be set to have UI elements render last, the shaders still do Z testing, which will prevent pixels from rendering out so it looks like they clip and the geometry is rendered on top. To fix that, you simply need to modify the shaders that come with NGUI to not test Z, and they will always render on top.

    It is quite easy to fix them. You can find the shaders in NGUI/Resources/Shaders. The one that is used by a lot of things is Unlit - Transparent Colored.shader, but you can change all of them just in case you have elements that use the other shaders. I think most of the example resources/atlases that come with NGUI use that 1 shader though. To fix the shader to not do Z-testing, open up the shader in the editor, and after the "ZWrite Off" line, add a "ZTest Always" line. That tells shader to always write out the pixel and not do z-testing.

    ZWrite Off
    ZTest Always

    With this you will find all the UI elements are rendered on top of your geometry properly.

    Hope it works for you!

    ccs