Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Dynamic Volumetric Lighting replacement

Discussion in 'Works In Progress' started by Lexie, Jan 11, 2016.

  1. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Could you post a picture of the artifact you're talking about, maybe one of the shaders isn't working on your graphics card.
     
  2. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,398
    I think all the shader are fine honestly.
    upload_2016-1-21_16-23-6.png
     
  3. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,341
    What is the difference between this and Sunshine?
     
  4. CWolf

    CWolf

    Joined:
    Oct 24, 2011
    Posts:
    106
    We bought Sunshine last year. Last time we checked it only supported a Directional light (didn't support point and spot lights) so it was useless for us.
     
  5. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,133
    Like I said on slack, this is looking amazing! Congrats!
    Btw, I wonder if UT has plans for - at least - adding a better filtering to the point light shadows, I do not buy those stacked/pixelated shadows as "soft shadows" at all.
     
  6. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,729
    Could just be solved by dithering the result to reduce banding maybe.
     
  7. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    EDIT: Sorry didn't zoom all the way in, you are correct. its hard to see them when the camera is stationary cause it only when the camera moves do you really notice them.
    Ill leave my below answer cause it explains other issues with this technique.
    END EDIT

    Thanks for this, Yeah those are the result of the depth aware blur (uses full res depth for this step), There are some numbers you can tweek to effect those. changing the numbers results in those artifacts showing up on distant things or close things and lowering the bleeding and shimmering pixels. I need to do a depth aware blur otherwise you get a lot of blooming and flashing pxiels. Maybe i could do a normal blur after the depth aware blur to remove the artifacts it can create. that way the blooming and flashing pixels will be way smaller and less noticeable. but you still get the hard edges on your scene geometry.



    Sunshine only supports Directional. Also it's quality on anything lower then full res looks bad IMO. It's because of the way it does its up-sampling and blurring. it results in your scene geometry's edges looking low res.

    Here's an example of the low res edges im talking about, it has a slider to blur this edge but it results in far way things being low res or your whole scene being bloomed out.



    I'm working on getting the default unity directional light working with my volumetric system. That way people wont have the overhead of running two volumetric image effects.
     
    Last edited: Jan 22, 2016
    Rodolfo-Rubens and manpower13 like this.
  8. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    yeah dithering the final HDR results will help remove the banding that happens. Thanks!

    Edit: Rather then adding dithering I did a technique used in film. Here are the results (left old, right new). Looks really good and didn't cost much at all. Click to full screen otherwise you're looking at a compressed image.

     
    Last edited: Jan 21, 2016
    hopeful likes this.
  9. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,341
    Actually, I only need one directional light (sun), so if you can get that to work, it would be great.

    Also, did you try Shadow Softener and how does that compare to your method?
     
  10. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Mine has better shadow bias, less acne, less peter panning. My soft shadows on point lights looks much better. The softness on spot and directional light look very similar (both use PCF with interpolation)

    It is hard to compare both these plugin as they work to extend unity's lighting. Were as mine completely replaces it. There are downside and upsides to replacing the lighting.
     
    Last edited: Jan 23, 2016
    CWolf likes this.
  11. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    I'm pushing a new test build if anyone is interested. Quarter resolution now looks a lot better. I'm happy with the quality vs fps it gives now.
    • Slightly faster volumetric lighting
    • Improved artifact reduction on half and quarter resolution while still retaining a strong silhouette.
    • Removed color banding by introducing a small amount of white noise into the final results. (might boost this effect a little more)
    • Enabled sample count and blend count keys to play around with.
    • Forced unity to use high settings on launch (saw some reports of unity starting in low).

    Ill work on directional lighting next week.
     
    Last edited: Jan 23, 2016
    mwituni, CWolf and elias_t like this.
  12. khos85

    khos85

    Joined:
    Jul 21, 2013
    Posts:
    541
    I would like to ask when you plan on releasing this nice looking asset? I really could use it for my offroad car game (on steam), I'm looking for volume lights for the head lights..
     
  13. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,341
    Did you try left clicking with the new test build? The camera will spin out of control.
     
  14. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Unplug your controller, there seems it be an issue with controllers and the fly camera im using. Ill fix it in the next build
     
    Last edited: Jan 24, 2016
  15. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Not sure yet. Working on stripping the volumetric lighting and getting it to work with unity's inbuilt lighting so more people can use it with no fuss. Hoping to get this done in two weeks.

    I know people want the speed improvements that my custom lighting gives so if I can fix a few of the downsides I'll release that as well.
     
    mwituni likes this.
  16. khos85

    khos85

    Joined:
    Jul 21, 2013
    Posts:
    541
    Ok great, keep up the great work! Hope you release this soon.
     
  17. Olafson

    Olafson

    Joined:
    Aug 7, 2012
    Posts:
    252
    With Default Settings.

    On my Laptop
    Unity 80FPS
    Custom 160FPS

    On my Desktop PC
    Unity 160FPS
    Custom 280FPS

    Awesome stuff.
     
    Rycons likes this.
  18. zugsoft

    zugsoft

    Joined:
    Apr 23, 2014
    Posts:
    446
    It's a amazing new job.
    Did you try on Mobile?
     
  19. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,341
    On my laptop I have the same problem, and no controller connected...
     
  20. S4G4N

    S4G4N

    Joined:
    Mar 13, 2013
    Posts:
    2,776
    Looking very good
    Is this going to be some kind of package that one can purchase ?

    @spryx check this out
     
  21. spryx

    spryx

    Joined:
    Jul 23, 2013
    Posts:
    387
    This looks incredible!
     
  22. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Strange, ill look into.

    I'm working on one now.

    Haven't tested on mobile yet. I'll test it out soon.
     
  23. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Amazing, well done, the most important thing that Unity needs for realtime games is improved lighting/shadows and this seems to be the solution.
     
  24. Soul-Challenger

    Soul-Challenger

    Joined:
    Dec 30, 2010
    Posts:
    152
    Do/will the volumetrics support varying "fog density": noise, gradient ?
    How is performance related to scale, view distance? Or is it post-effects based?
     
  25. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    you can change the global density as well as the density per light. The scatter type can be changed globally and per light.
    Right now it uses a fast 3D noise to add some variance to the air density, Ill probably add support for 3D textures as well.

    The gradient is based off the light attenuation. No plans to extend that just yet.

    The volumetric lighting is marched in view space, so performance depends on the amount of pixels each light volume takes up. There is also an overhead to the effect (downsampling, bluring, upsampling). If you run at a quarter resolution, you don't have to march through many pixels, so adding more lights doesn't have a very big impact.

    I've been trying to get my volumetric lighting working with unity's inbuilt lighting. unfortunately the API for command buffers and lighting is really limited, so limited in fact that its impossible to do it with the same method I use with my lighting. I have some ideas on how I could work around the limitations but it's too hacky and the results would be much worse then mine.

    I'm going to talk to some people at unity and request some features be added to the command buffer and lighting events so I can implement volumetric lighting with unity inbuilt lighting.

    For now I'm going to switch back to working on my Custom lighting.
     
    Last edited: Feb 1, 2016
  26. Soul-Challenger

    Soul-Challenger

    Joined:
    Dec 30, 2010
    Posts:
    152
    Thank you for the info! Sounds great :)

    Hope unity will respond in a favorable way to your requests concerning command buffer and lighting events.
     
  27. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    So one of the main speed increases comes from saving out data from previous frames. This requires space in the video card to store all this information. On low setting the space requirements for a standard scene are small, but on high and very high settings you need a lot of Vram to store all those textures.

    PCF Filtering helps a lot on stationary low res shadows, but as soon as you have moving shadow casters or moving lights the filter falls short and you see a lot of aliasing.

    So I've been working on using Variance Shadow Maps. The biggest upside to VSM is you can filter the shadows the same way you would filter a texture. this allows you to get really good results on low res textures. Pre-filtering the shadow maps means that soft shadows only take one texture look up! zero branching.
    This might also mean volumetric lighting will get soft shadow for free, but ill need to see what artifacts it creates.

    Here is a comparison: Left VSM with 7x7 tap, Right is unity's "soft shadows". Both use a 128 cubemap.



    I still need to figure out how to blur a RenderTexture cubemap in unity. I was hopping there would be a way to generate mipmaps but I haven't come across anyway to do it. If anyone knows how to solve these issues id love to know.

    Another added bonus is point lights now have soft shadows, rather then a grainy gradient.
    Ill work on cleaning up the code and i'll push another build for you all to play around with.

    Edit: After trying to reduce the artifacts that VSM makes. I have come to the conclusion that this method will not work for my needs.
     
    Last edited: Feb 3, 2016
  28. Olafson

    Olafson

    Joined:
    Aug 7, 2012
    Posts:
    252
    Sounds good!
     
  29. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    3,810
    I've been following this regularly for a while now. Any idea on when you might be ready to release something?

    Have you had any success with directional lighting?
     
  30. Zuntatos

    Zuntatos

    Joined:
    Nov 18, 2012
    Posts:
    530
    @Lexie Any ETA on a release? It'd be a shame if it was canceled now.
     
  31. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    I've been working on my own game for a while, I've switched over to using my lighting and modified the branch so volumetric lighting works with my runtime baked GI solution.

    http://hitboxteam.tumblr.com/post/139873080211/got-my-new-lighting-working-with-spire-modified

    I've also been working on an experimental thing for my game to get indirect lighting working with dynamic lights.


    Its pretty inaccurate but we have a lot of dark spaces and we need some indirect lighting to fill them. Pretty happy with the results but ill need to render this to a low res texture and upsample, similar to how the volumetric stuff works. Its just too expensive and grainy doing it at full resolution.


    I got directional lights working (no cascade). It's pretty rough and the same approach as unity's so I wasn't able to beat unity's performance. My plan was to get my volumetric lighting working with unity's directional and just using it for directional lights.

    I've also been messing around with Phase functions to simulate light scattering, the effects make the scene less foggy while still having volumetric beams when looking towards the light. Ill post some screen shots once I've made the editor to switch between all the different ones.
     
    Last edited: Feb 23, 2016
    elias_t, zugsoft and one_one like this.
  32. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    A comparison shot of unity's spot light vs mine. For some reason unity uses a cookie to sample the luminance rather then using a math equation, this results in awful artifacts around the edges of the gradient.



    I'm pushing towards getting a build ready for release.
    One day i will add IES support for lights. Not today though.
     
    Last edited: Feb 26, 2016
  33. macdude2

    macdude2

    Joined:
    Sep 22, 2010
    Posts:
    685
    @Lexie — you think you'll ever release your runtime GI? I'd love a solid system that could bake lightmap quickly for user generated levels.
     
  34. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    its runtime baked GI for those that don't know. ahh maybe one day. Our world is already voxelized so it was a lot easier to make. For it to work for other people i'd need to voxelize the world, That might end up being too time consuming for it to be usable in game. there are other methods like "just in time lighting" that would be better suited i think.

    if its just direct lighting then my current system should work perfectly. it handles a lot of dynamic lights as long as you put aside enough storage in VRAM.
     
  35. Olafson

    Olafson

    Joined:
    Aug 7, 2012
    Posts:
    252
    If you system does not improve on the Unity directional light, but does improve the point lights, it is still worth it for us.
    We are using a large number of point lights at night, and right now we need to disable their shadows to get decent performance. Would be sweet if we can enable those using your tool. Thx!
     
  36. macdude2

    macdude2

    Joined:
    Sep 22, 2010
    Posts:
    685
    I did know that, must have just been tired when I posted! My game, Metamorphic, is voxel based – each level comes from a portal 2 level editor-esque system. Could your runtime baked GI system work with that? I'd be extremely interested if so.
     
  37. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646

    Good to hear there would still be interest, although I do want to get volumetric directional lights working. Id rather not have to run two volumetric passes by having to fall back to using the sunshine plugin.

    In regard to my baked GI solution: The big issue is our light model is very different to how light works. The technique I'm using can support a more realistic light model, but the VRAM usage increase by 3 times. although a simplified lighting model on GI would still look nice with realistic lighting.

    Here is an image of my GI, This is a test scene and not representative of my game. Some tiles emit light, and the bounces from the directional light are baked. This is primarily what I use the GI for.

     
    CWolf likes this.
  38. macdude2

    macdude2

    Joined:
    Sep 22, 2010
    Posts:
    685
    Interesting, does it support spot or point lights yet or just directional lights?
     
  39. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    I'm guessing your talking about my Baked GI thing.

    Right now it supports directional, area, point. Haven't bothered with spot light yet cause i don't use them.
     
  40. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Today I got volumetric lighting working with my custom Directional lights.
    I still need to work on shadow filtering and cascade shadows.

    I decided to check out Sunshines volumetric lighting and do some comparisons. I modified my phase function to try and imitate the scatter function it uses, its not exactly the same but the results are similar.

    Both are done at quarter resolution with 16 samples and blurring enabled and cascade shadows disabled.

    Interactive compare

    Mine - 0.8ms.



    Sunshine - 4.58ms (Note: Not compressed, actually looks this bad)

    EDIT: I Hadn't fully configured the sunshine plugin, so it wasn't running at full inefficiency.
    My plugin is only slightly faster then sunshine, but my results are a lot better.

    As you can see the quarter resolution on the sunshine plugin is pretty unusable, this is because it uses a really simple method to up-sample the texture, resulting in those awful artifacts. There is a slider to blur those aliased edges, but the results are something similar to insane bloom on your scene. Also the signal loss is really large, looks like they don't use a tile method to increase signal sample count.

    More surprisingly my volumetric pass is a /edit: slightly /endedit faster. I thought my more advanced down-sampling, depth aware blur/up-sampling would result in lower fps... I was wrong.

    I think i need to blur the final result slightly to remove the hard edges in the silhouettes the depth aware up sampling leaves behind.
     
    Last edited: Mar 9, 2016
  41. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,341
    Wow, just wow. Will be an instant buy for me if it works well in a small confined area with lots of small details like an airplane cockpit. Will it work well in that use case?
     
  42. Olafson

    Olafson

    Joined:
    Aug 7, 2012
    Posts:
    252
    That looks good. Nice progress!
     
  43. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    I revised my downsampling, upsampling and blurring steps today. The directional light tended to expose a lot of the artifacts with the technique I was using. I have switched over to using a checkered Min/Max when downsampling the depth buffer, The results are a lot better now.

    Also adding one level of blur after up sampling tends to give really nice results.
     
  44. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    652
    I'm really impressed with your work here and I'll almost definitely be buying it as soon as you release it.

    I would like to see some examples of spot lights though. I've seen plenty of point lights and now directional, but I'd like to see how it looks with spots.
     
  45. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    I have another version of my lighting if anyone want to test it out.

    Download Version 4



    Rendering the volumetric lighting at a lower resolution is extremely important if i want to be able to ray-march more then a few lights. I've gone as far as I want to go with upsampling, I'm really happy with the results I'm getting. I know a few ways i could improve it, but I'm not sure if it's worth the trade off.

    In this build I have added my Dynamic volumetric Directional light, I still need to add soft shadows and cascade support so right now its limited to hard shadow on the directional. I've also included a bunch of spot lights and some trees that use the standard cutout shader. I've also added a bunch of moving objects to show off the power of stationary lights. Only the moving shadows need to be recalculated.

    When my volumetric lighting is enabled (default) there is no global fog, the "fog" you are seeing is a result of the light scattering from the directional light. If its disabled, the standard Global fog will be enabled to try and simulate the effect.

    If you run this scene on high settings you will notice the VRAM MB usage is pretty huge, The buffer size for stationary lights should be lowered, right now I have it set to 200MB, Ideally it would be better if it was < 80MB. You will notice that dropping the settings from high to medium will result in significantly less VRAM usage. its something like 100MB down to 20MB. This number is much more reasonable but the shadow fidelity of medium shadows are too low for moving objects. I plan on adding a resolution limit to the stationary shadow resolution. this will mean that moving objects or lights will render to a high resolution texture shadow map, while stationary shadows will render to one resolution lower. The downside of this is the shadow bias will need to be calculated based off the lower resolution, I still think my shadow bias and acne will be better then unity's even with this.

    added them just for you.
     
    Last edited: Mar 10, 2016
    adventurefan and Rycons like this.
  46. MaT227

    MaT227

    Joined:
    Jul 3, 2012
    Posts:
    620
    Hi @Lexie could you tell me more about the supported hardware and platforms ?
    Would it be possible to access the shadowmap ?
    Thank !
     
  47. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    361
    Hey, Lexie.
    I've been playing around with command buffers recently and I managed to extend unity's built it lights to make them volumetric. Volumetric lights take all settings from unity lights - color, intensity, shadow maps, cookies, attenuation etc. I just added few more parameters like density. I could tell you how I did it if you are interested. Here is my little demo.

    Edit: Here is a thread about my video. I got several PMs asking about it. PM me only if it is meant to be private. Thanks
     
    Last edited: Mar 10, 2016
    frosted, ArthurT, hopeful and 6 others like this.
  48. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    652
    Awesome. I look forward to trying out the new version tonight.

    Any word on getting it to work with Enlighten? Does the duplicating the lights work around work?
     
  49. gurayg

    gurayg

    Joined:
    Nov 28, 2013
    Posts:
    230
    Looking better and better.
    Thank you for showing your progress.
    Is the value next to "Hybrid" indicate the number of static shadow maps? How does that affect FPS ?
    The difference in memory size is dramatic between High and Medium but being able to give users a choice depending on their system is great.
    Look like if you can find a way to reduce the memory footprint (hopefully) your system will out perform Unity's in all cases.
    Would it be possible to see a daylight and indoor/outdoors hybrid scene at some point?

    All the best
     
  50. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Wow!, are you using the lightevent to access the shadow map and render the light volume? I looked into trying to do it that way but that event wouldn't trigger unless the light was casting a shadow. So if you took a shadow casting light and then moved it up into the sky away from shadow casting objects, the event would turn off. After finding that flaw I didn't dive in any deeper. I'd actually love to just use unity Directional light over my own. I couldn't figure out how to read the cascade spheres though. I'd love to know how you access those.

    I really wanted stationary lights for my game, its too expensive to render all the shadow casters every frame. I couldn't see a way to get that working with the inbuilt lighting unless I had the source. Volumetric lighting + Dynamic lighting is pretty costly. Downsampling helps a lot, but I wanted a method that could handle both and still be faster then unity's inbuilt lighting.


    I haven't tested it yet, Ill do it today. I noticed a really sweet asset on the store that does non shadow casting lights that can interface with enlighten, So there must be a way to get it working.


    Everthing is shader model 3 and Directx 9 compatible, It should work on all hardware. but it probably wont run that well on phones. The shadow maps would be accessible if you wanted to use the command buffer right after the light has finished rendering. The stationary shadow map would be accessible but you can't guarantee a light has one.


    Yes the number next to hybrid is the amount of stationary lights that have a saved shadow maps. this means that when it comes time to render this light. they only need to render the shadows of moving objects. A point light needs to render a lot of shadows when you think about it. you could end up rendering half of the objects in this scene 3-6 times per point light! This is where my system greatly outperforms unity's, with this extra time I can render Volumetric lighting, better soft shadows and better bias while still being faster then Unitys. If you hit M it will switch my system from hybrid to dynamic only. This basically tells the lights there is no buffers available and it has to render in dynamic mode. this also give you an idea of what the FPS would be like if all the lights in this scene were moving. If all the lights are moving, it becomes clear that rendering this many fully dynamic volumetric lights even at a quarter resolution is pretty unfeasible. (note: My dynamic spot lights are slower then unity's, I need to optimize them. My point lights however are normally slightly faster then unity's, Adding volumetric ontop however will cause my lighting to be much slower then unity's inbuilt, which is expected as i lose all that gain from stationary lights. However if you had a mix of moving and stationary, depending on the ratio, mine would be faster with volumetric turned on)
     
    Last edited: Mar 10, 2016
    gurayg likes this.
unityunity