Search Unity

fog in deffered

Discussion in 'Unity 5 Pre-order Beta' started by zelmund, Dec 1, 2014.

  1. zelmund

    zelmund

    Joined:
    Mar 2, 2012
    Posts:
    426
    fog doesnt work anymore in deffered lighting? or there is some information about difference betwen deffered and deffered legacy?

    video with issue
     
  2. Roni92

    Roni92

    Joined:
    Nov 29, 2013
    Posts:
    226
    Interesting looking game, what is it?
     
  3. zelmund

    zelmund

    Joined:
    Mar 2, 2012
    Posts:
    426
    this is just scene
     
  4. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    8,373
    I believe the built in fog isn't supposed to work in the deferred and you should use the fog post effect.
     
  5. zelmund

    zelmund

    Joined:
    Mar 2, 2012
    Posts:
    426
    but in unity4 its just works. why it doesnt in unity5 ?
     
  6. Void24

    Void24

    Joined:
    Oct 15, 2013
    Posts:
    50
    It is my understanding that in Unity4, fog was a function written into shaders individually. If you didn't write it into a new shader, it was not there.

    Unity5 uses a post effect to draw fog based on the deferred depth buffer. This will work regardless of your shaders used, you will never have a shader ignore the fog.

    In a way, this "just works" FAR better than it did in Unity4.
     
  7. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    5,840
    Except of course for geometry that doesn't write to the zbuffer.
     
  8. unicat

    unicat

    Joined:
    Apr 8, 2012
    Posts:
    416
    Doesn`t work here. I have attached the global fog script to my main camera. It only works in forward or legacy deferred mode. Not in deferred. I have ticked global fog in the lighting window. Do i miss something ?
     
  9. netvortex_dc

    netvortex_dc

    Joined:
    Jan 13, 2014
    Posts:
    126
    Fog is simply broken under deferred mode. I have the same issue as you do and switched my game back to forward rendering. Forget about "Global Fog" as it won't work on some objects and will result in odd looking scenes.
     
  10. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,760
    It does, just like your video shows... "deferred lighting" is what was in 4.x, and continues to exist in 5.0 under "legacy deferred" name.

    In deferred shading (new in 5.0), fog doesn't work simply because there's no place where to put it. We could add a manually implemented postprocessing effect to do fog, which would do exactly the same as adding your own GlobalFog postprocessing effect.

    The lighting window displays a warning when fog is enabled and deferred shading is used, suggesting to use GlobalFog effect.

    Same in Unity 5. Except in the (new) deferred shading, because see above.

    "Works for me". File a bug with a repro?
     
  11. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,760
    File a bug please.
     
  12. unicat

    unicat

    Joined:
    Apr 8, 2012
    Posts:
    416
    Filed a bug report: Case 660385
     
  13. seattlebluesky

    seattlebluesky

    Joined:
    Sep 2, 2014
    Posts:
    170
    Are your ImageEffects up to date for your version of Unity 5 Beta? I've been successfully using Global Fog as a camera post-effect in Deferred rendering mode for a while BUT I have been re-downloading 'Standard/Sample' assets for each Beta as they do get updated also from time to time.
     
  14. unicat

    unicat

    Joined:
    Apr 8, 2012
    Posts:
    416
    After doing a clean install of U5 b18 and using the fps controller from the sample assets it is working now.
    Thank you.
     
  15. AustinRichards

    AustinRichards

    Joined:
    Apr 4, 2013
    Posts:
    321
    I tried using the global fog camera effect. I found it is not nearly as nice as the old fog method. The old fog method allowed it to slowly get more dense, the global fog feels more like a wall of fog. I had to add the component twice, one closer and one farther to really get a smooth transition. One aspect I do like about it is the horizon seamlessly blends with the horizon unlike the old method, but I do think it is a bit more expensive.

    It takes about 0.2-0.25MS for me to process each global fog component.

    Here's a picture:

     
  16. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,760
    What is the "old fog method"?

    In any case, GlobalFog should match the built-in fog exactly - same fog modes, same density, same colors (with options for height-based fog and radial fog too).

    In any case. If you see weirdnesses with fog, GlobalFog (or well, anything else) where you have to resort to some horrible workarounds ("add fog twice to get transition") - file bugs with repro projects!
     
  17. AustinRichards

    AustinRichards

    Joined:
    Apr 4, 2013
    Posts:
    321
    You're exactly right, I was using the old global fog from Unity 4. Just updated it :)

    Edit: Transparent objects are practically impossible to use now though since fog completely doesn't affect them..... This isn't a solution...
     
    Last edited: Jan 5, 2015
  18. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,760
    Well, if you liked the old GlobalFog, you can just keep on using that.

    Not sure I follow. Regular built-in fog (i.e. the one that's part of the shader code) does affect transparent objects just fine. GlobalFog does not, by design (it's z-buffer based). In Unity 4.x, GlobalFog was wrongly drawn after the transparent objects, but using the distance of the closest opaque object behind all transparencies (so it was "applying fog" to transparencies, but in a wrong way). If you want to keep that "broken" behavior - sure, you can just keep on using the 4.x GlobalFog effect. Or change the 5.0 one to do that (comment out ImageEffectOpaque attribute in the script).
     
  19. seattlebluesky

    seattlebluesky

    Joined:
    Sep 2, 2014
    Posts:
    170
    To confirm the built-in fog doesn't work in Deferred rendering mode right?
     
  20. zelmund

    zelmund

    Joined:
    Mar 2, 2012
    Posts:
    426
    it is by using image effect.
    and yes, transparent (semitransparent, not cutout) objects are not affecting by post effect fog. cheked it... and got little frustration =((
     
  21. AustinRichards

    AustinRichards

    Joined:
    Apr 4, 2013
    Posts:
    321
    So if regular built in fog affects transparent objects, why can't the 5.0 post effect? We have now lost a necessary feature in deferred. Can the 5.0 post effect not also affect transparent objects correctly like the built in fog? Or is it just not possible in deferred shading?
     
  22. GixG17

    GixG17

    Joined:
    Aug 18, 2013
    Posts:
    102
    The only problem I have with the Unity5's GlobalFog is that, because it's z-buffer based, it's dependent on the draw distance of the camera. My current project dynamically changes the draw distance of a camera to reduce unnecessary draw calls (using the camera's frustum culling like a pseudo occlusion culling)... so the fog keeps getting closer or recedes depending on how far (or close) the draw distance is.

    P.S. I can't use Unity's built-in occlusion culling because my environment is created at run-time.
     
  23. netvortex_dc

    netvortex_dc

    Joined:
    Jan 13, 2014
    Posts:
    126
    You can utilize dynamic batching, i had the same problem. It only works below 320 Tris so instead of actually combining meshs split them and you'll have dynamic batching on them.
     
  24. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,563
    @Aras about the current global fog, in unity4 the height fog are affecting the skybox, but in unity5 it doesn't. Is there a way to get this effect back, something that i can change for this in the code somewhere?

    @Edit : Nvm.... got it :)
     
    Last edited: Jan 14, 2015
  25. GixG17

    GixG17

    Joined:
    Aug 18, 2013
    Posts:
    102
    Right, but then I'd have to work around the geometry limit as opposed to figuring out a way to get fog working... Thanks for replying but I'm afraid that what you're suggesting is merely replacing one annoyance with a major constraint; not to mention it still doesn't remove the need to have some form of occlusion culling.

    I wonder if I could get a fog-like shader to work on a distant object that's linked to the camera...
     
  26. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,760
    Yes, you could just keep using the old effect. Or change the current one to fog the "background" too (there's a check for depth being really close to "far plane" somewhere in the shader - removing that check should make it affect skybox).
     
  27. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,563
    Yup, i found the depth check part, i need the skybox to be affected since i want to add a simple hgphase function in the fog. And it works great :) , just need it to affect the transparent objects.
    Fog.PNG
     
    Whippets and Luckymouse like this.
  28. Luckymouse

    Luckymouse

    Joined:
    Jan 31, 2010
    Posts:
    484
    @rea Look nice.
     
  29. Whippets

    Whippets

    Joined:
    Feb 28, 2013
    Posts:
    1,775
    Holy cow that fog and lighting is awesome. Are you using your own effects for the fog, bloom, and lighting or is that Unity stuff?
     
  30. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,760
    Remove ImageEffectOpaque attribute from the image effect, if I understood your problem correctly.

    Screenshot looks very nice!
     
  31. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,563
    Thanks guys,
    @Whippets all built in, no bloom. only tonemapping and a slight modified global fog.
    @Aras sadly it's still doesn't looks right, is there a way to get the same fog in deferred just the same as using forward and legacy deferred?
     
  32. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    28,158
    Global image effect fog seems like a waste of performance and looks identical to vertex shader fog in a lot of cases. Would Unity consider injecting vertex colour fog? ie lerp to, or is this out of the question? I ask because it neatly solves issues with transparency and z buffer, and it's a lot of work having to replace unity built in standard shader with a surface shader version.
     
    Reanimate_L likes this.
  33. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,563
    That could be a great workaround actually as long as the fog are flexible and accessible script, ie can be a used to deal with SSAO by using the fog buffer to fade the SSAO intensity.
     
  34. nickpettit

    nickpettit

    Joined:
    Dec 31, 2013
    Posts:
    33
    @Aras So, I think I may have found a bug in Unity 5.0.0f1 but I'd like an expert to confirm.

    When using deferred rendering, the Global Fog image effect does not properly occlude ambient lighting or directional lighting that intersects the far clip plane. In fact, it might not occlude geometry that intersects the far clip plane at all, and perhaps turning off any nearby lighting just hides it. I have some screenshots that demonstrate the problem (you'll need to zoom in to see). Notice the thin line running across the Game window; that's where the camera's far clip plane intersects a Terrain object and some geometry that are both lit by ambient light and a directional light.

    The first screenshot has all image effects turned off so you can get a sense of the scene.

    The second screenshot has all image effects turned off (except for the global fog) to help demonstrate the issue.

    The final screenshot has all image effects turned on. Fog is disabled in the render settings in this screenshot, but I found that enabling it seems to remove the problem from the terrain, but the blue directional light is still visible on the geometry that intersects the far clip plane.

    image_effects_off_and_global_fog_off.PNG image_effects_off.PNG image_effects_on.PNG

    Am I just doing it wrong? :) I'm happy to take more screens or zip up the entire project if you need more information.
     
    Last edited: Feb 13, 2015
  35. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,760
    Can you file a bug report with the repro?
     
  36. nickpettit

    nickpettit

    Joined:
    Dec 31, 2013
    Posts:
    33
    @Aras Sure, no problem. I included my description and screenshots, and Unity is packing up the 8GB game now. I'm assuming there'll be a sharable bug report link when it's done, so I'll post it here if you want to take a look yourself.

    Edit: It has been filed http://fogbugz.unity3d.com/default.asp?672106_dro2ums4suc7gnpo
     
    Last edited: Feb 13, 2015
unityunity