Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Skybox / cubemap derived fog color

Discussion in 'Shaders' started by Ryan-Gatts, Nov 15, 2013.

  1. Ryan-Gatts

    Ryan-Gatts

    Joined:
    Sep 27, 2012
    Posts:
    54
    Are there any existing solutions for this effect? I've been consistently stumped whenever I try to tackle this problem in strumpy or shaderlab (which I'm pretty new to).
    $desired_skyfog.jpg

    I understand that the default unity fog cannot be fragment shaded in this way, but are there any known tricks for achieving this volumetric lit-fog look using cubemaps?

    I've thought of somehow using the default unity fog as a mask and rendering a second sky on top of it (that's how I'd do it if I were in after effects, anyway), but I have not idea how to go about that.

    If we could make this relatively cheap, I think this has application in pretty much every game that has fog.

    Thanks
     
  2. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    Might be possible to do this as a post-processing effect (mabye have a look at the global fog image effect).
    You'd have to render the skybox only to a rendertexture and sample its color when it is time to render a geometry fragment with custom fog.
    Sorry, it is a bit hard to explain - I haven't done much with image effects yet, so I would need to experiment first. Maybe someone else has some more ideas.
     
  3. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    You can do that with GlobalFog, just need to modified it to use Skybox as Fog Color
     
  4. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    In practice, this may not work as well as it first appears, as the terrain would start looking transparent, showing any details in the skybox (e.g. clouds) through it. A very low-res (heavily blurred) version of the skybox might reduce that effect, though?

    The easiest way to apply the effect would be as a full-screen post effect - you'll need a depth texture, just read that, do your fog calculation, and blend between the original pixel and fog colour. Won't work for translucent objects (or other effects that don't write to Z), though.

    Alternatively, you'd probably need to write your own set of shaders that sample the cubemap.

    Would be interesting to see it in action. Anyone who's played World of Warcraft will know how bad solid-colour fog can look - something like this might be the answer?
     
  5. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    True, the problem is the cloud in the skybox, sometimes it really annoying to have those in the fog. That's why i sampled the skybox with very low resolution for the fog colour, something like 64x64 or less (more than that the cloud will be pretty obvious).
    or you can layering the skybox (this one kinda tedious though), so one layer with skybox without cloud (low res version is enough since we only gonna sample the colour for the fog), and another skybox with cloud (this one we can render it as skybox normaly)
    $2.JPG
     
    Last edited: Nov 18, 2013
  6. Ryan-Gatts

    Ryan-Gatts

    Joined:
    Sep 27, 2012
    Posts:
    54
    @rea and @bluescrn

    Thanks for the suggestions! I'll work on implementing your suggestions when I wrap back around to working on my cloud/fog shaders.

    If anyone else has any other methods that they prefer please continue to share :)
     
  7. latinsupercube

    latinsupercube

    Joined:
    Dec 11, 2013
    Posts:
    2
    Hi I've been trying to find a solution to the exact effect you have shown @rea using a low res skybox as the overlayed fog, are you able to share?
     
  8. backwheelbates

    backwheelbates

    Joined:
    Jan 14, 2014
    Posts:
    231
    Bump!

    Has anyone made any progress on this?

    Thanks!!
     
  9. grahnzz

    grahnzz

    Joined:
    May 7, 2013
    Posts:
    46