Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Help to create a better fog (shader or image effect)

Discussion in 'General Graphics' started by antislash, Apr 23, 2015.

  1. antislash

    antislash

    Joined:
    Apr 23, 2015
    Posts:
    646
    Hi U3D users,
    i don't know if this is the best place to post this... i am new to forums, so i apologise if i'm wrong...

    ok here is my request...
    i am in the path to make my own fog, as the built in fog is terrible....

    i am looking for advice about how to begin with ....
    should i script an image effect componant ? write a shader ?

    i would appreciate some help .....
    if someone is okay to work with me i can explain how to obtain a good fog and share the asset.

    thanks in advance guys...

    Victor

    ps : here are 2 pics attached, one with the standard fog and one reworked in PS.
     

    Attached Files:

  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    5,597
  3. antislash

    antislash

    Joined:
    Apr 23, 2015
    Posts:
    646
    thank you very much,
    it is almost exactly what i wanted.... it just misses the overall shadowing and desaturation...
    excellent
    thanks Mgear
     
  4. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    The overall shadowing you probably want to use something like https://www.assetstore.unity3d.com/#!/content/15699 or Amplify Color to get.
    However to get the fog to not only blend towards white, but also desaturate, you will probably need to create a custom fog calculation for it.
    The neatest way to do it is probably copy in all the unity built in shaders, and extend the macro
    Code (CSharp):
    1. #define UNITY_FOG_LERP_COLOR(col,fogCol,fogFac) col.rgb = lerp((fogCol).rgb, (col).rgb, saturate(fogFac))
    (Located in UnityCG.cginc)
    With something that not only lerps but also does your desaturation.
    This should result in you not having to do a post process or similar.
    (You can in the same file also find the code for how they calculate how much fog should be applied.)
     
    theANMATOR2b likes this.
  5. antislash

    antislash

    Joined:
    Apr 23, 2015
    Posts:
    646
    Hi zicandar,
    i'm very new to unity, i can code a bit and understand code, but it's not fomerly my job.
    so i was in the path to do it step by step.
    i think REA , in the other thread already did a great job with his extended fog and i submitted that remark to him, let's see what comes next ;)

    the result i got with photoshop is pretty simple to achieve (zdepth+3 adjustment layers)
    i simulated scatter with a gradient, no raleigh, so, once coded, i think it would be pretty inexpensive.
    i was wondering if the use of a LUT when fog on was a good move, didn't try.
     
  6. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    If you don't have semi-transparent objects this could easily be done using a single post process effect.
    But as most games have particle systems ect... You usually want the fog to be done the way unity does it.
    If your ok with it being a post process then the asset linked earlier would likely be a good start.
    However, once the game gets a bit more complex, then usually the "real" built in fog is better.

    If your ok with overriding the unity shader files, then this might work if you replace the line I showed earlier. (WARNING untested!)
    Code (CSharp):
    1. #define UNITY_FOG_LERP_COLOR(col,fogCol,fogFac) col.rgb = lerp(lerp((((col).r + (col).g + (col).b) / 3), (col).rgb, saturate(fogFac)), (fogCol).rgb, saturate(fogFac + 0.2))
    Obviously this can be refined futher, especially the + 0.2 MUST be tweaked
     
  7. antislash

    antislash

    Joined:
    Apr 23, 2015
    Posts:
    646
    yup alphasorting is a problem, i had that kind of issue in cryengine,
    thanks for the tip ;)