1. We've introduced thread tags, search within a thread and similar thread search. Read more here.
    Dismiss Notice
  2. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    Dismiss Notice
  3. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  4. We've released our first Timeline Experimental Preview, our new tool for creating cutscenes and more! To check it out click here.
    Dismiss Notice
  5. Unity 5.5 is now released.
    Dismiss Notice
  6. Check out all the fixes for 5.5 in patch releases 1 & 2.
    Dismiss Notice
  7. Unity 5.6 beta is now available for download.
    Dismiss Notice

True Volumetric Lights (Now Open Source)

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

  1. abrasive

    abrasive

    Joined:
    Aug 10, 2014
    Posts:
    59
    Another warning comes out:

    Shader warning in 'Sandbox/VolumetricLight': 'SHADOWS_NATIVE' : macro redefinition at line 46 (on d3d11)

    Compiling Vertex program with DIRECTIONAL SHADOWS_DEPTH SHADOWS_NATIVE
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING
     
  2. smonz3

    smonz3

    Joined:
    Jan 9, 2017
    Posts:
    5
    Oh boy do these look beautiful. I read a while back that they weren't compatible with VR and you don't plan on making it so, is that still the case? I loaded up the example scenes and plopped a SteamVR camera in there and it looks to be rendering nicely in the editor window, on the headset it looks pretty good but for some reason the right eye is far more saturated with light than the left eye making for a slightly blurry image, otherwise the fog looks lovely. Any idea if that would be an easy fix? Would love to try and incorporate this into a VR game, though whether it is too taxing or not has yet to be seen! the example scene was running about 20 FPS :D
     
  3. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    309
    @abrasive I take it you don't like warnings :) The first one points to empty line. I don't know what's the problem. And the macro redefinition is harmless. I remember there was some problem with the SHADOW_NATIVE macro. I couldn't make it compile and work at the same time. I don't remember the details. I'd rather not touch it if it works.

    I mean, sure, there is a lot of things I could have done better. Especially the shadows. But I knew next to nothing about Unity when I started this project. And learning about inner workings of Unity was part of the motivation. This is by no means a polished product. I'd like to clean the source code but I don't want to invest the time.
    In fact, I'm working on different technique for volumetric lights. This time based on technology introduced in Assassin's Creed 4. So I'm unlikely to return to this one. I'll do bug fixes and compatibility patches but that's about it.
     
  4. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    309
    No idea what's the problem. I would take a quick look but I don't have VR. I can't help you unless Untiy lets me somehow see images for both eyes without actual hardware.
     
  5. abrasive

    abrasive

    Joined:
    Aug 10, 2014
    Posts:
    59
    Many thanks! :)
    Yep, I try to avoid warnings in my projects. This way I feel much better in making games ;)
    I plan to use Unity 5.3.x for a long time, so please do not stop support of this version like others do.

    So far the result is superb in image quality with Unity 5.3.7!
    Well done! :)

    Please continue work on this great asset!
    Now I start to learn the Unity shader stuff too, so one day I may help in developing ;)
     
    Last edited: Jan 20, 2017
  6. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    309
    That flipped camera problem that some of you reported was cause by Forward+MSAA combination. It is fixed now. I also tried to run it in 5.6b2 to see what's the problem and didn't find any. It works for me...
     
  7. AntonyQS

    AntonyQS

    Joined:
    Nov 14, 2016
    Posts:
    13
    Really awesome plugin dude, appreciate the time and effort you've put into it.

    'Quick' question: I'm currently using Tenkoku Sky setup, but the volumetric lighting seems to be misting up the sky some. I've had a quick tweak of various setups for the Volumetric lighting on the world directional light, but can't seem to find a balance between nice close rays and not having the sky blown out.

    This is something we'd like to include in later scenes as an effect, but for the generic feel we need to see the sky. So after the ramble I essentially have 2 questions:

    1.) Is there any way to have close rays/volumetric style lighting whilst retaining a background sky?
    2.) Is there any way to dynamically change the strength of volumetric lighting on interiors so it's more pronounced?

    Again thanks for all the cool work you're doing on this!

    Cheers,

    Ant
     
  8. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    309
    1) Skybox extinction parameter didn't help? It could be modified to remove fog from skybox completely if desired. Keep Max Ray Distance to minimum to accumulate less light along the ray. Or the accumulated light could be clamped to some max value.
    Otherwise, this is often solved with properly setup height fog. That's what happens in reality after all. Particle density decreases with altitude. This way objects around you (close to ground) are in fog but if you look up you can see the sky clearly. Here's a simple example
    heightfog.PNG

    2) Not sure what you mean. You don't want to change intensity of individual lights but control them all at once? Some sort of master intensity multiplier?
     
  9. olivers89

    olivers89

    Joined:
    Nov 25, 2013
    Posts:
    3
    first of all, i absolutely love the volumetric lights!

    i encountered an issue that i think could maybe fix for me if someone pointed me in the right direction.

    I am working on a little game with planets in the super mario galaxy kind of way.
    the lights work perfectly but sometimes turn off, even when on screen when i look up to the sky (from the gravity source up) like so, you can see the light setup in the inspector, the gif shows the effect i got: Off.png On.png Show.gif

    I'd be really grateful for any help or pointers as how to fix this "lightswitch" problem. From what it gather it happens everytime the lightsource is in the lower half of the Camera. thank you so much in advance!

    Unity 5.5.0f3 - OSX Sierra 10.12.1 - AMD R9 370X
     
  10. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    309
    @olivers89 Does it happen when you disable shadows on your light?
     
  11. olivers89

    olivers89

    Joined:
    Nov 25, 2013
    Posts:
    3
    hey @Michal_ no it does not.

    I have not encountered this behaviour when having moving objects (updated by position directly, or animated via Unity Rigidbody physics) interact with the light.

    gif4.gif
     
  12. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    309
    Unity stops rendering shadows when there are no shadow casting objects inside light's volume. It also stops executing callbacks and that breaks the effect. Unfortunately there is currently no way how to detect it happened.
    You have to make sure there is some shadow casting object inside light's volume at all times. That will force Unity to update shadow map and execute callbacks. It could be a tiny object, object hidden behind other geometry or a small invisible object that only renders to shadow map.
     
    Alverik, chelnok and Martin_H like this.
  13. AntonyQS

    AntonyQS

    Joined:
    Nov 14, 2016
    Posts:
    13
    Sweet, thanks for the help on this! I've managed to get it less washed out in the distance now. As you said the light ray distance was also providing a small amount of distance based fog so bringing that down to a value of 10 seems to keep the rays obvious enough to catch the eye.

    In relation to the second question I had, it was regarding how the volumetric lighting is handled in interiors with an area light (ie no source of direct point lighting) being stronger than the one that's attached to the directional light for the landscape...I think I answered my own question in playing with these settings again per light though, so don't worry about that! :)

    Again, thanks for the help and this IS an awesome plugin.
     
    Michal_ likes this.
  14. olivers89

    olivers89

    Joined:
    Nov 25, 2013
    Posts:
    3
    @Michal_ thank you very much for your time, i appreciate it! i still had the issue, and it took me a while to realise that i also need to up the shadow draw distance too in the quality settings :) awesome asset!
     
  15. gian-reto-alig

    gian-reto-alig

    Joined:
    Apr 30, 2013
    Posts:
    723
    Hi

    I have a problem with the volumetric lights. I am trying to use it in an indoor level with an isometric view. thus lots of lights whose light volumes intercept the walls and floors of the level.

    The idea is to keep the surrounding spaces not occupied by level geometry complete black (kinda like in old style isometric games):

    VolumetricLightProblem01.png

    That plan works quite well as long as the volumetric lights are switched off. As soon as I switch them on, this happens:

    VolumetricLightProblem02.png

    Everything turned up way higher than sane in the volumetric light script so the problem becomes more visible.
    As you can see, the volumetric light volumes penetrate the walls and floors and continue into the black space. Now, this has nothing to to with shadows or no shadows. The smaller point lights on the pillars are using no shadows, while the spotlights on the (invisible) ceiling are using realtime shadows.
    Both light volumes seem to ignore my wall and floor geometry.

    I guess this is just how the volumetric light script and shader curently work.


    Now, my question is: is there a workaround to prevent this from happening? Is there a way how I could enhance the script so the volume gemometry gets created in a way that the volume no longer penetrates walls and floors?
     
  16. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    2,415
    Do you have the walls set to cast shadows too? I don't see the columns casting shadows so I'd think that's the source of the issue. Based on my experience with the asset I think it should look different than your screenshots.
     
  17. gian-reto-alig

    gian-reto-alig

    Joined:
    Apr 30, 2013
    Posts:
    723
    All of them are set to cast shadows. What you see in the image is that the shadow casting light cone are barely touching the column, so the shadows are actually rather weak at that point, and they overlap with the light cone of the next shadow casting spotlight, so the shadow is next to invisible.

    Then there are the point lights not casting shadows as these are fainter, shadows are less noticable and I had to compromise somewhere to keep the framerate up (will experiment with baked shadows once 5.6 hopefully brings improvements to shadowmap baking).
    Thing is, all the wall and floor geometry is set to cast shadows, yet both the shadow casting as well as the non shadow casting lights seem to ignore the geometry when it comes to the volumtric light volume.

    Tested the shadow casting lights with a white plane below the floor.... the light is not going through the floor geometry, shadow casting works as expected. The no shadow casting point lights of course do, I guess I will need to bake shadow at least for those (if that helps with the light volumes though IDK).

    Another test, switching of the point lights, still shows the shadow casting light volumes going through the geometry.

    EDIT: Some more testing revealed something interesting.

    I switched all the point lights to using shadows. And now I see a little bit clearer where things go wrong. Seems like at least as long as shadow casting is used, the light volumes do not completly ignore the geometry:

    VolumetricLightProblem03.png

    As seen in this image, the light volume is using the wall geometry shadows in the upper part of the wall.
    BUT:

    VolumetricLightProblem04.png

    Just behind the wall, at some point the light volume starts to leak through... seems like at some point the wall geometry just isn't thick enough anymore, if that makes any sense.


    EDIT2:

    Based on my prior finding, I experimented with an additional cube with the same flat black material behind the walls, and a plane with the black material just below the floor height to block the light volumes. Seems to work fine to make sure light is not leaking through, respective the light leakage is not visible in case of the leakage through the floor.

    Now, this only works with shadowed lights.... is there anything I can do for non shadowed lights, as I am still not convinced I should use shadows for all the lights.
    Could I make the volumetric light shader use a special cookie to prevent the light leakage, like a cookie that shadows the light just where the wall is?
     
    Last edited: Feb 6, 2017
  18. AlexLFC

    AlexLFC

    Joined:
    Dec 6, 2016
    Posts:
    1
    Fantastic efforts Michal and thank you so much for sharing, it really adds something to my VR scene!
    I've added it to a torch attached to a hand controller, it works so well.

    And like Smonz above, sadly this only works in the left eye and not the other.

    I think the saturation he talks of in the right eye is the raw light without your fog/volumetric, and the left eye is a little washed of colour due to the added fog your plugin adds.

    Is there anything you could suggest? Thank you!
     
  19. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    309
    @gian-reto-alig Light leaking is a general problem. Not limited to volumetric lights. If you put an object behind your wall it will be incorrectly lit by your point lights. Shadows are easiest ways how to prevent it. Just make sure the light isn't too close to other geometry and/or tweak shadow bias. Using shadows on this many lights will obviously have big performance impact...
    Cookie is another option. For example, make a cube map with one half black and you can have a point light that only works in one hemisphere. Might be good enough for a light snapped to the wall. You could modify the script to have separate cookie for light and volumetric light for more control.
    Best solution in your case would probably be to bake shadow maps at compile time and use them at runtime. You would get full quality for little performance cost (at least for static lights).

    @AlexLFC Still don't have any way to test it. So I have no idea. You can try to capture a frame with RenderDoc, Visual Studio or NSight and send me the file. I'll take a look.
     
    gian-reto-alig likes this.
  20. HenriqueGomez

    HenriqueGomez

    Joined:
    Dec 13, 2012
    Posts:
    57
    Hey guys! Is there any way to make this executable in Edit Mode?
    Tried adding the tag [ExecuteInEditMode()] but it returns several errors requesting me to change the Destroy functions in VolumetricLigthingRenderer.cs to DestroyImediate.
     
  21. RavenTravelStudios

    RavenTravelStudios

    Joined:
    Oct 15, 2015
    Posts:
    45
    This is great. ♥ thanks :)
     
    Last edited: Feb 13, 2017
  22. KillTV

    KillTV

    Joined:
    May 14, 2015
    Posts:
    4
    Just updated to 5.5.1f1 and this awesome shader/fx has stopped working and is now generating errors: I updated to latest version from the repo and was about to post the errors here when I noticed that the editor was running in DX9 not DX11. On further investigation it seems that there is a bug in Unity which is causing some people (including me) to not be able to run the editor in DX11. I grabbed the 5.6 beta (which has a million other issues) but doesn't have the DX11 problem and it looks like the shader problems go away. I was unable to test this properly as I couldn't run my builds in the beta due to the other problems but I wanted to share this info with anyone else who is having the same problems.

    I believe that 5.5.0 also is ok, so anyone using this most excellent shader might want to re-consider updating beyond 5.5.0 until a stable 5.6 is out or the issue is fixed in some other release.

    I don't post on the forums very often, but thought it might be worth it in this case.

    And of course to say, this Rocks and thanks to Michal :cool:

    Edit: https://issuetracker.unity3d.com/issues/failing-to-create-dx11-device-on-windows-7
     
    Last edited: Feb 16, 2017
    chelnok, Martin_H and Michal_ like this.
  23. Soul-Challenger

    Soul-Challenger

    Joined:
    Dec 30, 2010
    Posts:
    138
    Finally got some spare time to get back to testing this. Thanks again for your work Michal, what a great way to enhance the atmosphere! Here's a recent one:

     
  24. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    428
    this chase sequence look very cool! he just miss the scream of the poeple.
     
  25. AdanGrotesco

    AdanGrotesco

    Joined:
    Sep 26, 2015
    Posts:
    30
    Hi! I really love your work and y really interested in use it in my proyect, but i cant find a way to implement with ufps. Can somebody help me with the correct one to mix the two tools (both are complet proyects) and working good?really thank you all!

    PD: sorry for my bad english!
     
  26. Prokishta

    Prokishta

    Joined:
    Oct 17, 2016
    Posts:
    1
    its realy cool but it very lagy
     
  27. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,024
    Started using this again. Looks incredible. Adjusted values some so only losing a few frames.

    Problem is I am still not getting the effect in any builds. Looks amazing in editor but nothing in build. Really need to get it working but am not getting any errors so not sure what to do.

    Using 5.5.0
    Windows 10
    Dx11
     
    Last edited: Mar 5, 2017
  28. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    2,415
    Did you manually add the shaders to the list of always included shaders? Iirc that's what solves this.
     
    Lex4art and hopeful like this.
  29. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,024
    That got it working. Sorry about that. Thanks for the help. Man I love this effect!
     
    Martin_H likes this.
  30. Animagic

    Animagic

    Joined:
    Nov 17, 2016
    Posts:
    1
    These Volumetric lights provide quite the nice touch to even the small project that I am working on. I definitely appreciate the work that has gone into lights and hope to see some more in the future. I have looked through the forum her and can't seem to find an answer for an issue I am having with the position of the rendered volumes when using these lights, though.

    In the scene below, when using a Perspective camera, the rendered light volumes are positioned right where their respective Light objects are and stay in their positions regardless of where the player is (the camera follows the player) and regardless of the FoV.
    upload_2017-3-8_17-2-19.png
    When switching to an Orthographic camera, the light volumes are rendered, it seems, in reference to the position/size of the camera and the volumes move around when the camera does. It's as if they are attached to the camera itself and not rendered at the Light positions.
    upload_2017-3-8_17-13-3.png
    I am rather new to custom Shaders so I am not sure exactly where the position of the rendered volumes is being set or if this is a limitation of the camera? Any help would be appreciated.
     
  31. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    309
    It wasn't really meant to work with orthographic camera. It uses custom projection matrix to simplify frustum/spot light intersection test. See VolumetricLightRenderer:272. You can try to replace it with orthographic projection. Or just use current camera projection matrix.
    I don't know what orthographic camera will do with the intersection tests or if this is the only problem but I guess it is worth a try.

    Or just use sprites for the spot lights. It seems to me it would look just as good in a 2d game and it would be a lot faster to render.
     
  32. monkzoren

    monkzoren

    Joined:
    Nov 5, 2014
    Posts:
    101
    @Michal_ Hello good Sir! I really like your job on the volumetric lights!
    We currently have some issues with PS4 and "BilateralBlur.shader" It looks like you are using "UNITY_DECLARE_TEX2D" witch is defined in the Included "HLSLSupport.cginc" and its declared differently on DX11 and XboxOne, while it looks like Playstation uses the DX9 method. DX11(#define UNITY_DECLARE_TEX2D(tex) Texture2D tex; SamplerState sampler##tex) vs DX11(#define UNITY_DECLARE_TEX2D(tex) sampler2D tex).

    So my question to you, is do you have any ideas for a fix or a workaround?
     
  33. KingoftheWest

    KingoftheWest

    Joined:
    Mar 10, 2017
    Posts:
    1
    Hello, gotta say, the package seems pretty damn cool. However, I'm running into a strange problem. For whatever reason whenever I apply the renderer script to my main camera, suddenly all my visuals are strangely flipped/mirrored. Do you have any idea what might be causing this? Upsidedown.PNG
     
  34. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    309
    Hello. I'm not sure I understand your problem. Are you saying PS4 is using old DX9 HLSL syntax? And it doesn't compile? This is the last version of volumetric lights that still uses old hlsl syntax. You can try it to see if it makes any difference.

    Damn it. I fixed that. Why is it back? Anyway, disable MSAA or (preferably) use deferred rendering path.
     
  35. monkzoren

    monkzoren

    Joined:
    Nov 5, 2014
    Posts:
    101
    Thanks for the quick reply, Some aspects of the PS4 Shader code(PSSL) is handled different than D3D11 and Xbox One, one of the reasons may be that you cant have stuff named "Sample"
    ("Do not use "sample" as a variable name in shaders. This is a reserved word that will cause shaders to fail to compile.") - From the unity PS4 "Start here guide"
     
  36. Dreamcube017

    Dreamcube017

    Joined:
    Dec 20, 2009
    Posts:
    188
    Firstly this looks wonderful.

    One thing I'm trying to figure out though is how to get the script into a different project. I know that sounds silly but I'm pretty new to GitHub. I can download the project that the scripts reside in, but surly I can't just pull them out and put them in another project. What would the proper way to go about adding the effects from your project. Thanks!
     
  37. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    309
    1. GitHub repo contains complete Unity project with settings and everything. You can't integrate it into another Unity project.
    2. I didn't really think this through and it isn't structured very well. There is no encapsulating folder that would make it easier to work with.
    Just take the files and copy them into your project (anywhere you want). It will be a pain to update it but it doesn't change much anymore. I sometimes use symlinks in cases like this but they're not very user friendly either.
     
  38. Dreamcube017

    Dreamcube017

    Joined:
    Dec 20, 2009
    Posts:
    188
    Hm that seems doable. I'll back up my current project and just copy the entire assets folder over. Well everything I think pretains to it. (Stuff in StandardAssets I'll assume don't really... eh, maybe I'll copy that too.

    I'm more of an artist/level designer here so I'll just merge everything on a backup and hope it works.

    I took a look at the fog from the Adam demo and wouldn't ya know it, it's set up the same way. (GitHub with a Unity project. And the part that makes it funny is that the fog scene is the ONLY project that's set like that and not a package in the asset store. Eh, I'll try both. xD

    Thanks again! :)
     
  39. Torigas

    Torigas

    Joined:
    Jan 1, 2014
    Posts:
    61
    Hi Michal,
    For some reason sometimes the volumetric effect seems to be turning itself off when i look away from the light source ( or rather in the direction the directional light is shining to), using various Unity Versions (5.5.2 and 5.5.0) in VR with the Vive. Is that something that anyone has seen before?
    If not i'll try to build a minimal example to upload later.
    Thanks!
     
  40. abramelingames

    abramelingames

    Joined:
    Jul 15, 2015
    Posts:
    18
    Michal do you plan upgrade the volumetric lights to 5.6? in unity 5.5 works very good.
    This is a test in 5.5 Including your awesome effect, not present in all lights, is quite subtle, in the windows it is better appreciated.



    If you could do a version for 5.6 would be very grateful
     
  41. WilliamBerne

    WilliamBerne

    Joined:
    Jul 17, 2012
    Posts:
    1
    Hi Michal, first thank you for your effort!

    I am currently working on a webGL project, but unfortunately, it seems that your work is incompatible with webGL platform:
    To test this, I used only your demo project, switched to webGL platform, then ran it, kept getting error messages like this every frame:
    error.jpg

    And the camera went completely dark cause the rendering was not working.

    I have searched but haven't found anyone reported similar issue.

    If it helps, my system is Win10, CPU: i5 7500, Graphic card: HD 630(integrated in CPU), Unity: 5.5.2f1.
     
  42. Dreamcube017

    Dreamcube017

    Joined:
    Dec 20, 2009
    Posts:
    188
    Well I guess that answers my question. I am using 5.6.6b to test out TimeLine and was going to try to implement it. Thank you for the research @WilliamBerne
     
  43. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    309
    Shadows stop rendering when there is no visible shadow caster. That kills the effect. There's a workaround somewhere above. Or try to experiment with shadow distance. Also, VR is not officially supported and it doesn't work according to many people.

    I'll take a look when 5.6 is out of beta (and I have time).

    Unfortunately WebGL is not supported. WebGL is even more restricted than mobile devices. I'll state it explicitly in readme.
     
    Alverik likes this.
  44. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    495
  45. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    309
    They're similar but different. Both simulate interaction between light and particles in the air.

    Atmospheric Scattering is physically based simulation of Earth's atmosphere. It calculates sky color and aerial perspective for entire atmosphere.

    Volumetric Lights effect works only in light's volume (sphere for point light etc.). Only large particles like fog, smog, dust are considered. It is meant for local light sources to lit fog or dust. You can use it with directional light to get aerial perspective effect but fog color won't be affected by sun position and you have to render your own sky.
     
    Alverik likes this.
  46. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    174
    Although it's kinda late, but did you make sure your lights have no bounce intensity? I've found Bounce intensity to cause a lot of light leaking at times (100% true if the light is a realtime light + not a directional light.) If you haven't fixed the problem it might be worth it to play with the Bounce intensity.