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

[RELEASED] Hx Volumetric Lighting

Discussion in 'Assets and Asset Store' started by Lexie, Aug 1, 2016.

  1. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Its pretty hard to pin down a ms cost for the effect. It depends largely on number of lights and settings. It not like other image effects that have a set cost.
     
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I see, but is it constant if the lights and settings are constant, or will it change based on view and so forth?
     
  3. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    The cost of the effect will changed based on how many screen pixels a lights volume takes up. A distant light is a lot cheaper because it only needs to render the effect for a small amount of the screen. A full screen light costs more (directional or when your inside a point or spot light)

    The screen depth is downscaled and then all the volumetric rendering is done at a lower resolution.
    When the effect is upscaled the cost of this can change based on how complex your scene is. It's easier to reconstruct a simple scene vs a complex one.

    Those are the two things that will change how much the effect costs, even if the settings are the same.

    Using my 970m(laptop gpu around the same speed as a GTX 660 or a GTX 750)
    In a simple scene on the lowest settings the downsampling + 1 blur pass + upsampling cost 0.6ms.
    A Shadow casting directional light cost 0.4ms
    A Shadow casting Fullscreen point light cost 0.18ms

    If the point light was further away from the camera it would cost less. If they didnt cast shadows they would cost less
    If the scene was really complex the downsampling + 1 blur pass + upsampling might cost 0.8ms

    If you want more blur passes it cost more.

    If you use lower resolution shadow maps it also speeds up these numbers (tested on highest shadow res)
    Edit: for example the directional light only costs (edit) 0.27ms on low res vs 0.4ms on high res

    On my GTX 1070 it doesn't bat an eye at this effect on low settings.

    In the next update ill have some presets for settings so people can get more out of the system with out needing to know how it all works.

    edit: TLDR hard to pin down the cost of this effect.
     
    Last edited: Aug 14, 2016
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    It does seem quite reasonable. Thanks for explaining!
     
    HakJak likes this.
  5. sarum

    sarum

    Joined:
    Mar 2, 2014
    Posts:
    212
    hey,

    does it play well with particles ?
    any chances we could get a web demo or a trial ?

    thanks :)
     
  6. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    If you want Alpha particles to composite correctly with the effect you can enable Transparency support and use my replacement particle shaders. Ill have some web demos shortly.
     
  7. sarum

    sarum

    Joined:
    Mar 2, 2014
    Posts:
    212
    thanks
     
  8. DrewMedina

    DrewMedina

    Joined:
    Apr 1, 2013
    Posts:
    418
    +1 for VR support (AA and single pass stereo). Looks great :)
     
  9. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    507
    How can I reduce light density on far distance and increase it for close distance?
    Thanks.
     
  10. pixelsplit

    pixelsplit

    Joined:
    Sep 16, 2013
    Posts:
    173
    Hi,

    we are getting the following error at build time when using the asset:
    Code (CSharp):
    1. Shader error in 'Hidden/HxVolumetricPointLight': '' : 'SHADOWS_NATIVE' already defined at line 12 (on opengl)
    2.  
    3. Compiling Vertex program
    4. Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING SHADER_API_DESKTOP
    5.  
    6.  
    7. Shader error in 'Hidden/HxVolumetricPointLight': '' : 'SHADOWS_NATIVE' already defined at line 12 (on metal)
    8.  
    9. Compiling Vertex program
    10. Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING SHADER_API_DESKTOP
    Is there anything we can do about it?

    Best regards
    zkw
     
  11. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Perhaps it doesn't support Metal / ES3 yet?

     
    Lexie and pixelsplit like this.
  12. pixelsplit

    pixelsplit

    Joined:
    Sep 16, 2013
    Posts:
    173
    Oh well thank you. There were still the flags for OpenGL2 and Metal on the Mac Build. Thanks for the hint!
     
    hippocoder likes this.
  13. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Ill put some better define flags on the shaders in the next build. Unity 5.1 had some strange things that caused me to have to define a bunch of stuff. Ill just do some better checks to make sure i don't define them twice.
     
  14. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    507
    Why image effects on the camera doesn't effect lights? I can't match directional light with my game because my game use contrast image effect but directional light can't get effected by that contrast image effect on my camera.
     
  15. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Change the order of the scripts on your camera, Place the contrast image effect after the volumetric pass. You can change the order of the scripts by clicking on the gear in the top right of the script and select Move Up
     
  16. wladm

    wladm

    Joined:
    Oct 4, 2015
    Posts:
    7
    Hi!

    Loving this asset so much. I was wondering - is there any way to make the fog / volumetric light to render on top of 2d sprites? It displays correctly on meshes, but it seems to ignore 2d sprites completely.
     
  17. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    507
    There is no difference if I put HX volumetric camera script on the top of all image effects or at the bottom, it doesn't effected by any image effect.
     
  18. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    What shader are you using to render the sprite? Sprites normally use some form of transparency so the shaders will need to be edited and transparency support would need to be turned on. If you tell me the shaders I can add them to the next build.

    The other option is to apply the volumetric effect after transparency has been rendered. you can do this by removing the [ImageEffectOpaque] tag from HxVolumetricCamera.cs. But this would be a hack.

    The volumetric pass is applied as an opaque image effect. You can edit HxVolumetricCamera.cs and remove [ImageEffectOpaque] tag from that script and it might work better with your image effect stack. But this will mean you cant use transparency support.

    It should work fine with most image effects with out needing to modify this though, Your not doing any strange image grabs or anything? What image effects are you using that don't work?
     
    Crossway likes this.
  19. wladm

    wladm

    Joined:
    Oct 4, 2015
    Posts:
    7
    I'm actually using skinned mesh renderer with the standard fade shader.

    Removing [ImageEffectOpaque] kind of works, but the scene looks a bit off now - hmmm...

    Thanks :)
     
  20. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    507
    Lexie
    After removing [ImageEffectOpaque] it looks correct and cool now! thanks it's awesome. (before removing none of image effects worked at all)
    But also you said I can't use transparency support after that! isn't really any other way for transparency to work? like sunshine?
     
  21. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    The effect should work with image effects with out having to remove that tag, either there is something strange with the image effects your using like they are doing a grab pass early. If you link me the image effect I can test it and see whats happening

    Every image effect I've tested works so there has to be something strange with your setup.

    If your using the standard fade shader, Then revert that change I said. And enable transparency support. Switch the shader to the standard shader I included. You might have to switch it to opaque and then back to fade.
     
  22. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    507
    Weird, I'm using (Scion,contrast,tonemaping,vibrance) there will no difference (not even a bit!) if I put Hx camera script on the top of those images effect or at the bottom. but after removing [ImageEffectOpaque] it reacts to image effects as expected. for example if I put it upper than "contrast" it looks better but without removing [ImageEffectOpaque] it doesn't matter where I place it. it'll looks all the same.
     
  23. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    So the volumetric effect gets applied after all the opaque rendering is done. Those image effects you're using get applied after all the transparent images get rendered. So yes the order wouldn't change anything, but no those image effects where effecting the volumetric lighting. For those effects to be physically correct, you want them to apply after the volumetric rendering has been applied (so like it was before)

    I've tested with all the image effects you've used and they all work as intended.

    generally you want AO to apply first, then volumetric lighting, then any tone mapping/color correcting
     
    Crossway likes this.
  24. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    507
    Thanks for help, but anyway for me it look a lot better with "[ImageEffectOpaque]" removed.

    40$ for such an asset like this is cool (a lot better than Sunshine that cost 125$ :D )
     
  25. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    507
    Please look at below pic. I increase the light to show you objects near the camera doesn't get effected by lights. as I figure out there is no parameter to setup this start light from.

    I don't like this gradient. I need uniform light density on close and far distance.
     
    Last edited: Aug 22, 2016
  26. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    This is physical correct though... distant object should look different then close objects with volumetric lighting because the light has more chance of scattering through the air on far objects.

    If you increase the extinction it will help it look more "uniformed". What extintion does it fade out the volumetric effect based of distance and air density. So increase that and maybe increase the density a bit.
     
  27. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    507
    Ok but too close distance and objects doesn't receive any light at all, not even a bit. When I was using Sunshine there was an option to change light distance that I could set it on "0".

    The problem is my character looks good from a little far distance but when I get too close to face there will be no volumetric light on the face and it looks darker.
     
  28. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    The distance the volumetric lighting starts getting calculated at is the near plane of the camera. It cant be any less then that because there isn't shadow data behind that plane for the directional light, If you lower the near plane on the camera it will start calculating the volumetric lighting sooner.

    Also if the object is really close to the camera there really wont be much visible volumetric rays between your eyes and the object. Unless your density is 1+ and its a really bright light. Thats just how light works.
     
    Last edited: Aug 22, 2016
  29. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    507
    Then why this gun (first gun) doesn't effected by light at all while the whole scene is white because of light density?
    I don't know how should I tell you that. but I'm pretty sure objects near camera (near as closer gun to camera) doesn't get any effects of lights. (While the whole scene looks with because of lights!)



    I need light effects on this closer gun too. isn't there anyway for this? cause I can't use this asset anymore only because of this issue.
     
    Last edited: Aug 25, 2016
  30. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    it is getting effected, its just a small amount. I can see a yellow tint to it. if you increase the density to 1 I'm sure you will see it getting effected even more.
     
  31. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    507
    I can't have such a high density. I just ask if this is possible you add something for more uniform light.

    My near far clipping is 0.3. I mentioned if I set it to 0.01 it will effects close objects too but can't decrease far clipping lower that 0.3 because of unity shadow flickering.
     
  32. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    If you increase the extinction you can increase the density a little more with out it over fogging your scene.
    The volumetric lighting calculations are all based on physically correct lighting models, where as sunshine isn't so its going to be hard to reproduce the same results as it.

    If you want to get similar results to sunshine set the mie scattering to 0. (scatter light evenly in all directions)
     
  33. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Also if you do the tone mapping after the volumetric lighting is applied it will help a lot.
     
  34. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    507
    So maybe if that extinction was higher like 5 times larger that would help. 0.5 isn't enough for me.

    Also I think your camera near far clipping is set to 0.01 and it looks correct for you. but I can't use near far clipping less than 0.3 because of shadow flickering. so because of that near objects doesn't get effect for me.
     
    Last edited: Aug 22, 2016
  35. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Im testing with 0.3 and I can see volumetric lighting up until the object clips through the camera. The biggest issue is your doing the tone mapping (scion) before the volumetric light is getting applied. If you really don't want to change the order. try ticking the checkbox to map the volumetric effect to LDR (Advance Settings->map to LDR) assuming your rendering in HDR
     
  36. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    507
    I changed extinction value from 0.5 to 4 from scripts and looks it solved my problem. thanks a lot for efforts to help.

    Can you please change extinction value to 4 in the next version?
     
    Last edited: Sep 29, 2016
  37. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Ill increase the range people can set on extinction in the next build.
     
    Crossway likes this.
  38. greengremline

    greengremline

    Joined:
    Sep 16, 2015
    Posts:
    183
    This looks pretty sweet! I am curious if I can get this to work for me.

    I'm creating a game where I generate a maze of rooms at runtime. These rooms are stored as prefabs then pulled into the scene and rotated anywhere from 0 to 270 degrees, so baking lights doesn't seem to work very well. Would this work for my use case? It's a base / facility so a lot of ceiling lights, some monitors, that kind of thing. Not a lot of open spaces.

    I'm using deferred rendering with linear colorspace, if it matters.
     
  39. Sin_Phi

    Sin_Phi

    Joined:
    Jul 16, 2016
    Posts:
    1
    UnitedStrength I am using a procedural generated environment with player placed lighting and a moving main light with deferred rendering. This asset gave me probably a 25% frame rate increase as well as looking amazing. Especially the lights like your monitors will look great with some volumetric effects. So it should be better than the default.
     
    hopeful likes this.
  40. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    408
    Hey @Lexie is there a way I could tell in code whether a point in the volume is in shadow?
     
    hopeful likes this.
  41. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    It will work with all the dynamic lights in your scene. (sounds like its all of them)

    Ah... this asset wont speed up your rendering. Unless you were using a different volumetric effect and your switching it out for mine. I have an asset to speed up shadow rending in the works. But not sure if/when that will come out.

    Your computer might have been using your integrated GPU and this effect caused your computer to switch over to your dedicated GPU.

    Do you mean on the CPU? Then no, the data for all the shadows is stored on the GPU, It's possible to capture the data and send it back to the CPU but it would be pretty slow and would require a lot of custom code.
     
  42. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    408
    Yeah no prob's I had a feeling that may be the case
     
  43. jeyb

    jeyb

    Joined:
    Oct 3, 2014
    Posts:
    2
  44. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    Does it matter the script order of the effect on the camera? (before/after other effects, tonemapping, etc)
     
  45. wetcircuit

    wetcircuit

    Joined:
    Jul 17, 2012
    Posts:
    1,409
    yes. I put it before imagefx like bloom and tonemapping.
    It works the other way too, if for some reason you want the light volumes to sit "on top" of the image.
     
  46. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Same, at the moment the effect is not really working in VR as I can see (I might be wrong, I was already using a suitable volumetric effect so didnt give it too much time).. it's visible and without artifact, mind
     
  47. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    It currently gets applied as an opaque image effect, So generally it will get called before tonemapping regardless of order.
    Just make sure you render AO and most other opaque image effects first.

    There is currently a texture getting leaked in some versions of 5.4, Looking into it today for a work around.

    I've optimized a lot of the code, It should shave off around 20 - 25% of the setup and finalize step.
    Should have a build ready today/tomorrow.

    Still working on getting Single pass stereo support (VR)
     
    Arganth, punk and elbows like this.
  48. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    I've pushed a small change to fix the memory leak in 5.4. Thought it best to get this live as soon as I can.
    If you email me your invoice ID I can send you the new build if you need it right away.

    I think the bug only effected unity 5.4.0.3f.
     
    Drommedhar, Arganth and punk like this.
  49. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    I've managed to shave off 0.1-0.2ms without any change to the image quality, this might translate to more saving on lower end GPU that have issues with bandwidth/fillrate. Ill do a little more testing before I push it live.
     
  50. paxilon

    paxilon

    Joined:
    Aug 9, 2016
    Posts:
    25
    Hey Lexie. I get a crash on large Environment Scenes with quite a lot of geometry. Is there anything I can do?

    EDIT: Just noticed that Unity crashes also with only a PLane and a cube in my scene. It's Unity 5.4.0f3