Author Topic: Rendering NGUI UI to render texture with opaque widgets  (Read 7959 times)

Steve Tack

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Rendering NGUI UI to render texture with opaque widgets
« on: August 26, 2013, 02:35:14 PM »
I'm working on a game where there's a literal HUD in a cockpit (as in, the UI is supposed to be projected onto a plane of glass in front of the player).  I have a "freelook" option where you can look around with a thumbstick or mouse and possibly eventually a VR headset.  When looking around, the HUD should stay in front on that pane of glass.

So I created a render texture that's generated from an NGUI UI.  It does work, but there's a problem with transparency.  The elements like labels that should be 100% opaque are partially transparent.  The closest Google hit I found was this:
http://www.beowulf99.com/blog/?p=1014

I think that might be outdated, as the shader referenced on that page does not seem to have Colormask RGB in it.  I'm running the latest NGUI version, so something may have changed since then.  I tried every combination of Unit shaders on both the atlas and the material with the render texture I'm using, but I can't seem to get the transparency to work correctly.

Is there a way to do what I'm attempting with NGUI and have it render the way I want?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Rendering NGUI UI to render texture with opaque widgets
« Reply #1 on: August 27, 2013, 02:42:14 AM »
It all depends on the shader you're using. All NGUI shaders are by default transparent, and don't write to depth. Write your own custom shader to suit your exact needs.

Steve Tack

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: Rendering NGUI UI to render texture with opaque widgets
« Reply #2 on: August 27, 2013, 11:04:24 PM »
Thanks for the reply!

As it turns out, the Google hits I read led me down the wrong path entirely.  The regular old Unlit/Transparent shaders work just fine for what I'm trying to do, as long as I set the UI camera's Clear Flag to "Solid Color", the background color to black, and the alpha to zero.  It also didn't help that I had forgotten I actually had some of my test labels set to semi-translucent, which threw me off.

Anyway, it's working great now.

Steve Tack

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: Rendering NGUI UI to render texture and linear color space
« Reply #3 on: September 12, 2013, 11:54:51 AM »
Had a follow-up question related to this.  I've started using an asset that requires linear color space to look its best, and now my NGUI-based render textures are getting *two* gamma corrections for color items using the color tint feature.  I'm using the color tint feature on some white font and sprite textures.  So, for example, if I want an orange color, I have to use an almost completely red color to get it to show up right.  RGB 255,32,0 tint renders as RGB 255,166,0.  I did the math, and that represents the color taken to the 1/2.2 (0.45) and then again.

That's using the settings I mentioned above (Clear Flag = Solid Color of black, zero alpha, Unlit/Transparent shaders on the texture atlas and material that uses the render texture.

Any idea what I can do?  I realize this might not be an NGUI issue, but I'm too much of a noob to know where the issue really is.

For now I can use colors that compensate for the double gamma correction, but that doesn't seem ideal.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Rendering NGUI UI to render texture with opaque widgets
« Reply #4 on: September 13, 2013, 09:52:09 AM »
NGUI is not meant to be used with linear space textures. You can specify "in linear space" option on the textures themselves, but I really have little experience with linear space lighting.