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

[RELEASED] Hx Volumetric Lighting

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

  1. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,646
    ?!
     
  2. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Sorry, I'm currently on holidays so my responses wont be as fast as normal.

    No i don't have a trial version. If you buy the asset and it doesn't function for your needs, just send me the invoice number and ill submit a refund.
     
  3. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,646
    Thanks for the reply.
     
  4. Wikzo-DK

    Wikzo-DK

    Joined:
    Sep 6, 2012
    Posts:
    78
    Is the update out yet? :)
     
    Crossway likes this.
  5. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Sorry there was some compiler warning I missed with certain compiler flags set, Should be live in a day or two.
    holiday/Hurricane Mathew threw off my plans a bit, I leave for steam dev days tomorrow, but ill be back to work after its done.

    If you need the update now, send me a message with your invoice and i can send you the build.

    VR is the focus of the next update hopefully have something around the 20-25th.

    Thanks for bearing with me through these busy time.
     
    punk likes this.
  6. TeohRIK

    TeohRIK

    Joined:
    Jan 22, 2014
    Posts:
    89
    well, it doesn't work...the roof is static object and it look like the light pass through the static roof
     
  7. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    The effect only works with dynamic lighting, Baked lighting unfortunately isn't in a format that can be applied to a volumetric pass. You can create another roof and set it to cast shadows only and remove the static flag. That way it will be rendered into the dynamic shadow maps.

    Or if the roof doesn't need to be baked, just remove the static flag
     
    Last edited: Oct 11, 2016
  8. TeohRIK

    TeohRIK

    Joined:
    Jan 22, 2014
    Posts:
    89
    Ok thanks. Guess I will still using baked direction light with combination of real time spotlight to create the effect. Its too hard to duplicate my environment and set everything to cast shadow only
     
  9. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    bug report for 1.04, the density particle is not working in the example scene in a fresh import 5.4.1
     
  10. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    The density particle checkbox is disabled on the camera. they still work. I'm going to create some better test scenes and stuff shortly.

    The plug-in now tracks every shader variant you use for the volumetric lighting, So having the density particles enabled would cause it to compile that variant into everyones build even though they don't use it.

    Probably should have just removed the scene for now.
     
  11. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    The warning

    "
    Shader warning in 'Hidden/HxVolumetricSpotLight': 'SHADOWS_NATIVE' : macro redefinition at HLSLSupport.cginc(322) (on d3d11)

    Compiling Vertex program with SHADOWS_NATIVE
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING
    "
    and

    "
    Shader warning in 'Hidden/HxVolumetricDirectionalLight': 'SHADOWS_NATIVE' : macro redefinition at HLSLSupport.cginc(322) (on d3d11)

    Compiling Vertex program with SHADOWS_NATIVE
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING
    "
    show up in 5.4.2, should I worry about it?
     
  12. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    everything will still work, now that 5.4.2 is live ill fix any conflict they've added. always a fun time with unity.
     
  13. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    There is a bug with transparency support, I'm fixing it now.

    Edit: Transparency bug is fixed as well as the issues with 5.4.2
    Its been submitted to the asset store. If anyone needs it early just send me a message with invoice number.
     
    Last edited: Oct 16, 2016
    yc960 and punk like this.
  14. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    Feature request: Add a magnitude option to noises, right now it is barely noticable no matter the setting even in example scene
     
  15. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Yeah i have some looping cellular automata data that we baked out for our procedural game, Ill port that over into a 3D texture to use for the noise, Right now its a pretty bad noise data so its not really worth using.

    Ill make it nicer and give it some more settings in the next update. Should give the illusion of clouds rather then speckled noise.
     
    wetcircuit and punk like this.
  16. Beinscheibe

    Beinscheibe

    Joined:
    Sep 24, 2013
    Posts:
    78
    Just a question:
    We are using PRISM as default image effect stack and I noticed that the Ambient Occlusion is applied on top of the volumetric lights. Also changing the order of the components does not help.
    Do you know a way to get rid of this?
     
  17. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    My guess would be it applies the image effect after transparency gets rendered, Normally you wouldn't want to do that but I guess that's the downside of applying all the image effects in one pass like that shader does.

    If you don't need transparency support you could remove a line of code from hxVolumetricCamera
    [ImageEffectOpaque]
    its on line 1839 I think. this will make it render after transparent objects and then the image effect stack can be ordered with the volumetric effect getting applied after prism.
    EDIT: actually don't do this. Do the bottom option

    Honestly the best and correct way to do it would be to use a different SSAA that applies after opaque objects have rendered and before transparent objects have render. Some screen space effects need to be rendered before transparent objects, and some need to be rendered after. Prism renders all of its effects at once for a slight speed increase, This is great and all but means it will conflict with image effects that need to render after opaque objects

    Edit: This is the solution
    You might be able to duplicate the Prism script and have one version that renders after opaque using [ImageEffectOpaque] and one that renders after transparent. That would be best actually. You'd then only render SSAA and maybe one or two more in the [ImageEffectOpaque] version, Then render the volumetric lighting, and finally render the prism with bloom, tonemapping, etc.
    But im not sure of exactly how prism works, so it might not be as simple as it sounds.
     
    Last edited: Oct 20, 2016
    hopeful likes this.
  18. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    There is a bug with OpenGL 4.1, I've submitted a new build to the asset store. If you need a copy sooner, just send me your invoice number and ill send you a download link.
     
  19. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,729
  20. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Just tested, Works fine with it, Unity's system is pretty good, the SSAA renders before the volumetric effect, And the tonemapping, bloom etc render after it (which is what is meant to happen, unlike prism).

    Edit: The really cool thing is it gets affected by the TSAA, So you can get away with less samples in the volumetric pass! Looking into getting the camera matrix from the TSAA pass out to make it more stable with the effect and animated the ray offset. Should basically give the ability to make the sample count 2x-4x as effective!

    Edit 2: To make the effect stable enough it removes the Antialising effect though. but it gives you about a 4x sample count effect. Its pretty cheap as well, I think ill break off the code and make a version that's design for just the volumetric effect.
     
    Last edited: Oct 21, 2016
  21. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,729
    Oh that's just fab news :D
     
    punk likes this.
  22. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646


    Ok top is with temporal sampling, Bottom is with it off.
    I've disabled the blur pass so you can see how much more detail it picks up. The blur pass would clean up the splotches. this would probably allow you to drop down the blur count to 1 in most cases. (blur passes on full and half res are expensive, So this is good news!)

    Both of these images are done with the same sample count!
    You will be able to drop down the sample count by 2x - 3x and still get the same quality as before. But will look even better when in motion (lowers flickering on small light shafts)

    Also the effect is pretty cheap to calculate.

    Im setting up a Vive tonight to get VR support all done, But ill come back to temporal sampling once I finish with that.
     
    Last edited: Oct 21, 2016
  23. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    387
    Fantastic!
     
  24. Beinscheibe

    Beinscheibe

    Joined:
    Sep 24, 2013
    Posts:
    78
    Thanks for the info Lexie ;D
    We just switched to a different AO solution and just use prism for the rest. For now that works great. Also we use Unity's AntiAliasing solution too (currently the one in the whole stack, will see about that). Works great too.
     
  25. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Ok, I got the first step of VR setup.

    By first step I mean that you have to have two cameras, one bound to left eye, one bound to right eye.
    Then have the volumetric script on both of them.

    This is not ideal because it causes unity to render all the shadow maps twice. (once for each eye)

    It's going to be a lot harder to get this to work with one camera target set to render to both eyes.
    This is because of the way VR and command buffers interact in unity. I think I know a work around, but I don't know if its possible or not. The biggest issue is reusing the shadow maps from the left eye and rendering them to the right eye.

    I can get the Directional light to render for sure as well as none shadow casting point and spot lights. Just a little worries about shadow casting point and spot lights.

    Just thought I'd give everyone a status update.

    It looks really cool though!
     
    punk and rrahim like this.
  26. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Beta VR Support so far. I will edit this post through out the day as i get more stuff working for VR

    If you render two separate cameras (one with left eye, one with right eye) everything is supported. (not ideal as it renders two shadow maps for every light)

    If you render one camera with eye target set to both with out Single pass stereo.
    Directional - Fully supported
    Point/spot - Doesn't render shadows, no way i can get it to work with out unity extending their API, moving onto stereo render now

    If you render one camera with eye target set to both with Single pass stereo.
    Directional - Fully supported
    Point - Fully supported
    Spot - Fully supported
    Blur pass - Fully supported
    Density particles - Fully supported
    transparency - working on it


    Once I get it as far as I can for today ill push a build.

    Edit: Ok i had my settings wrong, and that's why i couldn't get single pass stereo rendering working with the vive. I definitely cant get it to work with one camera with out single pass because of the way unity's command buffer and shadows work. I'll start converting everything to work with single pass now.

    Edit2: Ok single pass stereo rendering and command buffers are pretty glitchy, a lot of things simply don't work. I'm having to write some custom stuff to get it to work, Might take some time.

    Edit3: Ok i understand the math now, going through and converting the shaders now, Got directional light working.

    Edit4: Got point lights working and spot lights nearly done, I had to chop up a lot of the code to get this working, I wont have a beta build ready tonight, Sorry.



    Right now the blur pass isnt functioning because there is a bug in unity with blit + command buffers + custom shaders + single pass stereo. But I have a work around, Just need to convert all the shaders.
     
    Last edited: Oct 24, 2016
    Ostwind, yc960 and punk like this.
  27. mbbmbbmm

    mbbmbbmm

    Joined:
    Dec 28, 2013
    Posts:
    58
    I hope VR support works out well, because I just purchased the asset and it looks amazing! I can just imagine how cool it will look in VR :)
     
  28. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    387
    Sounds like you are making some awesome progress :D
     
  29. lionroot

    lionroot

    Joined:
    May 1, 2014
    Posts:
    8
    Is this possible to be used in orthographic scenes?

    Thanks!
     
  30. paulojsam

    paulojsam

    Joined:
    Jul 2, 2012
    Posts:
    486
    for curiosity sake, does the unity package provides a trigger to change the hx volumetric camera values in real time, to have diferent areas with diferent settings
     
  31. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    No.

    You can use density particles to make areas more misty then others, but they can be expensive to render on low end cards.
     
  32. paulojsam

    paulojsam

    Joined:
    Jul 2, 2012
    Posts:
    486
    that was my fear ...
     
  33. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Alright, VR support is pretty close to done, Going to see what version of unity is the lowest it can support. Also need to clean up some stuff that got a little broken for non VR rendering. But all in all it worked out pretty well.

    Going to mess with a weighted sample count so the center of the camera has more samples then the outer edges, this should speed up VR render a bit and shouldn't be noticeable at all.

    Should have everything ready by tomorrow afternoon to push to the asset store.
     
    punk likes this.
  34. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    387
    Great news can't wait to try it
     
  35. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    If you render at quarter resolution and the density particles at eighth resolution and have a low sample count with only a couple of shadow casting volumetric lights, its not too expensive.
     
  36. Lesovoy

    Lesovoy

    Joined:
    Mar 18, 2016
    Posts:
    7
    Hi! Thanks for asset! That’s really great! i bought this awesome asset yesterday for my personal project and find an issue about how it works with unity terrain billboards. Maybe somebody can help me to make unity billboards work with zdepth? Shader programming is not my best thing =(( ((the screens are overexposed for clearing the trouble)






    Code (CSharp):
    1. Shader "Hidden/TerrainEngine/BillboardTree" {
    2.     Properties {
    3.         _MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}
    4.     }
    5.    
    6.     SubShader {
    7.         Tags { "Queue" = "Transparent-100" "IgnoreProjector"="True" "RenderType"="TreeBillboard" }
    8.         Pass {
    9.             ColorMask rgb
    10.             Blend SrcAlpha OneMinusSrcAlpha
    11.             ZWrite Off Cull Off
    12.            
    13.             CGPROGRAM
    14.             #pragma vertex vert
    15.             #pragma fragment frag
    16.             #pragma multi_compile_fog
    17.             #include "UnityCG.cginc"
    18.             #include "TerrainEngine.cginc"
    19.             #include "../Includes/AfsBillboardShadow.cginc"
    20.  
    21.             struct v2f {
    22.                 float4 pos : SV_POSITION;
    23.                 fixed3 color : COLOR0;
    24.                 float2 uv : TEXCOORD0;
    25.                 UNITY_FOG_COORDS(1)
    26.             };
    27.  
    28.             // AFS Billboard Shadow Color
    29.             fixed4 _AfsAmbientBillboardLight;
    30.             // AFS Tree Color
    31.             fixed4 _AfsTreeColor;
    32.  
    33.  
    34.            
    35.             v2f vert (appdata_tree_billboard v) {
    36.                 v2f o;
    37.                 //TerrainBillboardTree(v.vertex, v.texcoord1.xy, v.texcoord.y);
    38.                 AfsTerrainBillboardTree(v.vertex, v.texcoord1.xy, v.texcoord.y);
    39.                 o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    40.                 o.uv.x = v.texcoord.x;
    41.                 o.uv.y = v.texcoord.y > 0;
    42.  
    43.                 float factor = v.color.g;
    44.                
    45.                 o.color.rgb = lerp(_AfsTreeColor.rgb, 1.0, factor);
    46.                 o.color.rgb *= lerp( ( _AfsAmbientBillboardLight.rgb ), fixed3(1,1,1), v.color.a );
    47.  
    48.                 UNITY_TRANSFER_FOG(o,o.pos);
    49.                 return o;
    50.             }
    51.  
    52.             sampler2D _MainTex;
    53.  
    54.            
    55.             // speedtree
    56.             uniform float _CameraXZAngle; // no, we do not get this....
    57.  
    58.  
    59.             fixed4 frag(v2f input) : SV_Target
    60.             {
    61.                 fixed4 col = tex2D( _MainTex, input.uv);
    62.                 //col.rgb = pow(col.rgb, 2.2) * input.color.rgb; // not needed since unity beta 20
    63.                 col.rgb = col.rgb * input.color.rgb;
    64. // shaded billboards
    65.             //    col.rgb *= lerp( ( _AfsAmbientBillboardLight.rgb ), fixed3(1,1,1), input.color.a );
    66.  
    67.                 clip(col.a);
    68.                 UNITY_APPLY_FOG(input.fogCoord, col);
    69.                 return col;
    70.             }
    71.             ENDCG          
    72.         }
    73.  
    74.     }
    75.     Fallback Off
    76. }
    77.  
     
  37. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
  38. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    If its a small body of water and you don't have extreme settings, it looks fine.

    Water can be hard to get working with volumetric lighting because the depth buffer is used to render all the volumetric stuff before the water has even rendered.

    My system can support transparent objects but Its not really designed for large bodies of water. What would need to be added is a pass that renders bodies of water to the volumetric depth buffer buffer or to a second caustics depth buffer. This is pretty easy to add but custom shaders to write the waters depth would needed to be added for every water plugin out there...

    I might add the back end for this for people to use and leave it up to the ocean developers to have a depth only shader for there ocean/water.
     
  39. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646

    So unity's billboards are actually alpha, Rather then opaque, If you enable transparency support on the volumetric camera it should switch over to using my custom billboard shader i wrote with transparency support. You have to make sure you dont have any other shader with the shader path "Hidden/TerrainEngine/BillboardTree"

    But the transparency support is more expensive to render.
    If you want opaque billboards id suggest using speed trees rather then unity's old tree method that hasn't changed since unity 2.0 I think. They really wanted people to switch over to speed tree.

    If you want to convert that shader though. change the line that reads
    "Queue" = "Transparent-100"
    to
    "Queue" = "Opaque"

    and the line that reads
    ZWrite Off Cull Off
    to
    ZWrite On Cull Off

    its not going to be completely accurate though because it uses alpha.

    You could make the alpha clip a little stronger to help it look better
    Change
    clip(col.a);
    to
    clip(col.a - 0.5f);

    this would make the alpha discard earlier, maybe even higher then 0.5f
     
    Last edited: Oct 25, 2016
  40. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Version 1.1

    VR support has been added. (Unity 5.4.1+)
    There are two methods to get it to work.
    Single camera with eye target set to both and single pass stereo rendering enabled (Recommended!)
    Two cameras, each set to render either the left/right eye and a hxVolumetricCamera script on each (Not recommended)

    Blue Noise I've also switched the raymarch offset to use Blue noise instead of the custom pattern. This ends up doing a better job and the patterns created are easier to hide with the blur passes.

    I've submitted this to the asset store, Just awaiting approval.

    I'm going to start working on some form of temporal sampling method to improve the volumetric effect at low sample count. It will either have its own built in temporal sampling that only effects the volumetric pass, Or set up the data in a way that it will play nice with Temporal anti aliasing image effects (like the one unity is working on)

    I also really need to focus on marketing stuff like example scenes and stuff.

    Ill also work on some presets so people that don't want to dig around in the settings wont have to mess with all the different settings to get what they want
     
    Last edited: Oct 25, 2016
  41. Lesovoy

    Lesovoy

    Joined:
    Mar 18, 2016
    Posts:
    7

    OMG! That is useful information! It works great with your custom billboard shader! Thanks! Actually it is a small challenge for kind of beginners to realize that unity terrain is not best idea to use as a full solution (( I bought some nice tree packages and thought it would be great idea to use unity terrain mechanics… Now I know the better true way -) Thank you for your time and great product!
     
  42. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    There was a bug that cased the tracked shaders to not get serialized some times.
    This would lead to lights not showing up when you built the game out. I've submitted an update to the asset store.

    I have another big update coming soon that will increase the speed and performance a lot.

    It will add temporal sampling and use a different blur function that leverages the use of temporal sampling. Over all you should be able to cut you sample count in half and blur down to 1. Should be a big improvement to speed and quality.

    I might be able to get zones added in to this build as well. Will see how well it goes.
     
    laurentlavigne and punk like this.
  43. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Should be able to push this tomorrow, The results are amazing.

    Below is sample count set to 4 and 1 blur pass at half resolution. Temporal sampling on vs off.

    To get the old system to look this good, id have to increase the sample count to about 22.
    To render close to 1080p at 22 samples the render loop took around 7ms for the whole scene.
    with 4 samples and temporal sampling it only took 4.3ms.



    upload_2016-10-27_17-17-51.png
     
  44. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    cool, does it work with unity standard TAA or a modified version of TAA?
     
  45. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    In the end I went with a custom method that just focuses on improving the volumetric samples.

    But you can still use unity's TAA or other TAA to get AA and it will slightly improve the volumetric pass as well.
     
  46. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    cool, BTW the 1.1 version seems to have weired banding in gamma color space in fresh project 5.5b9. I use linear, so it does not bother me.
     
  47. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    420
    Hi, there is a problem. you only increased extinction range on the HxVolumetricCamera script not HxVolumetricLight script! can you please fix this on the next version? Thanks.
     
  48. Johnny_Jr

    Johnny_Jr

    Joined:
    Jan 23, 2015
    Posts:
    9
    After upgrading to v1.1 the volumetric light is applied upside down for regular cameras and in VR it seems it might be flipped horizontally (if I disable single pass stereo rendering it is applied correctly in VR, but with artifacts)
     
  49. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    After sending 1.1 to a few people it had a few too many bugs so I've pulled it from that version from the asset store.
    I've just about got all the bugs fixed as well as temporal sampling working.

    VR was a little harder to get right then I first thought, The lighting data was slightly off in the beta of 1.1. I have improved it so it calculates the lighting exactly right for each eyes view matrix.

    Hopefully have something shortly.
     
    yc960 likes this.
  50. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    277
    Deleted User likes this.
unityunity