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] Lux Water

Discussion in 'Assets and Asset Store' started by larsbertram1, Jun 18, 2018.

  1. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    for each plane you use to render the surface you need a matching volume mesh. OceanPlane does not have any...
    so you have to use pPlane1 or pPlane2 – or create a volume based on the OceanPlane.
    if you attach the underwater script to the weapon camera, then the underwater post shader does not "see" the scene as it gets the depth buffer from the weapon cam and not the scene cam.

    so first you would have to grab depth from the 1st camera. see luxwater_cameradepthmode.cs e.g.: this script does it for metal - but you could comment the if (metal) parts. it uses a commandbuffer to grab the depth buffer and uses Cameraevent.AfterLighting. at least in unity 5.6.3 this commandbuffer will be executed after the 2nd (weapon) camera has finished lighting :( using BeforeSkybox however solves the problem as the weapon camera does not render a skybox.
    in case you want caustics and render them using the gbuffer normals you will also have to copy the normal buffer from the first camera.

    then you have to tweak the underwater post shader and make it sample the _Lux_GrabbedDepth texture instead of the _CameraDepthTexture. this shader also uses the built in _ProjectionParams which of course matches those of the weapon camera. you will have to provide _CustomProjectionParams which fit those of the main camera. or make sure that far clipping planes of both cameras just match.

    and this are just the first steps to make it work somehow...
    so actually 2 cameras are not supported out of the box.
     
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    attached you will find an oceanvolume mesh.
    make sure you import it using "Use File size" unchecked in the model import settings so it fits the oceanplane.
     

    Attached Files:

    wwg likes this.
  3. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    Lux Water - split screen support (preview)

     
    Vincent454, sjm-tech and Rowlan like this.
  4. wwg

    wwg

    Joined:
    Apr 2, 2014
    Posts:
    130
    @larsbertram1 - I'm really liking LuxWater! Nice work!

    I have some of your other assets, but didn't know about the water until a few days ago. I'm excited to see it develop even more - especially any large/infinite ocean features.

    I was using Suimono for a while and although it looks good, the performance hit was just too much. I switched to Aquas, which has good performance and looks pretty good, but feels flat and lifeless. LuxWater has better performance than Aquas and looks much better...and the Gerstner waves add a lot of life the my scenes.
     
    Mark_01 likes this.
  5. wwg

    wwg

    Joined:
    Apr 2, 2014
    Posts:
    130
    @larsbertram1 - Question about foam:

    I set the Foam Edge Blend Factor to .05, to create larger bands of foam along the shore. When viewed from low angle (UFPS standard player height), the band looks thin - see image 1. When viewed from a higher angle (or straight above), the band is much thicker - see image 2. The third image is viewed from directly above.

    lux1.png lux2.png lux3.png

    My expectation is that foam width would look about the same from all angles. Any suggestions?

    Thanks!
     
    Last edited: Jan 9, 2019
  6. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    unfortunately this is a common problem with screen spaced foam: it is heavily view dependent.
    so the only solution here is to create a shoreline foam mask and sample this in the shader. this however would not play nicely with dynamic objects...
     
  7. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    606
    Hi does this work with forward rendering?
     
  8. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    yes, it does.
     
  9. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    606
    Great. I have a game that uses alot of 2d sprites and 3d meshes like paper mario. Would I be able to achieve water puddles and reflections with your app?

    Thanks
     

    Attached Files:

  10. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    version 1.07 has been submitted which brings deep water and massively improved orthographic rendering.

    ## Version 1.07

    #### Breaking chances
    - Refraction may look other than before. You will have to check your settings.
    - Far normal settings (Fade and Scale) have changed, so your far normals will most likely be off.
    - Orthographic projection: You have to explicitly enable orthographic support to make it work.
    - Long story short: I entirely rewrote the lighting function which may simply break the rendering of your water materials. But in case you tweak your old settings this version should give you you nicer lit and faster rendered water surfaces ever.

    #### Major Changes

    ### Added
    - Deep water lighting added.
    (https://docs.google.com/document/d/...qm38h-u3Az-ozaaOX0/view#heading=h.xv6ou9wdiuc)
    - More transparent underwater shaders added which support deep water rendering.
    - Split screen support for water volumes added (preview)

    ### Changed
    - Lighting: Refactored, fixed and optimized.
    - Translucent Lighting: Has been totally reworked. You will have to to tweak translucency color and set up "Intensity (Water)" and "Intensity (Foam)".
    - Underwater Scattering params exposed.
    - Far Normal Fade: Reworked. You may have to readjust the settings.
    - Pixel Snapping: Added MSAA_4x (experimental).
    - Water Mask rendering: Optimized and reduced needed passes from 3 to 2 by using vface.

    ### Fixed
    - Underwater Post Shader: Fixed Fog depth attenuation density.
    - Underwater Post Shader: Fixed caustics not attenuated by color absorption.
    - Underwater Post Shader: Fixed absorption of reflections and lights above the water surface.
    - Underwater Post Shader: Synchronized color absorption (was exp in water surface shader and exp2 in underwater).
    - Underwater Post Shader: Synchronized caustics animation.

    #### Features

    ### Fixed
    - Caustics: Fixed influence of fog being different in water surface and underwater post shader.

    ### Changed
    - Caustics: Smoothed normal based blending.

    ### Changed
    - Foam: Further smoothed foam caps.
    - Foam: Edge foam and foam caps now get combined using max (instead of simply adding them).

    ### Added
    - Foam: Added "Scale" to deep (or underwater) foam as well as otherwise it might just vanish if "Scale" is high.
    - Foam: Deep (or underwater) foam uses parallax mapping as well.

    #### Misc

    ### Changed
    - UnderwaterParticles Alpha Blended shader: Enhanced underwater fog and absorption.
    - Cleanup: Hid Lux Water post shaders from shader select menu ("Hidden/...")

    ### Fixed
    - OceanPlane: Added OceanVolume counterpart.
    - WaterPlane_LowTess: Added missing vertex colors.
    - WaterVolume_LowTess: Added missing vertex colors.
    - Metal: VFace issues fixed once more.
     
  11. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    ahh, i have no experience with 2d games, sorry. but lux water was not designed to render puddles but water surfaces and volumes like river, lakes or even oceans.
    regarding reflections: Lux Water supports cubemap based reflections as well as planar reflections. no magic here.
     
  12. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    and except from water volumes - orthographic projection now is 1:1 with perspective: so caustics and depth based attenuation are in.
     
  13. wwg

    wwg

    Joined:
    Apr 2, 2014
    Posts:
    130
    Ok, got it. Thanks!

    A couple other issues:
    1. A white line on the horizon, when the camera is underwater (see image). It flickers on and off as the player moves. This is the ocean plane and volume.
      lux4.png

    2. When moving/flying over the water (in editor or in runtime), the water surface starts to oscillate and move. This seems to only happen when the Gerstner waves are enabled.
     
  14. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    you should check your water volume mesh. do the edge vertices get disconnected by gerstner waves?
    even if the outer vertices are properly masked by vertex colors so the do not get displaced high steepness and amplitude values may corrupt the mesh.
    and of course you have to make sure that the water volume is small enough so that it does not get clipped by the far clipping plane.

    i have never seen anything like this. and do not have any idea how it actually looks.
     
  15. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    version 1.07 is online, happy diving!

     
    OdderOtter, Vincent454 and sjm-tech like this.
  16. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    606
    Ok no problem. Thanks for the update!
     
  17. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    official support for azure and enviro is coming with the next update.

    luxwater_azure.jpg
     
    Mark_01, ftejada, Rowlan and 2 others like this.
  18. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    779
    Getting pixelation when I try to add Lux water on my Mac (Unity 2018.3.1.f1). Any idea what might be happening?

     
  19. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    no idea, sorry.
    which water shader is it?
    do you use forward or deferred?
    metal or opengl core?
    and have you checked the included demo scenes? how do they look?

    actually version 1.07 has some issues regarding vface on metal which will be fixed in the next update.

    this is how it looks:

    Bildschirmfoto 2019-01-15 um 16.33.56.png
     
  20. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    version 1.071 has been submitted.
     
    ftejada likes this.
  21. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,200
    Thanks, it's already live. That was fast :)
     
  22. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    really fast.
     
  23. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    779
    I use deferred and metal and yep my settings are like the ones in your screenshot except that I have both static and dynamic batching enabled.
    I've just updated to the latest lux water and this is what the simple demo looks like in my project:



    Only the muddy water works. The others have that pixelated glitch. Any ideas?
     
  24. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    779
  25. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    that would be fine for water which does not use gerstner waves.
    in case you use gerstner waves you need zwrite.

    you will have to make sure that you have attached the CameraDepthModescript.
    in case the camera is set to deferred you have to enable GrabDepthTexture in this script and edit the shader as described in the docs.
     
  26. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    779
    Ah. Yes. Thought I had read the docs but did so a bit too quickly. Seems fine now.
     
  27. ffertigo

    ffertigo

    Joined:
    May 31, 2015
    Posts:
    12
    Hello, I got your Asset but it looks like the underwater effects are broken here. I'm using Unity 2018.2.20f1. Thank you for your help. Screenshot_7.png
     
  28. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    indeed.
    is your scene view opened at the same time? that might corrupt underwater rendering.
    you may also enable "debug" in the underwater rendering script and enable "gizmos" in the gamme view to get a better picture of the rendered water mask.
     
  29. mmaclaurin

    mmaclaurin

    Joined:
    Dec 18, 2016
    Posts:
    244
    Hello, gentle reminder from a big fan: is it still in the plan to do a Lightweight Render Pipeline version of Lux? Microsplat released LRP, Enviro is working on it, so hoping that I'll be able to move my whole project over when you do LRP for Lux.

    BTW, would be happy to pay separately for a LRP version. That was Microsplat's approach and I thought it was perfectly reasonable.
     
  30. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    i will look into this when its all out of beta.
    but no promise...
     
  31. mmaclaurin

    mmaclaurin

    Joined:
    Dec 18, 2016
    Posts:
    244
    Isn't it out of beta as of 2018.3?
     
  32. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    779
    Lux Water can use Enviro and Azure fog. Any chance you or @Thrawn75 could add Kronnect Volumetric fog integration?
     
  33. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    779
    Also... I don't see the water in Scene view unless I'm very close to the water plane, and even then it shows at a lower height than it does in the game view. Any idea what I'm doing wrong? Mac. Metal U2018.3.2f1
     
  34. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    as far as i know it shall be with 2019.1.
     
    mmaclaurin likes this.
  35. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    metal needs the cameradepth mode script to work properly – which only works in game view.
     
    transat likes this.
  36. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    sorry, but i think this is a little bit out of scope. i am not familiar with this asset and have no idea how it handles transparents. but maybe @Thrawn75 has some answers.
     
    transat likes this.
  37. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    Version 1.072 is available:

    ### Fixed - Caustics in backside rendering fixed.
    ### Changed - Deferred fog improved which now keeps fog above the water surface.
     
  38. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,894
    Hi! I’ll be in contact with Lars to test the integration. Cheers.
     
    Mark_01, mmaclaurin and transat like this.
  39. FreezerJohn

    FreezerJohn

    Joined:
    Nov 14, 2018
    Posts:
    6
    Hi!
    First of all thanks for the great update! The deep water lighting is really nice :)
    But I now got a problem with the blur mask since I've updated from 1.062. It always renders full screen blur when entering the volume trigger; also the same in all demos. Couldn't figure it out ..any clues? Is there a known issue? I'm running 2018.2.15, deferred on DX11
     
  40. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    arrgh, that is a bug, sorry.
    fix it by editing the "LuxWater_UnderWaterPost" shader.
    find line 325ff:

    col.rgb = lerp(col.rgb, underWater.rgb,
    // saturate( (underwatermask.g * 8) * (1.0 - underwatermask.r) )
    underWater.a
    );

    and change it to:

    col.rgb = lerp(col.rgb, underWater.rgb,
    saturate( (underwatermask.g * 8) * (1.0 - underwatermask.r) )
    // underWater.a
    );
     
  41. FreezerJohn

    FreezerJohn

    Joined:
    Nov 14, 2018
    Posts:
    6
    Works perfect, thanks!

    Another thing I noticed: When Vegetation Studios touch react system is active, there leaks light through the edge at the shoreline for edge blend factors greater than 0. I would guess this is somehow caused by the touch collide camera that renders from underneath.
    shoreline_touchCollide.jpg
     
  42. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    hmm, i know this from the editor: if the scene view is opened the water mask will be corrupted. but i have never seen this caused by an aditional camera.
    are you sure that the scene view was closed?
     
  43. FreezerJohn

    FreezerJohn

    Joined:
    Nov 14, 2018
    Posts:
    6
    Yea, the effect is similar, although smaller. Interestingly, in this case, there is no difference when the scene view is opened or closed. But having the scene view opened without the touch collide camera gives the much bigger usual artifact. You can easily test it when you throw in vegetation studio in the deep water demo. I don't know the details, but their camera renders to a texture that gets used their shaders.
    I guess as a simple work around I just deactivate the camera when in water, there's no need for touch collide anyway. So solving this issue is not super important to me, but thought it's worth mentioning.
     
  44. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    it is!
    i will look into solving the scene camera issue – which may already fix the vs issues as well.
     
    Rowlan likes this.
  45. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    after having a very deep look into the rendering i think:
    - this only occurs if you are using tesellation - right?
    - and it turned out that in case you are using tessellation "_WorldSpaceCameraPos" does not seem to be set properly when drawing the water mask - which is needed by the tessellator. if i set it by script everything looks fine for me.
    additionally we seem to have to set the "_ProjectionParams" as well.
    if al of this is done neither scene view nor an additional camera seem to currupt the underwater post anymore :)

    attached the updated script.
    please let me know if it works for you.
     

    Attached Files:

  46. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Hey @larsbertram1, Love the shader! Just started splashin in it this week and biggest issue I came across, which I am not sure if there is a fix, is fog or atmospheric scattering-


    Is there a way to get a scattering effect like Volumetric lighting, Azure[Sky] or even fog working with the shader?
     
  47. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    779
    Just opened the Lux Water Volume Splitscreen Demo and am getting 2 errors and one warning in the console:

    Code (CSharp):
    1. [Error] Shader error in 'Hidden/LuxWater_DeferredShading': forced to unroll loop, but unrolling failed. at /Unity/2018.3.2f1/Unity.app/Contents/CGIncludes/UnityDeferredLibrary.cginc(134) (on metal)
    2. Compiling Fragment program with DIRECTIONAL SHADOWS_SCREEN UNITY_HDR_ON LUXWATER_DEEPWATERLIGHTING
    3. Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP UNITY_HARDWARE_TIER3 UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_LIGHTMAP_FULL_HDR
    and

    Code (CSharp):
    1. [Error] Shader error in 'Hidden/LuxWater_DeferredShading': unable to unroll loop, loop does not appear to terminate in a timely manner (1024 iterations) at /Unity/2018.3.2f1/Unity.app/Contents/CGIncludes/UnityDeferredLibrary.cginc(136) (on metal)
    and

    Code (CSharp):
    1. [Warning] Shader warning in 'Hidden/LuxWater_DeferredShading': gradient instruction used in a loop with varying iteration, attempting to unroll the loop at /Unity/2018.3.2f1/Unity.app/Contents/CGIncludes/UnityDeferredLibrary.cginc(139) (on metal)
     
  48. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    hey baldinoboy,

    the shader supports fog as rendered by azure and the upcoming version of enviro.
    in both cases you have to edit the "LuxWater_Setup.cginc" file and comment/uncomment the desired fog version.

     
    glenneroo, Baldinoboy and Rowlan like this.
  49. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    funny unity! but i will have a look into it.
    it compiles fine in 2018.3.1.
     
    Last edited: Jan 20, 2019
  50. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    i just checked lastest in 2018.3.1. and it compiles fine on metal.
    i am not entirely sure if it is 100% equal version 1.072. if not: version 1.073 should be coming the next days.