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,899
    na, not out of the box. but it contains code for sampling directional shadows on transparent materials.
    however: this may not fit underwater rendering.
     
  2. KarloE

    KarloE

    Joined:
    Aug 26, 2013
    Posts:
    175
    Got it. Well I got the package nevertheless, even if it doesn't work out in this sense, I'm happy to support.

    Could you point me in the right direction when you get a moment? What part of the code to look for, etc.

    Thanks a ton.

    Btw I got quite a collection now! :)

    upload_2021-6-2_19-6-5.png

    EDIT: I think I found it, it is probably this "GetLightAttenuation" part, right?
     
    Last edited: Jun 2, 2021
  3. KarloE

    KarloE

    Joined:
    Aug 26, 2013
    Posts:
    175
    Will definitely need some guidance on this when you are available.

    EDIT: I managed to do it using command buffers. No clue if its a good way to do it. It works very well visually.

    upload_2021-6-2_21-48-24.png
    I
     
    Last edited: Jun 2, 2021
  4. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    ah, fine.
    and yes: for the underwater caustics you may simply sample the screen space shadow map.
    i thought about shadows in general and especially on the water surface which needs a different approach like the one the particles takes. sorry abut the confusion.
     
  5. KarloE

    KarloE

    Joined:
    Aug 26, 2013
    Posts:
    175
    Main thing is it works! :)

    Now the only 2 things I still need underwater shader to do eventually (but not urgently) are:

    1. Underwater sun shafts like in subnautica, I'm gonna work on that bit once I get a moment
    2. There is still that problem from ages ago with underwater mask having holes, each time I enable gerstner ways they appear. So I'm keeping the surface flat for now but would definitely love to have waves eventually.
     
  6. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    after doing a lot of tests and investigation i came to the conclusion that these holes are simply created by the gpu and automatically dropping small triangles.
    so the only way to fix this would be prefiltering the mask.
     
  7. KarloE

    KarloE

    Joined:
    Aug 26, 2013
    Posts:
    175
    So basically filling the holes after mask is created? If yes, that was my idea as well.
     
  8. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    yes.
     
  9. zenforhire

    zenforhire

    Joined:
    Nov 5, 2012
    Posts:
    65
    We are using Infinite_Ocean.
    We change Cameras each time player moves to a different station. NOT one Camera for whole game.
    We read your code as it takes the first Camera and never assumes the Camera will be different the next LateUpdate.
     
  10. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    simply make the camera variable public.
    or use cam = camera.main in the update function now that it is far less expensive these days.
     
  11. MGreenberg

    MGreenberg

    Joined:
    Oct 21, 2019
    Posts:
    3
    Hi, How to I change the black fog depth of the Ocean... I am building a sub game and it gets dark 10m under the surface how do I change that to 100m for instance? Excellent water system :))
     
  12. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    you have params for "along view" and "along depth" which should let you do what you want.
     
  13. Masashi-Wada

    Masashi-Wada

    Joined:
    Jul 6, 2010
    Posts:
    87
    Hi,
    I need a great ocean on my smartphone. Now, I'm excited that Lux Water is the closest thing to it. I saw noise on the screen when I ran it on my device. Is there any information about this?
    It's not that you can't see the ocean, it's what you see in the next frame that renders the correct ocean, and in that frame you see noise elsewhere. So I don't think Lux Water won't work on mobile.

    It uses ROG Phone and gives the same results on both Forward and Deferred, as well as on both OpenGL ES3 and Vulkan. (build for Unity2020.3.9 windows)
    Thank you.

     
  14. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    i never ran it on a mobile device, sorry.
    there used to be some precision problems where real halfs corrupted rendering but these should all be converted to floats.
    what catchs my eye: i do not see any reflections there? so maybe it is reflection probes here going nuts?
     
  15. Masashi-Wada

    Masashi-Wada

    Joined:
    Jul 6, 2010
    Posts:
    87
    Hi,
    Thank you for your support.

    I found this noise to occur when using "Enable Caustics". After disabling it, I don't see any noise on my smartphone. I don't understand the exact reason, but it's a great solution for me who need the ocean.
     
  16. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    thanks a lot for the feedback!
    caustics need the depth or normal buffer (only available if using deferred) to be accessible. no mobile feature i guess at all. so further investigation should not really be worth it as you most likely will disable it anyway due to performance.
     
  17. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,476
  18. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    there is
    no tutorial – just the demo scene. but it should just work?
     
    khos likes this.
  19. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,476
    Many thanks for your quick reply, here is a short video of the behaviour


    The foam bit works but the vehicle is not making any tessellation/displacement. Any tips would be welcome.
     
  20. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    you have to enabel and add projectors.
     
    khos likes this.
  21. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,476
    Thanks for the tip. I am trying to add the normals projector but so far only see the pink bit see screens:
    upload_2021-6-14_19-52-16.png
    The debug info shows foam projectors registered 2, but no normals one, but I have added added the one "PF_Water Normal Projector Ripples" prefab supplied by the asset:
    upload_2021-6-14_19-52-52.png

    Any hints would be most welcome
     
  22. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,476
    PS I also see similar thing with the sample scene "06 LuxWater Water Projectors Tess Demo", could my project settings have something to do with it?
     
  23. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    this is fine for the scene view.
    you have to check game view for the final result.
     
  24. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,476
    I have checked the game view, see 2nd screenshot, nothing shows, do I assume that I need to move the PF_Water Normal Projector Ripples around some to see the final result?
     
  25. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    did you add the luxwater_projectorrenderer script to the camera?
    please use the frame debugger to see if the projector ever gets rendered.
     
  26. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,476
    Thanks, yes, screenshot one in my previous post shows I have got the script added, not sure of the frame debugger but I can only see the gui text shows that no normal projector is registered, even though it is in the scene, same goes foe the sample scene that is shipped with asset.

    Hmm, I might try create a new test project, import your asset and see what that does, maybe there is a setting in my project that interferes, weird.
     
  27. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    sorry, i missed that one :)
    in the frame debugger you should see the foam buffers being rendered to custom render texture. this should happen very early in the frame = at the top of the frame debugger.
     
    khos likes this.
  28. yumyumumy

    yumyumumy

    Joined:
    Sep 8, 2020
    Posts:
    2
    I am considering the water asset. Does this support planer reflection in VR (single pass rendering)? I've been searching for a long time and can't find anything that supports water reflection.
     
  29. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    most likely not... basic vr rendering is supporte which includes underwater as well, but planar reflections are kind of expensive. so i never looked into this.
     
    yumyumumy likes this.
  30. yumyumumy

    yumyumumy

    Joined:
    Sep 8, 2020
    Posts:
    2
    Thank you for the reply. Maybe there is no water asset that supports reflection with VR single pass in the current situation (CetoWater works for multi-pass, but I'm looking for single-pass). Your water assets are high quality and I will check your work in the future.
     
  31. rasto61

    rasto61

    Joined:
    Nov 1, 2015
    Posts:
    352
    @larsbertram1 hi, can you please check our private conversation?
     
  32. Fabraz

    Fabraz

    Joined:
    Sep 15, 2014
    Posts:
    66
    Hi again!
    We've run into another rendering issue and wanted to check if you had any insights on it. There's some visual artifacting going on with gerstner waves that we noticed recently, here's 2 examples.

    waterStormy.png
    (the darker bits here) waterBright.png
    (the bright teal parts here)

    It looks to me like the underwater fog color cutting through and getting applied on the surface. We'd previously been using metal support, but found that turning ZWrite back on fixed the problem in the editor. In the console builds however (switch specifically) the water surface no longer renders at all. Any idea what could be causing it to not render on certain platforms? Even trying a totally new project importing the plugin, leaving ZWrite on does not render on Switch.

    Any thoughts or suggestions are appreciated!

    Ben
     
  33. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    you manually changed from vface to SV_IsFrontFace in the underwatermask shader for xbox, right?
    so maybe this does not work for other plafroms. other platforms may just use another shader compiler.
     
  34. Fabraz

    Fabraz

    Joined:
    Sep 15, 2014
    Posts:
    66
    Thought that might have been the case as well, so I tried this also with a fresh install of the plugin from the asset store without any of the modifications in. The ocean demo with zwrite on out of the box didn't work either.
     
  35. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    hmm, anything specia about switch's depth buffer you can share?
     
  36. Fabraz

    Fabraz

    Joined:
    Sep 15, 2014
    Posts:
    66
    Nothing that I can see from their documentation/forums unfortunately, but I'll keep looking
     
  37. Fabraz

    Fabraz

    Joined:
    Sep 15, 2014
    Posts:
    66
    Alright, have a bit more info! Did some more testing and found a potential lead comparing frame debugs in the editor vs the build.

    This is looking at the same mesh, the left side is running off the devkit, the right is from the editor.
    cameraDepthIssue.PNG

    The main differences that jump out to me are _CameraDepthTexture and _GrabTexture both having different values unlike the other parameters. Seems potentially related?
     
  38. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    i do not think so, sorry. depth texture is only needed to composite the water properly with the geometry already on screen.
    but your screen shots showing the bug only showed bugs on the surface itself.
    so it is most likely the underwater image effect going nuts here. not the water shader itself.
    try to disable underwater rendering and look if the water surface shows up any bugs.
    i guess not.
    then debug the underwater mask like you did before for xbox.
    i guess switch here does not resolve vface properly. of it ignores the depth buffer for any reason when writing out the underwater mask.
     
  39. Fabraz

    Fabraz

    Joined:
    Sep 15, 2014
    Posts:
    66
    Alright! For disabling the underwater rendering, is that just disabling/removing the component? Not seeing other places to effect that. At least trying it quickly in the editor, it seems to disable most features where the problem would present itself like the gerstner waves, so its hard to say if the problems still there. I'll make a build to see how it presents there though.
    Just to check, the graphical issue only presents with ZWrite off. Are gerstner waves usable with zwrite off normally and thats the issue to solve? Or is Zwrite required and its just the Switch not rendering with zwrite on that is the issue?

    Another potential thing to note is that changing the culling from "Off" to "Back" fixes the issue while ZWrite is off, but obviously runs into issues when underwater and seeing the mesh from below
     
  40. Fabraz

    Fabraz

    Joined:
    Sep 15, 2014
    Posts:
    66
    So I tried with the underwater component back on but with the underwater mask debugging shader back in.

    cameraDepthIssue2.PNG

    So far the gaps in the surface persist both outside the volume and aren't visualized in the debug shader while inside. Seems like that would mean the issue wouldna't be with the underwater mask? Based on the culling I also noted, might it be that the visual glitch is the backface showing instead of the surface?
     
  41. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    na, you can't use gerstner waves and disabling zwrite.
    so this seems to cause the issues here: the surface renders some back faces on top of front faces although front faces should write to depth and therefore occlude the back faces.
     
    Last edited: Jun 30, 2021
  42. Fabraz

    Fabraz

    Joined:
    Sep 15, 2014
    Posts:
    66
    Right, thought that might be the case with zwrite needing to be on.
    And makes sense as to the issue, though in that case it seems like the water would more partially render, maybe with those gaps like in the screenshot, but instead its entirely gone in the test project.

    upload_2021-6-29_17-9-46.png

    This also includes the backface when below the water as well.
     
    Last edited: Jun 29, 2021
  43. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    just to sum up:
    - i was wrong about the underwater mask causing the issues.
    - it is the water surface not rendering properly
    - if you turn on zwrite water entirely vanishes?!

    i don't know if there are any debug tools like renderdoc or so for switch which might help to get an insight of what is going on here.
     
  44. Fabraz

    Fabraz

    Joined:
    Sep 15, 2014
    Posts:
    66
    Yup, I think thats accurate so far.
    To add to point 3, I've tried now on PS4, where the water surface doesn't render properly in a different way.
    On Switch, it disappears completely, though occasionally you can see tiny artifacts/pixels of it, I think the line below the horizon in the last screenshot is an example of it.
    Meanwhile on PS4, more of it renders properly, but with large swathes missing. Seems like both along the tesellation/triangles and somewhat screenspace-based with the gaps cutout in large squares/pixels. (ignore the broken submarine material, thats from replacing the plugin in the test project with our main one with the xbox modification)
    cameraDepthIssue3.PNG
    I'm trying a PS5 build next to see if its similar to the PS4, otherwise everythings fine on the other platforms. There is a more dedicated graphics debugger for the Switch I'll try after!

    EDIT: The PS5 build has the same visual issue. I took a video this time to better show it:
     
    Last edited: Jun 30, 2021
  45. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    crazy, here a lot of the primitives are culled. no idea why. this is with depth write enabled?
     
  46. Haze-Games

    Haze-Games

    Joined:
    Mar 1, 2015
    Posts:
    186
    Hi all,

    First, thank you @larsbertram1 for this amazing water asset :)

    I'm trying to know when my camera is actually underwater, because I have grestner waves, meaning sometimes the camera can be underwater even if it's actually above the water plane position / trigger collider, especially when the camera is at a "high amplitude wave" at this moment.

    I read the documentation, and saw that I need to check the "grestner height". I have tried doing so, but the provided LuxWaterUtils.GetGestnerDisplacement() returns an offset that greatly mismatches the actual wave height at requested position.

    I have also tried with a floating object using the provided script SetToGrestnerHeight, with no dampening, no time offset, and update every frame, and as you can see - it often goes downwards when the wave is actually going up (this is using SetToGrestnerHeight component):



    Please check especially at 00:30 above to see the issue more clearly.

    This issues makes it impossible to know if the camera is under water. Any ideas of what may be causing this?

    I'll continue investigating... Maybe water scale has an impact on the offset calculation, or some other parameter that I'm unaware of?

    Thank you!
    Charles
     
  47. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    this script returns a height pretty close to the height offset of the waves. but as these are distoreted in all 3 dimensions it is not fully accurate. nevertheless you should get a somehow matching result.


    yeah, scale is not supported at all. the GetGestnerDisplacement script performs calculation close to the vertex shader. but if you scale your water plane in the final from object space to world to clip space operation using scale the script has no idea abot this.
    so do not scale meshes!
     
    Haze-Games likes this.
  48. Haze-Games

    Haze-Games

    Joined:
    Mar 1, 2015
    Posts:
    186
    OK thank you for the quick reply! But... my only scaled objects is the water plane itself. In the demo scenes, water objects are highly scaled (in the 3000ish) so I though that was OK (I have same scales of water as in the 07 LuxWater Water Volume Forward Demo).

    Will take a deeper look into this, as I guess it should match closely to it, not as I'm having right now :D

    Cheers,
     
  49. ScorphiusMultiplayer

    ScorphiusMultiplayer

    Joined:
    Nov 10, 2018
    Posts:
    66
    HI,

    If I lower the far Clipping planes. - Far to less than 600/500. Part of the ocean does not get rendered.


    upload_2021-7-14_8-52-42.png
     

    Attached Files:

  50. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    this is a problem described in the docs: if the underwater volume is larger than your far clipping plane parts of the volume will be clipped generating holes in the underwater mask texture.
    so reduce the size of the volumes or raise your far clipping plane.