Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  6. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Screen Space Multiple Scattering

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

  1. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    201
    EDIT: Now on Github https://github.com/OCASM/SSMS

    In games, fog looks pretty unrealistic:




    According to this paper light scatters when traveling through fog, resulting in a blurry image, which clearly is not the case there:

    http://www.cs.columbia.edu/CAVE/projects/ptping_media/


    So, by repurposing Keijiro's Takahashi's bloom it's possible to make a much more convincing image:




    Matches reality much more closely:



    The white sphere is there to show that bright pixels in the foreground don't bleed into the background (which is what happens if you use regular bloom). With actual bloom added on top of that this is the final result:



    It has a fancy name but it's basically a DOF effect. Only issue right now is that transparent objects don't work well with it, something to do with not being able to write their values to the depth buffer I guess. Other than that it looks great, just add it after fog in the camera stack:





     

    Attached Files:

    Last edited: Dec 20, 2016
  2. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,001
    That does look very very nice indeed. Can a color tint be used at all? And could this be altered for height fog like the Unity fog effect?
     
    Last edited: Dec 17, 2016
  3. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,001
    I just tried it in my project and it looks lovely, though when I build the game it seems to freeze the rendering, it works fine in the Editor but not in a standalone build for some reason.
     
  4. Pathelion

    Pathelion

    Joined:
    May 11, 2012
    Posts:
    209
    Okay I really need to test this later this night. This could help to hide the billboards of my trees.
     
  5. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    201
    I did some tests and the answer is yes to both of them. Will release an updated version later today or tomorrow after I polish it a bit.

    Yeah I screwed up. Just put the Shaders folder inside the Resources folder.
     
    hopeful likes this.
  6. jdraper3

    jdraper3

    Joined:
    May 28, 2015
    Posts:
    117
    Just tried this out, but for some reason it isn't having any visual effect. No errors, and changing any of the properties, order in the fx stack, on, off, etc all make no difference at all.
     
  7. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    201
    New version: uses a slightly modified version of the Global Fog effect found in the Standard Assets. Supports both distance and height fog:

    No fog:


    Height fog:


    Height fog + SMSS:


    Height fog + Distance fog + SSMS:


    No fog:


    Height fog:


    Height fog + SSMS:


    Another benefit is that alpha blended particles no longer look like crap. OK, sometimes they do.

    I should have mentioned this earlier but it only works properly on Deferred. In Forward the vertical UV coordinates are flipped so that causes some problems.

    Included in the package are the SSMS files and modified versions of GlobalFog.cs and GlobalFog.shader. They need other components from the "Effects" package from the Standard Effects so make sure you have those imported beforehand.

    I also uploaded a very basic project (tested on 5.5) that shows how to set it up.
     

    Attached Files:

  8. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,001
    Very nice change, though I am getting a difference in the fog from the standard GlobalFog and your modified version which makes it unusable in my case which is a shame as it looks lovely.
     
  9. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    201
    What difference are you getting? For some reason when you import the updated Global fog script the shader becomes unassigned. Maybe that's the problem?
     
  10. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    920
    Thought I'd post a vid
    Here is the first package in my forest scene. It adds a lot of depth and is an attractive aesthetic.

     
  11. mons00n

    mons00n

    Joined:
    Sep 18, 2013
    Posts:
    212
    Looks great; love the color! What are you using for rain if you don't mind me asking?
     
  12. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    920
    Last edited: Dec 18, 2016
  13. jdraper3

    jdraper3

    Joined:
    May 28, 2015
    Posts:
    117
    Is this 5.5 only? Neither version is working at all for me on 5.4.
     
  14. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    201
    I've only tested it on 5.5.
     
  15. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    201
    Another update: to avoid conflicts with the Standard Assets I copied the fog effect into another file . I also changed file names so this time in order to update:

    - Copy your settings for fog and SSMS.
    - Remove them from the camera.
    - Delete the SSMS folder.
    - Import the package.
    - Add the effects back (SSMS Global Fog and SSMS).

    The downsides of ad-hoc coding :oops:. I promise next updates will be more straightforward.

    The new feature is energy loss. The idea being that depending on what the fog is made of some light will be absorbed by it so the image that reaches the eye/camera is much darker. To simulate this the pixels behind the fog are darkened based on its density. This doesn't affect the fog color.





    Instead of an example project the package now includes a basic scene that shows how to setup the effect.
     

    Attached Files:

    hopeful, Hikiko66, radimoto and 3 others like this.
  16. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,270
    This is looks great, Thanks for sharing.
    Btw i think it would be easier to distribute update by using a repo for this.
    It seems you keep having trouble doing update :)
     
    mons00n likes this.
  17. mons00n

    mons00n

    Joined:
    Sep 18, 2013
    Posts:
    212
    +1 for a public repository
     
  18. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    920
    New version looks awesome.

    In the new version I have to manually enable and disable the SSMS before it starts working. If I enable it in a start function, that also doesn't work. Is it waiting for something else to initialize?
     
  19. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    201
    You wanted a public repo? You got it:

    https://github.com/OCASM/SSMS

    Tell me if anything is broken.

    The latest version requires SSMS Global Fog to be in the camera stack, before SSMS itself since it creates the necessary fog rendertexture to calculate how blurry each part of the screen should be.
     
    Last edited: Dec 20, 2016
  20. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    201
    New update: Added a slider to make the blur, well, blurrier:

    Set at 1:


    At 10:


    At 100:


    No decrease in performance, but take note that higher values = more artifacts.
     
    Shawn67, mons00n and hopeful like this.
  21. spaceemotion

    spaceemotion

    Joined:
    Sep 29, 2015
    Posts:
    36
    This looks fantastic! I downloaded your example from the github repository and it worked out of the box.

    However, after I added it to the lighting tutorial project (the viking village you're showing in the example shots) I somehow only get a black screen with the "SSMS Global Fog" component and an over-saturated one with the normal ("SSMS") component. Even when removing all components from the camera except for yours, no change.

    What am I missing here? Cheers!
     
  22. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    201
    The effect is still dependent on the global fog settings. Go to the Window > Lighting > Fog and set the color to something other than black. Set the density to lower than 1 or set it to linear and adjust accordingly. Also, disable stylistic fog.

    Import the attached scene to your "Lighting Optimisation Tutorial" project to have a working example.
     

    Attached Files:

    Lex4art and spaceemotion like this.
  23. b4c5p4c3

    b4c5p4c3

    Joined:
    Jan 4, 2013
    Posts:
    537
    It looks great
     
    OCASM likes this.
  24. Lex4art

    Lex4art

    Joined:
    Nov 17, 2012
    Posts:
    157
    Thanks for sharing, great asset!
    Unity-5.5-text-OCASM.jpg
     
    Shawn67, OCASM and macdude2 like this.
  25. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    920
    Must be something else
    See this video of my apparently obscure problem. I've tried disabling the other camera effects as well.


    Do you know why it is different when I enable and disable the ssms script?
     
    Lex4art likes this.
  26. b4c5p4c3

    b4c5p4c3

    Joined:
    Jan 4, 2013
    Posts:
    537
    I have the same problem.
     
  27. Nateply

    Nateply

    Joined:
    May 20, 2014
    Posts:
    46
    Me too.
     
  28. Lex4art

    Lex4art

    Joined:
    Nov 17, 2012
    Posts:
    157
    Btw, I tested this trick on SSMS and it works in Scene view now ... mostly. The distance offset not working in Scene view, only in Game view at play: screenshot. Also fog distance blur working only in Game view too, but this is minor problem. I'm not a programmer at all, but maybe someone can fix that. From artist point of view ability to see all effects in Scene view is sooo nice ).

    Upd: this two little bugs can be fixed with one simple action - switching off and then on "SSMS (Script)" on camera. After that all works fine in Scene view, but only until Play mode is activated (after that bugs re-appears and off/on action needed to be redone again).
     
    Last edited: Dec 29, 2016
  29. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    201
    What if you start with both "Global Fog" and SSMS disabled and you enable them both in Start(), in that order? Does the problem also occur in the example scene included in the package?

    It didn't occur to me to make it visible in the Scene view since the standard global fog isn't either but yeah, seems to be a bug with how Unity updates the Image Effects in the Scene view versus Game view.

    EDIT: Actually, no, it's not a bug but a design error. Update incoming xD.
     
    Last edited: Dec 29, 2016
    Lex4art likes this.
  30. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    201
    OK, so the effect now works by default in the scene view and updates properly. The error was in how I was passing the information from the global fog effect to SSMS: accessing the rendertexture via GetComponent() instead of setting it as a global texture. The more you know...

    Maybe this will help with @NA-RA-KU 's problem too, not sure.

    Get the updated package on Github: https://github.com/ocasm/ssms
     
    Lex4art and Hikiko66 like this.
  31. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    920
    Yeah, that fixed it ^_~
     
    OCASM likes this.
  32. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    201
    Trying to add particles into the mix:

    Disabled:


    Enabled:


    Progress is slow because I have no idea what the hell I'm doing :confused:
     
  33. StevenPicard

    StevenPicard

    Joined:
    Mar 7, 2016
    Posts:
    482
    Thank you for sharing this!

    How do I keep it so the fog sits along the ground (more like mist) so I can still see the sky? None of my settings seem to make any difference or give nice results.
     
  34. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    201
    Take a look at the example scene included in the package, just uncheck "Distance fog" and you're good to go.
     
  35. Lex4art

    Lex4art

    Joined:
    Nov 17, 2012
    Posts:
    157
    Last edited: Jan 18, 2017
  36. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    201
    hopeful, Hikiko66 and Lex4art like this.
  37. Lex4art

    Lex4art

    Joined:
    Nov 17, 2012
    Posts:
    157
    OCASM likes this.
  38. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    201
    Alpha blended particle support (kinda) now available as an experimental branch:

    https://github.com/OCASM/SSMS/tree/particles

    Looks quite nice but comes at a cost which is that the scene has to be rendered again to create the extra blur mask. If anybody knows of a better method, let me know please.

    Another change is that the blur is applied before transparencies. It has its pros and cons visually (performance is the same) so if you prefer it the other way just comment out the tag "[ImageEffectOpaque]".

    Disabled:


    Enabled:


    EDIT: More images:




     
    Last edited: Jan 14, 2017
  39. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    201
    Seems like somebody at Nintendo likes multiple scattering as well:



     
    matteumayo and No0B25 like this.
  40. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    201
    Farelle, Shawn67, hopeful and 2 others like this.
  41. smonz3

    smonz3

    Joined:
    Jan 9, 2017
    Posts:
    15
    Hey OCASM, this looks fantastic! Any chancce you're planning on getting this to work with Forward Rendering? Would be great to be able to implement this into some VR projects..
     
  42. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    201
    Sure, I'll give it a shot today.
     
    smonz3 likes this.
  43. smonz3

    smonz3

    Joined:
    Jan 9, 2017
    Posts:
    15
    Awesome :) I'll keep an eye on GitHub for it!
     
  44. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    201
    Github updated. In order to make it work with forward all you have to do is comment out the lines marked "Deferred" and uncomment the lines marked "Forward":

    In SSMS.cginc the lines are: 240, 241; 278, 279.
    In SSMSGlobalFog.shader the lines are: 135,136; 140,141; 171,172.

    I suppose it's not the most elegant solution but oh well, it works :p.
     
    matteumayo likes this.
  45. Dave-Carlile

    Dave-Carlile

    Joined:
    Sep 16, 2012
    Posts:
    959
    Can you do conditional compilation in shaders?
     
  46. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    201
    You can use keywords for that I think but I haven't really messed with that yet. I'll look into it, though.
     
  47. smonz3

    smonz3

    Joined:
    Jan 9, 2017
    Posts:
    15
    Wow OCASM, you're fast :D thanks!
     
    StevenPicard and OCASM like this.
  48. Skolstvo

    Skolstvo

    Joined:
    Dec 21, 2015
    Posts:
    107
  49. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    201
    EDIT: Reading it properly I see they're only referring to light not being completely obstructed by the fog. That's a feature already in SSMS. Just set "Max Density" lower than 1 (by default is 0.999).
     
    Skolstvo and hopeful like this.
  50. PixelMind

    PixelMind

    Joined:
    Aug 16, 2013
    Posts:
    100
    This looks absolutely fantastic. Thanks for sharing!
     
    OCASM likes this.