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

True Volumetric Lights (Now Open Source)

Discussion in 'Shaders' started by Michal_, Mar 10, 2016.

  1. Dreamaster

    Dreamaster

    Joined:
    Aug 4, 2014
    Posts:
    148
    Can I ask a silly question? If you brought in the volumetric directional light to your atmospheric project, is there any reason to keep two projects separate when all one lacks is volumetrics for the other light types?
     
  2. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    365
    Not a silly question at all. It is actually a bit complicated.
    Short answer is that they're not the same thing. I only took part of it and have to modify it to work with atmospheric scattering. They are similar but different enough to make it hard putting them in one system.

    Long answer. This is kind of hard to explain. I hope none of you is a physicist :) Volumetric lights only simulate interaction between light and "large" air particles like water droplets, ice crystals, dust etc. That's what fog, smog, haze is made of but that's not all what our atmosphere is made of. There are also small air particles like oxygen and nitrogen molecules. They too interact with the light but the effect isn't really visible for short distances (several kilometers). So you can easily ignore them if you're only after fog.
    They do play a vital role in atmospheric scattering though. Those air molecules are the reason why sky color is blue during the day and reddish at sun set. Atmospheric scattering has to take both particle types into account and their densities at any given altitude have to be somewhat similar to Earth. You wouldn't get blue sky otherwise. Determining how many particles are there in a way of any incoming light ray is very expensive. You have to precompute a lot of information to make it suitable for real-time rendering.

    All this means that both systems are performing different calculations on different data. Volumetric lights are using very simplified atmosphere model that can be evaluated at run time and atmospheric scattering is using more realistic model but has to rely on a precomputed data.

    I hope that explains why I decided to split them even though they do share something. It is possible I'll make them work together better or even merge them into one project in the future. I'll wait and see if anybody is actually using it. Right now, the Atmospheric Scattering project seems to be flying below radar.
    Also, one of the teams at work wanted to try it in one game. That means I could be making polished, optimized version at work. Chances are I wouldn't be able to publish that for obvious reasons. We'll see
     
  3. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    Yes, but you can "re-implement" it according to Carmack.
     
    PeterB and Enrico-Monese like this.
  4. nbac

    nbac

    Joined:
    Jul 7, 2015
    Posts:
    267
    okay i do understand why you do not put it as one project but are we able to use both systems in one scene or do the leverage each other?
     
  5. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    365
    They are completely separate at the moment and you can use both. As long as it works that is. I didn't try it yet. There could be some bug that prevents them from working together. I plan to look into it.
    And even if it works already, they don't share anything atm. You'll be paying full prize for both.
     
  6. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    Speaking of bugs, is it possible that there is an issue with the volumetric light solution that causes the scene to "fog up" massively (from subtle effect to whole screen is white in the next frame), when making changes to unrelated shaders or textures while play mode is running? I've encountered this so often that I turned the volumetric light script on the camera off for testing other things, because it got in the way of A/B testing small changes to textures etc.. It's a shot in the dark, but could it be that the asset has an issue with serialization and deserialization?
     
  7. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    365
    I know what you mean. Super annoying, right? That's one of the things I wanted to address in the upcoming "clean up" patch. Material parameters are reset when Unity recompiles a shader and some of the materials aren't ready for that. I'll show you how to fix it next time I'm around a computer.
     
    shkar-noori, Alverik and Martin_H like this.
  8. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    Awesome, good to hear you're on it! I'm in no rush, just let us know when it's up in the repo :). Thanks a lot!
     
    shkar-noori likes this.
  9. TerraUnity

    TerraUnity

    Joined:
    Aug 3, 2012
    Posts:
    1,247
    @Michal_ Awesome pack and you are one of the coolest people around.

    Reviving this again as it hasn't been requested but I really need to know if it's possible to support forward rendering!

    Keep up the great job ;)
     
    Alverik likes this.
  10. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    417
    I second that, if it's possible. A great deal of systems still use forward rendering. In the country where I'm at right now, for example, Pentium 4 is still pretty common. People who are doing better have dual cores, and the well off have I3 or if they're very well I5 or I7 systems, but that's not the norm... Most other people just get smartphones instead, as they are given "free" by the ISP/phone company as part of a sale plan, also most people don't even know what a video accelerator card is for, and rarely buy them... and I'm sure this kind of situation is still true in a lot of countries...

    Using deferred rendering only, leaves out too much audience for my liking, so whenever I see people making their effects compatible with both render styles it makes me very happy. Anyways, if it's possible it would be really cool to have a version for forward rendering, even if it was a bit simplified.
     
  11. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    I think if you target such hardware specs you don't have the performance budget for volumetric lights anyway (I have an i7 with a gtx 660, running the volumetrics at half resolution and very low samples because I pixelate the image afterwards anyway, and it still is a noticeable performance hit). If lowend hardware in your target market is your only reason to want forward rendering compatibility, then it seems rather pointless to me. I think there's no way they can run any volumetric light solution on such old machines. You'll need to fake it just like games from that era did (static transparent sprite light beams coming from windows etc.).
     
  12. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    417
    My point was that there are tons of systems out there which don't use the latest tech, like it's usual in countries like the U.S. Target hardware varies per project, but having the option to allow effects on older video cards is always desired. And you never know where the implementation will go, hopefully the asset will get faster over development.
     
  13. TerraUnity

    TerraUnity

    Joined:
    Aug 3, 2012
    Posts:
    1,247
    I agree with all being said above. You can't expect to have fancy graphics and low budget at the same time.

    However my request was based on the deferred rendering path limitations itself and not the hardware bottleneck. The main 2 reasons for me regarding deferred limitations are:

    • Mesh Renderer's Receive Shadows "Flag" HERE

    • Render Settings' Fog HERE


    However, I managed to solve them for now as follows.


    For the Receive Shadows option on Mesh Renderers, I think the documentation only points to the flag checkbox which is disabled when Unity is in deferred mode. You can simply set the mode to forward rendering, select & enable Receive Shadows checkbox on desired game objects and then revert back the rendering mode to deferred again! This way objects will receive shadows in deferred either or am I missing something?! Why isn't it available at first place!​

    Maybe it is disabled to be controlled by scripts through the API and also I heard that enabling/disabling this option had no effect at all as it was always enabled before so devs decided to bypass this option completely.



    Regarding the missing fog in deferred, I can not use the Global Fog image effect either, because I have a 2 camera setup which first camera renders the whole world without any effect and then passes it to the second camera which only renders the vehicle/player with all needed image effects. Global Fog effect relies on the camera's far clip plane and most importantly the 2nd camera's Depth Texture does not have world objects information to generate fog from.

    Why is there a 2 camera rig?
    Answer: Having more control over main player's shadowing while there is other shadow settings (e.g. very long shadow distance) for world objects being rendered by the 1st camera.

    Anyway, the workaround is to use a volumetric fog system.​


    So to make the long story short, having support for all available rendering paths results to reach a wider audience whether they have complex settings as mine or not.
     
    Martin_H and Alverik like this.
  14. gian-reto-alig

    gian-reto-alig

    Joined:
    Apr 30, 2013
    Posts:
    756
  15. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    see below:
     
    red2blue, Alverik and gian-reto-alig like this.
  16. nbac

    nbac

    Joined:
    Jul 7, 2015
    Posts:
    267
    this is fantastic! thanks! credits to you michal and kode80
     
    Last edited: Aug 10, 2016
  17. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    Wow, I haven't heard that term since 1998.
     
    Reanimate_L, Martin_H and Baldinoboy like this.
  18. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    365
    I'll do it in a matter of days. I have a bunch of changes/improvements in a separate branch I wanted to include but I'll leave that to a separate update. It still needs some work and it looks like I won't have time in the next few weeks.
    Still no plans. You have to understand I'm making all of this for fun in my free time. Reaching wider audience was never really part of it. I guess the best I can do now is to give it a moment to see how difficult it would be... no promises
    I haven't tried it yet but we talked about both solutions quite a lot with Lexie. Both projects are very, very similar. Both are based on Killzone and Lords of the Shadows tech papers. The main difference is that Lexie spent a LOT more time polishing his version. Especially filtering/upscaling is a lot more sophisticated. You get a very clean image as a result and you can render at lower resolutions and use less raymarching samples. All this extra work should theoretically make it slower (with the same number of samples) but I know Lexie really tried to optimize it. He needs it for his own game too. I have yet to do my first profiling session...
    That's great! Looks like all three assets work together after all
     
  19. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    I too tried to combine the assets but I found that the clouds are rendered over the volumetric light. Will not be an issue until your camera is at ground level.
     
  20. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    417
    Sorry man, my native language is Spanish and that's how they call them in normal speech even now (in Spanish, here). For some reason, It just felt weird to say GPU or something similar when referring to the way people know about them in here, I think you'd be hard-pressed to find average people who even know what GPU means (plus the acronym is in English), not a problem for technicians or other people working in IT here, I guess...
     
    Last edited: Aug 10, 2016
    Martin_H likes this.
  21. IronDuke

    IronDuke

    Joined:
    May 13, 2014
    Posts:
    132
    Could you tell us which specific assets were used in this? (Naturally Michal's volumetric lights, but I'm also eyeballing those clouds...)

    --IronDuke
     
    Alverik likes this.
  22. elbows

    elbows

    Joined:
    Nov 28, 2009
    Posts:
    2,502
    IronDuke and Alverik like this.
  23. Dreamaster

    Dreamaster

    Joined:
    Aug 4, 2014
    Posts:
    148
    IronDuke likes this.
  24. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    365
    It is live. I just noticed I changed format from RGBA16 to RGBA1010102 for some reason. I'm not sure it was a good idea. It kind of depends on your project needs. Feel free to change it back. It takes 50% less memory and it is potentially a little faster but gives you less precision.

    Edit: Damn. I just realized directional light is using the alpha channel. I'll revert the format back
     
    Alverik likes this.
  25. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    Thanks a lot for working on this! In case it matters, I'm using directional light with a light cookie to simulate cloud shadows.
     
    Alverik likes this.
  26. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    417
    Isn't there a workaround? or the possibility to be able to switch the mode in editor? it's always cool to have options to make things better performant. I usually don't mind if precision or overall quality drops a bit if there's something be gained from it.
     
  27. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    Alverik likes this.
  28. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    417
    I see, but still, changing the code every time I want to change a setting still feels a little time consuming, and your never know when you'd like either option. I for one, like the option to be able to tinker with options until I find a group of settings that fit my case. Also it's been like 2 or 3 months since I started to learn C# (and programming in general... as I'm mostly an artist/designer), so I don't know how I would go about adding the in-editor settings myself...
     
  29. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    365
    Yeah, I was thinking I'll make some of the hard-coded constants adjustable from the editor. I know it is not super user friendly. I never really expected people to use it as a finished product. I'm still surprised how many people are happy with this rough prototype/hobby project.
    Anyway, don't expect anything soon. It is crunch time - only work and sleep for me for the next week or two :)
     
    Alverik likes this.
  30. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    417
    Man, it looks amazing! And it's free! Honestly that's the perfect combination. Even if there are a few drawbacks, they're not even close to overshadowing the value of the asset.

    Also, we know you have a life (if you can call crunch time that, lol), so don't worry. And anyway, are you working on a game right now or is it some other type of app? whatever the case I'd love to hear about it.
     
  31. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    @Michal_ I am having a performance problem...
    I added the vol script to several lights in a new scene (4 to be exact, not sure how many is overkill), and when I press play it runs at a smooth 13 fps.

    The profiler says gfx.waitforpresent takes upto 80ms to run, and disabling all those components seems to fix it.
     
  32. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    417
    Ummm... I don't know if I'm being super noob by saying this, but has anyone tried using threading (like with threading Ninja) or better coroutine systems like MEC for heavy computations? I'd guess if you can qualify anything as heavy computations, then this is it. If there's any heavy code computations in the effect, maybe it'd be worth checking if any of those assets or custom made versions, with the same idea, might help?
     
  33. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    So far I haven't seen the whole-screen-turns-white-effect yet in the new update. But on the two occasions where I deliberately changed a script and waited for it to recompile in editor play mode, Unity just froze. It also happens with the volumetric light script disabled though. So I'm not sure if it even is related.

    Edit: It's not a big issue though, make sure you get through that crunchtime without straining your health and then prioritize taking a break in your free time. I've seen burnout hit people, it's no joke.
     
    Last edited: Aug 13, 2016
    Alverik likes this.
  34. TerraUnity

    TerraUnity

    Joined:
    Aug 3, 2012
    Posts:
    1,247
    Fair enough, keep up the great job ;)
     
    Alverik likes this.
  35. Aerys

    Aerys

    Joined:
    Aug 3, 2016
    Posts:
    15
    First test using the free megascans library on unity 5. I have also used the really powerful @Michal_ volumetric light system!!!

    Hope you enjoy
     
  36. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    417
    Very cinematic shots! Nicely done. And the light looks amazing ;) Seriously, it wouldn't look as cool without the lights (as the're just rocks, lol - great textures and meshes though).
     
  37. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    I can't find this megascan library, can you point me the way?
     
  38. elbows

    elbows

    Joined:
    Nov 28, 2009
    Posts:
    2,502
    https://megascans.se/
     
    Alverik and yc960 like this.
  39. Neoligero

    Neoligero

    Joined:
    Nov 5, 2015
    Posts:
    1
    I found this strange behavior when the camera goes in and out of the light.

     
  40. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    365
    Strange. Never saw that before. I used dozens of lights without any problem. Are you still having the issue? Can you create a minimal repro project?
    Yeah, that's just Unity. It takes very special care to make the scripts recompilable. I never saw a project that wouldn't freeze Unity when recompiled on the fly.
    I don't remember exactly but I think some magic numbers are involved in the collision detection. I didn't want to bother with near plane, fov etc. so I took a shortcut. I'll take a look when I have time.
     
    Alverik and Martin_H like this.
  41. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    Thanks for the catch-up, sorry I haven't replied until today, went to a business meeting :D

    If I have 4+ lights with this on, I get a frame-drop of more than 40 frames down to around 30, running on a VERY high end system.

    Also, didn't notice this until our latest build but it appears as though the volumetric lighting is not working in a build (Windows, haven't tested on anything else); everything is fine in editor, but simply not there in a build.
     
  42. TerraUnity

    TerraUnity

    Joined:
    Aug 3, 2012
    Posts:
    1,247
  43. abramelingames

    abramelingames

    Joined:
    Jul 15, 2015
    Posts:
    44
    Very cool and interesting. I put you on the credits. Thanks for share this.
     

    Attached Files:

    Michal_ likes this.
  44. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    365
    Hey guys,
    just to let you know I didn't abandon the ship yet. Something else came up. I somehow managed to get myself involved in three different projects at work and the milestones sometimes overlap in a nasty way. I'll get back when I can.
    Are you sure you have all the shaders in "always included shaders" in graphics settings? Check the Unity log file. There is likely some kind of error. Possibly missing shader.
    Looks great. Thanks for sharing.
    I'm glad you find it useful. Is there a website or something? I'd like to know more. PM me if it is a secret.
     
    Alverik, yc960 and Martin_H like this.
  45. abramelingames

    abramelingames

    Joined:
    Jul 15, 2015
    Posts:
    44
    this is the site:
    http://abramelingames.blogspot.es/
    the project named 'injection π23'
    i worked on it, the downloadable version available is old (unity 5.2), for the next downloadable version (in 5.4) I will include the volumetric lights : ) ... the change is awesome
     
  46. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    365
    @TerraUnity @Alverik I pushed update with forward rendering path support, in case you're still interested. It wasn't difficult after all.
    @Neoligero That clipping issue should be fixed in latest update. I wasn't a clean solution, it was a quick one. I hope there aren't any side effects.

    Let me know if I broke something, I wasn't very careful.

    About the future. I still have a few improvements in mind but I can't bring myself to start working on it. I need a change. I'll keep fixing bugs but that's about it for now. Maybe I'll return to it after some time
     
    TerraUnity, yc960 and Alverik like this.
  47. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    417
    Hey, great man, thanks! And yeah, that's alright, working on the same thing for a long time can get tiring. It's good to have other projects too to get one refreshed :)
     
  48. neoderthal

    neoderthal

    Joined:
    Jan 16, 2015
    Posts:
    1
    Hi Michal
    it's very nice of you what you did here...i will try that for my project.. if i'm able to finish my project i will buy you a nice steam or amazon gift card
    :p

    Thanks !
     
  49. TerraUnity

    TerraUnity

    Joined:
    Aug 3, 2012
    Posts:
    1,247
    Many thanks Michal, It's already great and useful. Take your time and keep up the great job.
     
    Alverik likes this.
  50. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    A question. This item does not seem to work properly with transparent items (a.k.a windows). I would consider this quite important. Any ideas on how to mitigate this? Since it is clear that, for example, stained glass we can't possibly have all those intricate design models as a mesh...

    Thanks!