Search Unity

Extended Global Fog (Unity5)

Discussion in 'Works In Progress - Archive' started by Reanimate_L, Mar 24, 2015.

  1. Luckymouse

    Luckymouse

    Joined:
    Jan 31, 2010
    Posts:
    484
    Of course you can add it to your shader. Just do what you can to improve your shader! Please don't ask me again if i mind..:p

    [Edit]
    Btw, the problem of scattering is in front of the tree (or transparent material) that antislash mentioned, I guess maybe the [ImageEffectOpaque] has been comment out in the GlobalFog script cause that issue.
     
    Last edited: Apr 23, 2015
  2. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Awesome thanks man :)
    btw why not divide the dpth?
    by using this i got a falloff effect for the distance scattering
    Code (csharp):
    1. saturate( dpth - 0.5 )
    and about the [ImageEffectOpaque]. . . . i don't even remember why i comment those :p

    @Elecman : Turned out they fixed the double fog in the latest unity 5 patch releases
    you can change line 296 in the global fog shader into this if you don't want the fog get affected by built in fog color
    Code (csharp):
    1. fogCol.xyz = sunEGround;
     
    Last edited: Apr 23, 2015
  3. Luckymouse

    Luckymouse

    Joined:
    Jan 31, 2010
    Posts:
    484
    Actually this formula used by cryengine's volumetric fog to block the scattering from scene's occlusion.
    It is their shader code:
    miePhase * saturate( ( sceneDepth - 1 ) * fog )

    fog should be the same as fogFac in your shader.
    I just use it because they used it. My scattering fog used it too.:D
     
  4. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    I see, that's interesting.
     
  5. antislash

    antislash

    Joined:
    Apr 23, 2015
    Posts:
    646
    hi Rea,
    i mean that in the sky, the light appears affected by fog (no halo, no lens effect)
    but when the light is seen from behind a foliage (i my case billboard foliage)
    it looks plain, like if it was no fog.
     

    Attached Files:

  6. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,372
    Wow, that fixed it just beautifully!

    Good news :) But what would a proper rayleigh function be to filter out the red and green over distance?
     
  7. antislash

    antislash

    Joined:
    Apr 23, 2015
    Posts:
    646
    hi folks,
    i d' like to add two wishes for that excellent fog :
    1 - global darkening and shadows blurring (fog blurs shadows a lot)
    2 - no fog in cavities and shadows at close range, actually, if you have a cave, you can see fog in it (something with lighpass buffer?)
     
  8. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,372
  9. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    hmm strange, i never get those :/
     
  10. Constantinos

    Constantinos

    Joined:
    Dec 11, 2012
    Posts:
    7
    Hi Rea,

    Thanks for sharing! Awesome work!
    By the way, is there a way to make the global fog work with multiple cameras?

    Thanks again!
     
  11. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    I'd just like to chime in and say this isn't exactly true. I use a custom edited version of global fog in Tenkoku, and was able to get around this (admittedly weird) link between the built-in fog and Unity's global fog.

    The globalFog image effect relies on the built-in fog linear settings, as well as the color. this is still the case, even when the built-in fog is turned off, so for example you can access the below variables to turn off the built-in fog and then adjust the linear scaling of the global fog...

    Code (CSharp):
    1. var fogStart : float =  10.0;
    2. var fogDistance : float = 1500.0;
    3. RenderSettings.fog = false;
    4. RenderSettings.fogStartDistance = fogStart;
    5. RenderSettings.fogEndDistance = fogDistance;
    The color can also be accessed and controlled, but I chose to do this on the fx shader itself instead.
     
    Reanimate_L likes this.
  12. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Okay....this is interesting, i'll try to add that into the extended global fog for the next update. Thanks @chingwa oh also the double fog issues are fixed in the latest unity 5 build i think..
     
  13. RangePlusOne

    RangePlusOne

    Joined:
    Dec 6, 2014
    Posts:
    123
    Hello everyone, I am curious why this effect is happening in fog. The particle seems to only emit if there is a mesh or terrain behind it. If the horizon or sky is behind the particle, it seems to display a cut out like effect. Any ideas? Capture.JPG
     
  14. domiii

    domiii

    Joined:
    Jun 22, 2015
    Posts:
    2
    IMPORTANT DISCOVERY

    Hi there and thank you so much for your awesome fog package!

    I just made this post reporting several bugs. Turns out, they were all caused by one thing: I enabled Unity's default fog! Since this fog package uses Unity's default fog color, you have to first enable fog, then change the color, and then DISABLE fog again! If you keep the built-in fog enabled, you will suffer from a ton of bugs.

    My feature request to the awesome author: Can you change the script to ignore global fog settings (since changing those requires enabling global fog first, which in turn causes bugs), and just add an editable property instead?
    Also, would you mind [putting this on Github or some other versioning system](https://help.github.com/articles/set-up-git/), so we can benefit from versioning and issue tracking? I can do it, too, but since you are the sole owner and author, you should also own the repository! :)

    Thanks again for this awesome package! Loving it!

    PS: This Unity Answers post explains how to set this up from scratch, included above-mentioned caveat: http://answers.unity3d.com/questions/978277/skybox-horizon-adjustment.html#answer-container-1000222
     

    Attached Files:

    Last edited: Jul 4, 2015
    theANMATOR2b likes this.
  15. backwheelbates

    backwheelbates

    Joined:
    Jan 14, 2014
    Posts:
    232
    Bump, great idea to put this in source control!
     
  16. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    If someone needs basic fog in deferred shading, I can do that. :) Interesting effect, BTW.
    Give me a look at the shader you're using, it's probably a rendering queue glitch I can fix. :) (I could just download the shader, but since there's several versions floating around this thread... :D you get the idea!)

    EDIT: Wait, was that a necro bump? I guess this is only about two months old, might not matter... :D
     
    twobob likes this.
  17. switlle

    switlle

    Joined:
    Jul 2, 2014
    Posts:
    2
    I have a problem with fog post effect. When some point or spot light interact with transparent material I got this problem upload_2015-9-2_13-13-43.png

    upload_2015-9-2_13-14-8.png

    upload_2015-9-2_13-14-30.png




    Video:

    Using Unity 5.1.2
     
    Last edited: Sep 2, 2015
  18. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Odd glitch... Does this occur if there's a directional light present? If it does, then it's probably something in the script doing it.
     
  19. switlle

    switlle

    Joined:
    Jul 2, 2014
    Posts:
    2
    Yes. the directional is inside this scene, but as well as point or spot light
     
  20. kmoosmann

    kmoosmann

    Joined:
    Mar 1, 2014
    Posts:
    22
    Hey - awesome shader, really! Is it normal it doesn't affect tree billboards? Anything that can be done about that? My trees vanish as soon as they are supposed to billboard. If I re-enable Fog in the Lighting settings, I can see them - but they are washed out and the lighting seems wrong.
     
  21. dradb

    dradb

    Joined:
    Jan 10, 2015
    Posts:
    86
    Hi rea,
    There seems to be a bug in the fog. Select height fog only, no advanced. The column in the foreground is very close to the camera but shows the same white distant fog line across it as the distant column. Objects close to the camera should show no signs of fog.


    fogBug.jpg
     
  22. dradb

    dradb

    Joined:
    Jan 10, 2015
    Posts:
    86
    Rea,
    There also seems to be a problem with height fog off and basic distance fog. The red fog starts well beyond the column close to the camera, but the fog covers both the near and far columns in a similar manner. Of course I may be just doing something incorrectly?

    fogBug3.jpg
     
  23. d3thdrug

    d3thdrug

    Joined:
    Feb 23, 2014
    Posts:
    3
    this looks great but how do I apply it to my scene? do I attach the script to an object? if so, which?
    please reply thank you
     
  24. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    Replace the global fog shader which is a standard unity asset with this one. You can find it by adding global fog effect to your camera.
     
  25. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    Is there going to be any more updates or fixes on this thread?
     
  26. aaron95j

    aaron95j

    Joined:
    Dec 9, 2013
    Posts:
    30
    I'm having issues with transparent textures too. If I have anything in the cameras view that is transparent and effected by a light the fog does not follow the sun.
     
  27. Exbleative

    Exbleative

    Joined:
    Jan 26, 2014
    Posts:
    216
    Hi, I'm trying to simply turn off the script for some scenes. I can't however seem to figure out how to get GlobalFog. Perhaps something to do with its namespace? I've tried:

    using UnityStandardAssets.ImageEffects;
    GlobalFog _globalFog;
    _globalFog.enabled = false;

    but _globalFog is always null.
    Tried getting it off the camera it was attached to as well, still no luck.

    Would love a hand! Thanks,
    Jay
     
  28. arnebp

    arnebp

    Joined:
    Oct 15, 2013
    Posts:
    22
    Thanks for sharing this fog shader @rea !

    In Unity 5.4, this shader seems to be drawing on-top the UI layer. The 'normal' Global Fog shader does not have this behavior. Anybody got a quick fix for this?

     
  29. Karlbovsky

    Karlbovsky

    Joined:
    Jul 11, 2012
    Posts:
    231
    Hi, i know this is a pretty much a dead thread but i´ll try...

    I´m trying to make my asset package compatible with this custom Global Fog script and shader, but struggling with the Transparent PBS materials issue too.

    The problem is the same mentioned above by @swittle and it only happens with PBS shader when transparent or fade rendering mode are selected. It´s for sure related to lights interacting with the transparent material. If there´s only one light in scene the issue is not present.

    I was wondering if someone have had any luck with it ?

    Thanks in advance.
     
  30. Crembo

    Crembo

    Joined:
    Jun 2, 2014
    Posts:
    16
  31. Karlbovsky

    Karlbovsky

    Joined:
    Jul 11, 2012
    Posts:
    231
    @Crembo Thanks mate, i will have a look at..
     
  32. lka69

    lka69

    Joined:
    Jun 6, 2009
    Posts:
    39
    Yeah a quick fix for Unity 5.4 would be really appreciated, i loved this effect so much...
    Thanks @rea
     
  33. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Wow, never know people still using this assets,
    Uhh hang on i think i have a fix for 5.4
     
    lka69 likes this.
  34. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Here you go, also i think there's something that i've changed but i'm not remember what is it. This fix has been around since 5.4 are in beta and i forgot to update it :D
     

    Attached Files:

  35. lka69

    lka69

    Joined:
    Jun 6, 2009
    Posts:
    39
    Thanks @rea ! You are awesome!!!
     
  36. BadSeedProductions

    BadSeedProductions

    Joined:
    Dec 26, 2014
    Posts:
    144
    The type or namespace name 'PostEffectsBase' could not be found (are you missing a using directive or an assembly reference?) ...\Assets\Standard Assets\Effects\ImageEffects\Scripts\GlobalFogExtended.cs 12
     
  37. DoctorLucky

    DoctorLucky

    Joined:
    Apr 12, 2015
    Posts:
    1
    Near as I can tell, the PostEffectsBase script that Rea's global fog script extends is a Pro-only asset, so you don't have PostEffectsBase unless you use Unity Pro.
     
    BadSeedProductions likes this.
  38. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    No, there is no longer a pro feature set, all engine features are standardized. What you are missing is the Standard Assets effects package which you need to import manually in each scene.
     
    theANMATOR2b likes this.
  39. Abram-Painter

    Abram-Painter

    Joined:
    Jun 6, 2016
    Posts:
    3
    One thing that a lot of people miss when it comes to fog is that all light still passes through it (given the fog is vapor and not smoke), because vapor is mostly reflective and not so much obstructive. Ever wondered why you could see car headlights and billboards clearly through the fog, or why you could tell what region of the mountain in the distance is snowy.

    examples:

    it is clear the white snow is not nearly as affected by the fog as it's rocky neighbors


    the light comes right through

    you may think this would be difficult because how would you scatter all the light coming in from every object, but actually, this is really easy.

    at the end of half4 ComputeFog in the shader, replace...
    FinalColor = lerp (fogCol, sceneColor, fogFac );
    ...with...
    FinalColor.r = (fogCol.r > sceneColor.r)? lerp (fogCol.r, sceneColor.r, fogFac) : sceneColor.r;
    FinalColor.g = (fogCol.g > sceneColor.g)? lerp (fogCol.g, sceneColor.g, fogFac) : sceneColor.g;
    FinalColor.b = (fogCol.b > sceneColor.b)? lerp (fogCol.b, sceneColor.b, fogFac) : sceneColor.b;

    it checks to see whether the original color is brighter or less bright than the fog. If it is less bright, fog will be put over it, if it's brighter than the fog, the fog is ignored.
     
    Last edited: Jan 16, 2017
    spaceemotion likes this.
  40. RomBinDaHouse

    RomBinDaHouse

    Joined:
    Mar 18, 2015
    Posts:
    13
    It is even simpler, just
    FinalColor = lerp (fogCol, sceneColor, fogFac );
    BUT only one thing is important - relative HDR Values of scene colors. For example, if common lit surfaces' colors are mostly in 0..1.0 range of final brightness then emissive (or lit with tiny lights) surfaces of lanterns\lamps\headlights must have values such as 10s, 100s, 1000s.
    I mean: lerp( 0, 1000, 0.001) = 1.0 (for "black" dense fog)

    Fog or smoke - it does not matter (almost) in this case.
    Same for snow albedo in comparison versus ground\grass\rocks albedo (it is 4x..10x brighter under sun, roughly ).
     
  41. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    I've never even thought of doing that. :O Nice.
     
  42. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    328
    If you guys are talking about fog not completely obstructing bright lights all you need to do is clip the maximum opacity of the fog color. That's a feature in my slightly modified fog effect found here (which I stole from "Inside" btw).
     
    theANMATOR2b likes this.
  43. arnesso

    arnesso

    Joined:
    Mar 3, 2015
    Posts:
    96
    I know it is an old topic,
    but i hope someone could help me.
    I would like to create a scene with full fog, except in the given area sphere.
    So in the fog there would be some place where is no fog. How could I solve this ?
    Because i cannot say, if the fog ontrigger then the density is zero :\
     
  44. Abram-Painter

    Abram-Painter

    Joined:
    Jun 6, 2016
    Posts:
    3
    OCASM, I have tried that once and I would say that it depends on what you are trying to achieve. In a lot of cases, using a max opacity is not at all what you want.

    Say you tried to imitate this effect:

    If there was a max fog opacity, everything in the background would be clearly visible and the fog would not look very realistic. What my shader is really useful for however, is making car lights visible if you could imagine one pass by, or a UFO in the sky where the light would clearly glow through the fog and clouds. This isn't about letting all light pass (I apologize for my previous incorrect explanation), it is about letting the light that is bright enough to still be visible through the fog, the way it works in the real world.


    Here, most of the car is barely visible, even though the lights are (almost)completely unaffected. This could not be achieved with the max opacity method.
     
  45. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    328
    I can't post pictures right now because my computer died but with a clipping value of 0.9 (SSMS uses 0.999 by default) it's possible to create those scenes. I recommend you download the package and experiment with it. Also, here's INSIDE's rendering talk where you can see an example that completely covers the background using this technique (at 4:18):

     
  46. Gua

    Gua

    Joined:
    Oct 29, 2012
    Posts:
    455
  47. lex24

    lex24

    Joined:
    Feb 4, 2013
    Posts:
    10
    Can somebody explain, why fog becomes pink when directional light's X Euler angle is more than 90 degrees?
     
  48. RSH1

    RSH1

    Joined:
    Jul 9, 2012
    Posts:
    256
    Is there a way to get this working with Unity 2019? I get the error

    The type or namespace name 'PostEffectsBase' could not be found (are you missing a using directive or an assembly reference?)

    And I can't seem to find the download for the legacy PostEffectsBase class any more.