Search Unity

Screen Space Multiple Scattering

Discussion in 'Works In Progress' started by OCASM, Dec 17, 2016.

  1. Eckis

    Eckis

    Joined:
    Oct 24, 2016
    Posts:
    1
    I'm getting this error "SSMS-master/SSMSGlobalFog.cs(109,29): error CS1061: Type `UnityEngine.Camera' does not contain a definition for `CalculateFrustumCorners' and no extension method `CalculateFrustumCorners' of type `UnityEngine.Camera' could be found"
    What am I missing?

    And by the way this looks great!
     
  2. PixelMind

    PixelMind

    Joined:
    Aug 16, 2013
    Posts:
    100
    Update to 5.5 or newer.
    I had that at first too when I first tried to run it on Unity 5.4. CalculateFrustumCorners function was added in 5.5 if I'm not mistaken.
     
  3. AdamGoodrich

    AdamGoodrich

    Joined:
    Feb 12, 2013
    Posts:
    3,553
    This looks amazing. Cant wait to try it out with some Gaia / Gena scenes :)
     
    Shawn67, hopeful and OCASM like this.
  4. AdamGoodrich

    AdamGoodrich

    Joined:
    Feb 12, 2013
    Posts:
    3,553
    Ok... this is just stunning! Unfortunately screen shots didn't work. Tomorrow I will play more with this and hopefully sort out the screen shot issue :)
     
    Whippets, kurotatsu and Shawn67 like this.
  5. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,296
    I'm confused. If this is basically a DOF effect then what makes it different than just using a DOF effect? Also, what Unity version is required to use this?
     
  6. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    211
    What I meant by that is that the technique used to emulate the effect (light scattering through fog, perceptually appearing blurry) works very much like DOF except that it uses fog to determine what areas of the screen should be blurry and by what amount instead of depth.

    5.5.
     
  7. AdamGoodrich

    AdamGoodrich

    Joined:
    Feb 12, 2013
    Posts:
    3,553
    Ok - so some images i am happy with :)

    Environment created with Gaia and Gena, and lit with SimulSky (way overkill as I essentially obliterated it), and playing with this amazing asset.

    Just love it, and would be happily to purchase it to fund more development from the author!

    Grab 20170303131439 w1920h1029 x189y66z-188r232.jpg

    Grab 20170303131803 w1920h1029 x178y101z-490r58.jpg

    Grab 20170303132039 w1920h1029 x159y92z-82r194.jpg
     
    Last edited: Mar 3, 2017
    Alverik, Lex4art, antoripa and 5 others like this.
  8. AdamGoodrich

    AdamGoodrich

    Joined:
    Feb 12, 2013
    Posts:
    3,553
    And the video :)

     
    Alverik, antoripa, wahyuway and 2 others like this.
  9. matteumayo

    matteumayo

    Joined:
    Jul 25, 2016
    Posts:
    166
    Hello,

    First of all, amazing work! Seriously the best fog asset I've seen so far - thanks so much for sharing. :)

    I do however have an issue - your fog seems to flip my game upside-down. This is actually a well-documented issue for global-fog in VR projects that was supposed to have been fixed in 5.6. However, after upgrading from 5.5 to 5.6, the issue persists.

    I'm using the altered Forward rendering version (with the commented lines changed.)

    Have you, or has anyone else, experienced this issue?

    Thanks.
     
    OCASM likes this.
  10. Astaelan1

    Astaelan1

    Joined:
    Sep 29, 2015
    Posts:
    162
    Can't wait to try this myself, looks really nice. Good fog can do a lot to cover up a lot of other issues with LOD switches and such. Very nice approach, and like @AdamGoodrich I'd be willing to pay a nominal fee to see active development on this continue, and possibly expand into some other areas.
    Perhaps a little blurring on the results of particle effects like waterspray on bigger waterfalls? more dynamic behaviour of fog over and near water in general (it behaves a bit differently)? volumetric behaviours to simulate being inside of clouds at the top of a mountain? Animation of some perlin noise within the fog? Parallax behaviour of distant fog vs closer fog if animated?

    Just a few ideas to play with.
     
    Lysander and OCASM like this.
  11. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    211
    If you use the regular deferred version, does it flip when you're in play mode?

    I certainly plan to develop it further. Noise is probably the next thing I'll add. However, for really advance stuff and if you don't mind paying, this seems to be a pretty good option:

    https://forum.unity3d.com/threads/fog-volume.225513/

    Regarding transparencies, I see no viable option to make them work short of blurring them on a case by case basis which would get expensive really fast. I think I'll make a branch that works like in the new Zelda: lower the bloom threshold and slightly lerp between the sharp source RT and the blurry one:



    Nowhere near as good but better than nothing.
     
    Alverik and antoripa like this.
  12. DNCstudios

    DNCstudios

    Joined:
    Feb 16, 2017
    Posts:
    6
    Hello..

    My camera is flipped when i used ssms and ssms global fog into my camera in runtime mode.When i unchecked smss global fog it looks not flipped,well..

    How can i handle this?

    Thank you.
     

    Attached Files:

  13. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    211
    DNCstudios likes this.
  14. matcafe

    matcafe

    Joined:
    Mar 13, 2017
    Posts:
    5
    Hi, new Unity user here. Your fog looks awesome, and I want to use it in my project, but I can't figure out how to swap the global fog for your fog, and haven't found any explicit instructions. Could someone kindly give a brief walkthrough (or a link)?
     
    Last edited: Mar 13, 2017
  15. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    211
    Just add the package to your project and then take a look at the included example scene.
     
  16. matcafe

    matcafe

    Joined:
    Mar 13, 2017
    Posts:
    5
    Thanks for your quick response. I followed the example scene (exponential for global fog mode) and got something that starts to look like the screenshots in Viking Village, but I now have a couple of new problems:
    1. Height fog has no effect, whether I toggle it on or off
    2. I can see the fog at very close distances in the game view, but once I jump into play, there is no fog for objects close to me. Is this because the main camera isn't the same as the game camera, and I only added SSMS to the main camera?
     
  17. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    211
    Can you post a screenshot of your camera settings? Would be easier to diagnose the problem that way.
     
  18. matcafe

    matcafe

    Joined:
    Mar 13, 2017
    Posts:
    5
    Screenshots of camera and game/play view:
    unity1.PNG unity2.PNG unity3.PNG
     
  19. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    211
    Oh I see, it seems that when you enter Play mode the "CameraLoop_HighQuality" camera is turned off. Either disable the other cameras and re-enable that one OR add the fog effect to all the cameras.
     
  20. matcafe

    matcafe

    Joined:
    Mar 13, 2017
    Posts:
    5
    Oh ok yeah I see it now after activating that camera in play mode. The height fog works fine too - I just needed to increase the height. But the "CameraLoop_HighQuality" camera is an auto-looping camera - how do I find out which camera it is using in Play mode?
     
  21. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    211
    Well the simplest method would be to enter play mode and then check in the hierarchy/inspector which camera is activated.

    EDIT Scratch that, just enter play mode, go back to the scene mode and look for the camera icon.
     
  22. shahzaib

    shahzaib

    Joined:
    Dec 14, 2013
    Posts:
    19
    just downloaded SSMS from Github and going to play with it! does it also work with SM3.0 mobile devices?
     
  23. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    211
    I haven't tested it on mobile but I don't see why it wouldn't work.
     
  24. SAOTA

    SAOTA

    Joined:
    Feb 9, 2015
    Posts:
    220
    I'm getting some good results, even in my test scenes.


    screen_1920x1080_2017-04-08_19-56-49.png
     
  25. bagieta

    bagieta

    Joined:
    Mar 24, 2017
    Posts:
    1
    Hey. Great stuff. I have tried to use it. Hovewer when I mix it with Temporal Antyaliasing I got flickering. Is there a way to fix it?
     
  26. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    211
    What kind of flickering? Also, what's the order of your camera's image effects stack.
     
  27. littleoak

    littleoak

    Joined:
    Oct 1, 2016
    Posts:
    2
    Man... you're beast. LOVING Effect prints. i'll test now!
     
    OCASM likes this.
  28. Quast

    Quast

    Joined:
    Jul 5, 2015
    Posts:
    441
    Can you please make a tutorial explain how to use this project settings ?
     
  29. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    211
    Anyone in particular you're having trouble with?
     
  30. matteumayo

    matteumayo

    Joined:
    Jul 25, 2016
    Posts:
    166
    Sorry it took me so long to respond - I eventually returned to this, and I'm experiencing the same behavior:

    Works fine in deferred, with standard deferred shader,
    Flips scene and game camera in forward with the forward lines uncommented and deferred commented out - even without MSAA on, which I've seen cause this with fog shaders in the past.

    I'm confused that this is still happening and nobody else has mentioned it... are you all using a different version of Unity? I believe I tested this on a 5.5 build originally, and today I've confirmed the behavior is the same on 5.6.0f3.

    Any ideas?
    Thanks
     
  31. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    211
    Maybe another shader in your camera stack is conflicting with SSMS?
     
  32. matteumayo

    matteumayo

    Joined:
    Jul 25, 2016
    Posts:
    166
    There are no shaders on the camera stack other than those default in the example scene.

    So, I made a fresh project and only imported your asset. Next I replicated my main project's settings, notably: Vulkan graphics API, VR support enabled, forward rendering.

    Strangely without changing (de/commenting) any code to make it work in forward rendering mode, I saw no issues or artifacts (although I haven't tested it in VR yet.)

    Then, when I switched the commented lines to the forward version, even in this fresh project, the view is flipped in scene and in playmode.

    Worth noting: I also of course tested everything before changing project settings (other than forward) and the behavior was identical.


    Does this make any sense to you? o_O

    Also, I'm testing it with the deferred commenting in forward in VR right now, i'll let you know how that works.
     
  33. matteumayo

    matteumayo

    Joined:
    Jul 25, 2016
    Posts:
    166
    Firstly, I'd like to note that I do understand this is a free asset, and I by no means expect any support to accommodate for the niche VR development scene.

    Nonetheless, here are my findings:

    I can confirm that the deferred commented version (default) works in my main project (in forward mode.)

    I think this may have to do with 5.6 fixing the flipping, and thus rendering your forward mode unnecessary? Just a thought.

    I found that it works (and looks fantastic) in VR only in multi-pass mode, not single-pass, which means it's largely useless for most projects (as the performance loss going to multi-pass is generally enormous). Here it is in single-pass VR - note however this is only one eye and thus doesn't show the main problem.:



    It may be difficult to see but this is the effect seen in single-pass VR: In the left eye, the fog is either higher or lower, depending on head rotation, than the right eye. When you tilt your head slightly left, you see 2 fog lines (really two Height Fog effects) - one in each eye, each at a different vertical position.

    You may also note the very large aliasing artifacts on the edge of objects. These are present with or without MSAA, and in multi and single-pass. They are caused by the SMSS script. Turning the Scattering Intensity to nothing does fix this aliasing issue, but also disables the SMSS, of course.

    Finally, and least importantly, there are minor artifacts on the edges, shown here: http://image.prntscr.com/image/5d61a31da2c146fcafc5ede477b3e269.png

    These aren't very noticeable unless the fog Start Distance is set far away.

    I'll keep researching to see if I can fig the fog shader single-pass issue, since I think all fog is messed up in single-pass.

    Thanks for any ideas,
    Matt
     
    Last edited: May 4, 2017
  34. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    211
    It's good to know that commenting the lines is no longer required for forward rendering. As for the VR issues, if the fog on its own also has artifacts maybe it's necessary to update it to be based on 5.6's global fog from the standard assets although if that's not somewhere on Github or Bitbucket already I couldn't include it in the repository anymore.

    Reading Unity's documentation on single-pass mode it seems that the shader would require some modifications to work properly. Would you like to take a shot at it?
     
    matteumayo likes this.
  35. Quast

    Quast

    Joined:
    Jul 5, 2015
    Posts:
    441
    Do you have any ideas for what you will do next ? what is your plan to improve this ?
    Just wondering :rolleyes:
     
  36. matteumayo

    matteumayo

    Joined:
    Jul 25, 2016
    Posts:
    166
    I've never really worked on shaders, but I'll take a crack at it. I'll let you know how if I can get things working. :)
     
    OCASM likes this.
  37. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    211
    TBH, this was intended purely as a proof of concept. I had been thinking: "how come nobody is doing it? Doesn't seem so hard". Turns out it's easy when all you have to do is modify somebody else's open source code lol.

    As for the future, not much to say really. Since transparencies don't play nice with it (and fixing that would require radically changing how they're rendered) making a new simpler effect would probably be a good solution. I had already started working on it but my PC unexpectedly died and it's going to be out of comission for a while. That one is easy since all it requires is a lerp as far as I can tell.
     
    Quast likes this.
  38. umauj

    umauj

    Joined:
    Nov 20, 2011
    Posts:
    80
    Truly amazing asset! Thanks a lot for sharing!

    Regarding transparency: did you already try applying your fx after rendering the transparent pass? Basically bluring the color info of the particles together with the opaque pixel beneath it? Ofc it is not correct, but maybe it would not look too bad... what do you think?
     
  39. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    211
    Applying it after transparencies is how ot was done at first actually. The problem there is that transparencies would be blurry regardless of how close or far to the camera they are. AFAIK, this problem affects all DOF effects on deferred renderers. Even UE4 has this problem.

    Having said that, if that's not a problem for your scenes then you can enable this behavior by commenting out the tag [ImageEffectOpaque] in the SSMS.cs script.
     
  40. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    918
    What would I have to do to mod the global fog shader to flip the height fog effect upside down and above the camera at an offset?
     
  41. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    211
    I'll be honest: I have no idea.
     
  42. nbac

    nbac

    Joined:
    Jul 7, 2015
    Posts:
    234
    this is awesome but the scattering deos not work for me. what does it color correction whise? it darkens my image massive
     
  43. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    211
    Are you using linear space?
     
  44. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    199
    OCASM very beautiful fog, and I start to use it, but when i switch on, and work in the scene view(I see fog there), unity start eat memory, and eat it all 16 gb. I have another effects of course, and it's heavy too, but only with fog everything start dying. Why is that? What should i do?
     
  45. Lex4art

    Lex4art

    Joined:
    Nov 17, 2012
    Posts:
    159
    +1 here, seems a memory leak ...

    P.S. Also, found Unity 5.6.1f1 leak (not related to SSMS) - put anything in Search (filter) field in Hierarchy window and Unity will start eating RAM with 1-3 GB/sec - on empty, freshly created project without anything changed... bugreport is sent, hope they will fix that.
     
    Last edited: Jun 3, 2017
  46. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    211
    Seems like the render targets aren't being cleaned up. Maybe the API changed in the latest version?
     
    id0 likes this.
  47. Howard-Day

    Howard-Day

    Joined:
    Oct 25, 2013
    Posts:
    122
    So, Out of curiosity, if I wanted to invert the height fog, say if I was making an underwater scene... what'd be the best way of doing that - preferably if I could set some sort of surface offset, so my gameplay can still take place on Y = 0? I fiddled with some of the math, but I couldn't seem to jigger it around to do what I wanted. :D Thanks!
     
  48. starikcetin

    starikcetin

    Joined:
    Dec 7, 2017
    Posts:
    201
    Looks beautiful. Good job.
     
    OCASM likes this.
  49. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    211
    I don't know but you could ask Keijiro Takahashi on Twitter. Unlike me he's a competent graphics programmer and he's dabled with this height fog implementation before.
     
  50. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,307
    Looks amazing! thanks for sharing.
     
    OCASM likes this.