Author Topic: NGUI and Global fog  (Read 6897 times)

nopecio

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 37
    • View Profile
NGUI and Global fog
« on: March 31, 2014, 07:06:43 PM »
Hi, i know all the image effects must be applied to the NGUI camera (a 3d camera in my case), but i can't get to work the global fog image effect, no matter the camera i'm attaching the effect to.
Is there a workaround this?
All the best!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI and Global fog
« Reply #1 on: April 01, 2014, 08:00:32 AM »
Anything that uses depth needs to go on the main camera, not NGUI's camera. In fact, all image effects should go on the main camera unless you want your UI to be affected by it. If you do -- why? Why would you want your UI to be affected by fog?

nopecio

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 37
    • View Profile
Re: NGUI and Global fog
« Reply #2 on: April 01, 2014, 03:29:15 PM »
Well, i don't want any fx affecting my UI, but if i put my fx on the main camera, as soon as i enable the GUI camera (2 cams,  3d and  2d) all my effects are somehow overriden and just ignored on the final composition.
I'm using vignetting which is working if i put it on the UI cam (but it affects my UI as well), but fog, i can't get it to work.
If this is not the right setup, how can i get the fx working along with the ui? I'm on ios BTW.
Thanks for your help!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI and Global fog
« Reply #3 on: April 02, 2014, 06:19:30 PM »
To get a vignette effect you can simply overlay a full-screen sprite using NGUI that has darkened corners. In fact many of the examples and all of the Tutorials that come with NGUI have a vignette effect done using a sprite.

The UI camera clears depth, which will break your fog. This is why the effects must be on the game camera. The order should be:

1. Main Camera draws the world.
2. Image effects get applied to what was drawn.
3. UI camera clears the depth and draws the UI.

I see no reason why this simple setup wouldn't work in your case. Can you post pics of both of what inspector looks like for each of your cameras?

nopecio

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 37
    • View Profile
Re: NGUI and Global fog
« Reply #4 on: April 03, 2014, 09:23:35 PM »
HI, thanks for your answer. I'm attaching a screenshot of my maincamera and my UI camera. The fog on the maincamera works fine until i activate the second camera :S
All the best!

EDIT: When i change the UI camera from perspective to Orthogonal my fog is back!
Does this gives you any hint on the issue?

« Last Edit: April 03, 2014, 09:29:33 PM by nopecio »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI and Global fog
« Reply #5 on: April 03, 2014, 09:28:34 PM »
Looks fine to me, aside from your background clearing color. It should have alpha of 255, not 5 (it's an old Unity bug -- default color has alpha of 5/255, which caused problems on some mobiles).

In any case... Just create an empty repro case with the main camera, fog on it, and a secondary camera that doesn't do anything (or maybe just shows one object), and submit it as a bug to Unity or ask on the Unity questions because this is something in Unity, not NGUI.

nopecio

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 37
    • View Profile
Re: NGUI and Global fog
« Reply #6 on: April 03, 2014, 09:35:09 PM »
Thanks i'm not sure if you saw my edit, but i'll post it here, just in case.
I found that if i change the camera from perspective to orthographic the fog is displayed normally.
I changed the alpha on the background color, but it didn't make any difference.

Do you think the perspective mode is the issue here? (my main UI is 3d BTW, i can't change it :( )

EDIT: Yes, you're right, this is a unity bug!, thanks for your help
« Last Edit: April 03, 2014, 09:40:17 PM by nopecio »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI and Global fog
« Reply #7 on: April 03, 2014, 09:43:49 PM »
Make sure your UI camera isn't tagged as "MainCamera". If that ain't it then yes, bug-report it. Especially considering that it works with ortho but not perspective.