Search Unity

[RELEASED] Lux Water

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

  1. carodak

    carodak

    Joined:
    Sep 22, 2018
    Posts:
    11
    When I increase the scale of a copied water_plane (scale x 23950.26, y 5252, z 18068) some of my underwater is not rendered. It works like a charm with default scale.
     

    Attached Files:

  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    if you scale the water the water volume may simply be clipped by the far camera plane.
    don't do so! use as sliding water volume instead. please have a look into the endless ocean demo.
     
  3. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    Do you need to recreate the actual distance? If you could get a render of what they look like on-screen that would be close enough, right?

    In my current project I'm toying with the idea of just keeping a copy of the previous frame for use in screen space reflections. In that frame the distant objects will already have their fog applied. Being one frame behind shouldn't be noticable in my game, especially if I offset based on camera movement.
     
  4. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    oh, we are talking about planar reflections which are rendered using a 2nd camera.
     
  5. wigglypuffs

    wigglypuffs

    Joined:
    Aug 10, 2015
    Posts:
    67
    Having an issue with lux water + enviro + unity2019.1.4f1 + standard 3d project. When my camera just slightly dips below the camera surface there is a brief moment where underwater effects aren't depicted.
     
    Last edited: Jun 8, 2019
  6. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    can you enable debug (and check "gizmos" in the game view)?
     
  7. wigglypuffs

    wigglypuffs

    Joined:
    Aug 10, 2015
    Posts:
    67
  8. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    ah, you used a non matching volume. i am glad you solved it!
    did turning on debug help you?
     
  9. wigglypuffs

    wigglypuffs

    Joined:
    Aug 10, 2015
    Posts:
    67
    I solved this specific issue through intuition. Also, I followed a process of elimination, checking what was different between my project and the demo scene. But, I was able to shortcut to the solution by having a hunch that it was a mismatched volume.
     
  10. wigglypuffs

    wigglypuffs

    Joined:
    Aug 10, 2015
    Posts:
    67
    What would be the best way to approach having Enviro rain drops hit the actual surface of the Gerstner waves?

    I believe the lux water documentation indicated there is integration with Enviro. Does this mean that feature is supported?

    Right now the drops strike the ocean floor in an unnatural way.

    Edit: I experimented a bit at runtime with the rain particles, setting the layer mask to water for the collision property of the particle system. While that causes the rain to strike the general area of the surface, it is far from hitting the actual waves.

    Perhaps this rain would have to be replaced with a completely new rain shader, that simply gets triggered by Enviro's weather system via event and disables Enviro's particle system. Thoughts?
     
  11. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    nope.
    particle collision uses physix afaik. but gerstner waves only exist in the shader. if you need the height of the waves at a given point you will have to reproduce the same math the shader does on cpu like provided by the utility script.
    too expensive to do it on particles i guess even if you go jobyfied. and this would only be the collision. how do you add the force from the waves to the water ripples?
     
  12. mmaclaurin

    mmaclaurin

    Joined:
    Dec 18, 2016
    Posts:
    244
    I'm working to get this scene running properly on iOS. It uses the underwater effect, looks great on Metal on MacOS

    1. Camera is deferred
    2. Using 5x5 infinite ocean rig.
    3. Have pushed the near clip plane forward to get this aquarium effect, hacked camera trigger to activate while camera is still in this position.
    4. Using Gerstner waves
    5. Using Metal on iOS
    6. Have uncommented appropriate LUXWATERMETALDEFERRED in "LuxWater CG Tessellation.shader"
    7. ZWrite is turned off in materials (both the close-in material and the skirt material)
    8. ZTest is LessEqual
    9. Culling is Back
    10. I've applied the Lux Water_Camera Depth Mode script to my camera and checked "Grab Depth Texture"

    It looks great on MacOS, but on iOS device I see the following problems:
    a) peaks of waves flicker as though front and back are z-fighting ? (not shown in image, needs video)
    b) areas of high brightness are showing black speckles (shown in image below)
    upload_2019-6-9_9-46-45.png upload_2019-6-9_9-59-47.png upload_2019-6-9_9-46-45.png upload_2019-6-9_9-59-47.png upload_2019-6-9_9-46-45.png upload_2019-6-9_9-59-47.png
    MacOS:

    upload_2019-6-9_9-46-45.png

    iOS:
    upload_2019-6-9_9-59-47.png
     
  13. mmaclaurin

    mmaclaurin

    Joined:
    Dec 18, 2016
    Posts:
    244
    Sorry about all those extra images, not sure what happened there
     
  14. carodak

    carodak

    Joined:
    Sep 22, 2018
    Posts:
    11
    I don't get exactly why the water volume is clipped by the far camera plane but I saw that yeah.
    Doing what you said, it solved the problem. I just have a little last problem.
    With the sliding water when I look down (face the floor) a small triangle appears

    Thank you very much
     

    Attached Files:

  15. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    unfortunately i can not debug on ios. so i can only give some hints, sorry.
    in order to track the issue down you will have to edit the "LuuxWater_Core.cginc" file.
    • Find: c.rgb = Refraction + specularLighting * (1 - Foam.a * backside);
      here specular lighting gets added to Refraction. it might either be NaN or negative according to the balck spots you get.
    • so my first try would be: c.rgb = Refraction + specularLighting * saturate(1 - Foam.a * backside);
      this prevents specularLighting from being multiplied with a negative number.
    • if this does not help try: c.rgb = Refraction + max(0, specularLighting * (1 - Foam.a * backside));
    hmm, you also wrote:
    gerstner waves do not work if you do not write in to the depth buffer.if you do not displace the surface nothing will ever overlap. but if you displace the surface wave peaks in the forground of course have to hide smaller waves in the background thus you have to write to depth.

    let me know if this helps in any way.
     
  16. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    just look at the scale you used: "When I increase the scale of a copied water_plane (scale x 23950.26, y 5252, z 18068)"
    so the water plane and the volume will get min 50 * 5252 meters in size = 250.000 meters or 125.000 meters in each direction from the pivot. i doubt that your far clip plane is set to 130.000 meters but maybe 3000 - 5000 meters so large parts of the volume will not be rendered but skipped by the shader leaving holes in the underwater mask.
    maby just a similar problem. you have to make sure that water volume is big enough so its bottom is always below the sea ground.
     
  17. wigglypuffs

    wigglypuffs

    Joined:
    Aug 10, 2015
    Posts:
    67
    Maybe something like this could be done in the shader. Minus the streaking at the end. And, then collision against the general surface with the existing particles fx in enviro to prevent it from traveling all the way to the ocean floor. With their splash effects turned off.

    If someone were to look really close they might notice the lines of rain particles aren't striking the exact positions rippling on the water. But, that would be hard to notice with all the waves and buoyancy anyway.
     
  18. mmaclaurin

    mmaclaurin

    Joined:
    Dec 18, 2016
    Posts:
    244
    Okay, interesting, I will do some testing this evening, but have some clarifications:
    - why does everything work so well on the Mac even with ZWrite being off?
    - I thought that ZWrite wouldn't work on iOS? I'll give a try, though
     
  19. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i does not work on metal desktop using deferred.
     
    mmaclaurin likes this.
  20. wigglypuffs

    wigglypuffs

    Joined:
    Aug 10, 2015
    Posts:
    67
    How do I tone down the water in this scene. Hard to explain what I mean, but it doesn't seem to be realistically lit considering the dark cloud cover. Which parameters should I be looking into?

    Thanks in advance.
     
    Last edited: Jun 20, 2019
  21. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    you have to tweak the reflections. you are using real time planar reflections right?
    actually i would skip these as they do not contain fog from – enviro?
    go with cubemap based reflections instead.
     
  22. pmargain

    pmargain

    Joined:
    Aug 10, 2017
    Posts:
    10
    Hi,

    I don't have much experience with Unity, and I'm wondering if Lux Water works with VR?
    Thanks!
     
  23. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    yes, but some features currently one in multipass stereo.
     
  24. carodak

    carodak

    Joined:
    Sep 22, 2018
    Posts:
    11
    Yes I get it know, thank you very much, I solved the problem by raising my clipping planes to 2000 (it was 1000 by default). I also read the part in the documentation that is talking about sliding planes and found out that you explained the problem there so sorry for asking something when you made a clear documentation. Next time I will see the documentation first.

    It works like a charm now!
     
  25. kotoezh

    kotoezh

    Joined:
    May 21, 2013
    Posts:
    21
    Hello. First, thank you for this great performing asset. I am using it on Android Mobile, (test phones Moto Z and Moto Z2, snapdragon 820 & 835, OpenGLES3). While on a desktop it looks alright, on my mobiles there are strange squares over the water surface. Example scene screenshots:


    . These sqares are lager than pixels of the normal map ( normal map works - it can be seen on the finely distorted sun) but smaller than waterplane grid and do not depend on grid waves. I have no idea where did these squares come from and how I can remove them.Can you advise please?
     
  26. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i have no idea right now... it looks as if it was related to normals. but if these squares are smaller than the quads of the water plane it should not be the vertex normals. and per pixel normals look fine as you said and one can see.
    how does it look if you disable reflections? maybe your cubemap is "broken"?
     
  27. kotoezh

    kotoezh

    Joined:
    May 21, 2013
    Posts:
    21
    Well, this happens only on mobile and also on the supplied demo scene (deep water rendering). So I don't think it is about broken cube map.

    I am not sure (I am quite new to coding shaders) but recently I had one observation on another asset which demonstrated improper behavior on GLES3 mobile. This shader behaved right on desktop and on GLES2 mobile, but after several minutes its animation began jittering on GLES3. What I figured is that tex2D function is probably calculated in a different way in GLES2 and GLES3 when given large texture coordinates. There were these lines:
    Code (CSharp):
    1. //before:    
    2. fixed4 caustics0 = tex2D(_Caustics, s.worldPos.zx * _CausticsCoord.xy + float2(_CausticsCoord.z + (_Time.x * _CausticsSpeed), _CausticsCoord.w));    
    3. fixed4 caustics1 = tex2D(_Caustics, s.worldPos.zx * _CausticsCoord.xy + float2(_CausticsCoord.z - (_Time.x * _CausticsSpeed), _CausticsCoord.w));    
    4. fixed4 caustics2 = tex2D(_Caustics, s.worldPos.zx * _CausticsCoord.xy + float2(_CausticsCoord.z, _CausticsCoord.w + (_Time.x * _CausticsSpeed)));    fixed4 caustics3 = tex2D(_Caustics, s.worldPos.zx * _CausticsCoord.xy + float2(_CausticsCoord.z, _CausticsCoord.w - (_Time.x * _CausticsSpeed)));
    And I changed them for these to prevent an unlimited growth of coordinates over time:
    Code (CSharp):
    1. //after:
    2.  
    3. float2 causticStaticCoords = s.worldPos.zx * _CausticsCoord.xy + float2(_CausticsCoord.z, _CausticsCoord.w);
    4. float causticTimeShift = fmod(_Time.x * _CausticsSpeed, 1.0f); // it's critical to use modulo to avoid passing large texture coordinates to tex2D
    5. fixed4 caustics0 = tex2D(_Caustics, causticStaticCoords + float2(causticTimeShift,0));
    6. fixed4 caustics1 = tex2D(_Caustics, causticStaticCoords + float2(-causticTimeShift, 0));
    7. fixed4 caustics2 = tex2D(_Caustics, causticStaticCoords + float2(0, causticTimeShift));
    8. fixed4 caustics3 = tex2D(_Caustics, causticStaticCoords + float2(0, -causticTimeShift));

    This modification made it stable, no jumping animation over time, so I supposed that for some reason in GLES3 tex2D multiplies texture dimension on float coordinate and converts it to some integer type, which causes overflow for large float coordinates, and using modulo before passing coordinates fixes the issues.

    I am writing this because I've seen similar constructions in the Lux water code, which potentially would cause wrong behavior on GLES3 mobile. But if so, it is not related only to time, because I am observing the squares right after a start of the app, when _Time.x is still small. But large world coordinates could also cause wrong tiling. Anyways, this GLES3 tex2D different behavior is something that is not obvious and worth keeping in mind.
     
  28. kotoezh

    kotoezh

    Joined:
    May 21, 2013
    Posts:
    21
    I will try disabling reflections and report later!
     
  29. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    according to the color it looks more as if it was "subsurface scattering".
    anything else that looks pixellated? like water borders?
     
  30. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    sorry, i did not see your question...
    have you been able to solve the issue already?
    are you sure all shaders are included in the build? it looks as if the underwater post is missing or does not work.
     
  31. Mysterius

    Mysterius

    Joined:
    Aug 24, 2015
    Posts:
    12
    Hello! I just bought the asset, it is truly fantastic congratulatiuons !

    A small question : is Unity fog (in Rendering/Lighting window) incompatible with Lux Water?
    When I enable the fog, the whole water becomes opaque and the color of my fog.

    I'm sorry if this has been answered before, I couldn't search "fog" in the forum because it's too short :p.
     
  32. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    unity fog works like charm, usually.
     
  33. Mysterius

    Mysterius

    Joined:
    Aug 24, 2015
    Posts:
    12
    Well I don't know why but it messes up with the water in my scene.

    Without fog


    With fog
     
  34. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    does the camera use deferred?
    if so: lux water uses forward and thus simply shows up fog if fog is enabled.
    the terrain and trees might use deferred which needs fog added s an image effect.
     
  35. Mysterius

    Mysterius

    Joined:
    Aug 24, 2015
    Posts:
    12
    I am using deferred, yes and this is deferred fog (deferred fog enabled in the Post Process Layer and then in the Lighting window). So... what you are saying is that I cannot have this fog with Lux Water ?
     
  36. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    you can.
    but i can't see any deferred fog (like on the trees or the terrain). only the forward fog on the water.
    so check your post processing settings (layer settings, is colume global, things like that) and make sure you get any deferred fog at all.
     
  37. Mysterius

    Mysterius

    Joined:
    Aug 24, 2015
    Posts:
    12
    Oh I see ! Well that's because it was too far to be seen. Here's a new screenshot with the deferred fog closer and visibly enabled. The water is still messed up.
     
  38. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    ok, fine :)
    you use linear fog... out of the box lux water only supports exp2. in case you want to use another fog mode you have to edit the config file. please refer to the docs to find the proper instructions:
    https://docs.google.com/document/d/...m38h-u3Az-ozaaOX0/edit#heading=h.khr8bprcxqw9

    and please: do not get upset when there is no fog on the planar reflections. this is not supported because of how unity handles fog and planar reflections are rendered.
     
  39. Mysterius

    Mysterius

    Joined:
    Aug 24, 2015
    Posts:
    12
    Aaaah I'm so sorry! I read the doc but I guess I didn't pay enough attention!
    I've edited the required files and it works now. Many thanks :)

    Don't worry about the fog not reflecting, that's good enough :)
     
  40. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    fine! and you are welcome.
     
  41. kotoezh

    kotoezh

    Joined:
    May 21, 2013
    Posts:
    21
    Ok, switching reflections off does not help. I changed normal map to clear visible circle geometry and can say it is alright, then I set different colors for a fog and scattering and seems it is scattering indeed (orange)
    Any ideas where to dig next?

     
  42. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    like i wrote before :) does anything else look pixellated? like water borders?
    or – if you enable – dynamic foam borders?
     
  43. MightyAnubis

    MightyAnubis

    Joined:
    Jan 29, 2018
    Posts:
    67
    @ Larsbertram:

    is there a way, to bring the WaterVolume to a Size, that allows Diving Depths of 100 Meters and more?
    Because the Problem is, after 1 or 2 Meters "Diving depth" all is dark like Night.

    and if i change the Water Light Breaking, all is like there is no water,this just looking not so nice.

    i need more Light in Diving mode. How can i handle this ?
     
  44. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    have you checked the deep water rendering demo? there you can definitely dive deeper than just 2 meters :)
    there are 3 params which drive light attenuation:
    1. light attenuation according to depth (and max depth)
    2. light attenuation along view
    3. deep water rendering and the Directional Lighting Fade Range.

    i guess you have to tweak 1. to bring back lighting at a depth of 2 meters.
    tweaking 2. should fix this problem:
     
  45. mrMonkey

    mrMonkey

    Joined:
    Mar 19, 2015
    Posts:
    3
    Hello! I'm trying to develop a boat game with infinite ocean.
    When I use GetGestnerDisplacement(myBoatPos,Description,NoOffset) My boat follow the waves but with a weird offset.
    Like if the wave tilling was really small acording to the real waves. (Between two waves my boat go up and down 3 or 4 times).
    Any ideas guys? :)
    Description is updated every frame by the way.
    Thank you!
     
  46. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    the shader can apply displacement only at given vertices. so it has a fixed resolution (well, some kind of dynamic if you use tessellation) and might miss a lot of the waves.
    the displacement as calculated by script however has an infinite resolution.
    try to assign the tessellation shader and crank up the tess factor to see how your waves actually look.
     
  47. MightyAnubis

    MightyAnubis

    Joined:
    Jan 29, 2018
    Posts:
    67
    @ Larsbertram: Found it, you mean the Dive Deep Script, i add it, works beautiful :) Kombi is now infinite Ocean + diving Depth.

    but i have one Question left:
    i want to effect the Shader to give an other Color (Fog Color) via Script.
    You discript it as "_Color"

    i did.
    mat.SetColor("_Color", new Color(WassercolorR, WassercolorG, WassercolorB, WassercolorTranse));

    if i change the Color this way, LuxWater goes only to ffffff ( so White )
    ( The Wassercolor R G B and Transe = Floats i change )

    best solution will be to "fade" the Colors (For example : from Color 1 to Color 2 )

    Goal i want to reach:
    I want red water @ Sunset and Sunrise @ special Times, after this, it should go to Blue ( night ) and back to brighter blue ( Day )

    Any Ideas ? fade will be better than just "set" but i have no idea to do this.

    1 QUestion left:

    WeatherMakerLux.jpg

    is happening if you use: "Weather Maker" and Lux Water, and turn on HDR.
    Any Idea what is the Problem, and is this to solve ? ( can you update this ? )

    Best Greetings, and thank you for your hard Work!
     
  48. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    are you sure your color is correct? try using: mat.SetColor("_Color", ColorColor.red);
    then make your sun light red at sunset :)
    _Color in LuxWater is the Underwater Fog color – like dust floating in the water.
     
  49. MightyAnubis

    MightyAnubis

    Joined:
    Jan 29, 2018
    Posts:
    67
    Hello Lars,

    Lux Water do not react to the Sun and Suncolor on Weather Maker. WAter always stay like it is ( That means: if you change the Fog, you get the most effect on the Water Color , but the Sunlight is nothing changing, indeed: also not @ Night, dont cares if the Moon or the Sun is shining, that is the Problem ).

    try using: mat.SetColor("_Color", ColorColor.red);
    Later this Eavening i try this, but one Question: This is not RGB only "Red" Code.
    Are a way to have R,G,B ?

    Wave Height i got, works nice. So lux Water ( with my Script ) changes VERY VERY slowly, the Waves in confirm to the Weather ( later, if i have fit all together, i post a Video here, over Lux Water, that Asset works so great....

    i wonder how much hours you have inside this.

    And: Have you any Idea, to "fade" the Color of the WAter ?
    ( so not set like a Swithc: Red, blu, green, > fade, for example, from ffffff to fffff1 ( only for example )

    i do not undersand why my Code is not working, i try your Way later :) Thank you.
     
  50. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    it is quite a while that i looked into weather maker, but i did not notice anything like you described.
    lux water fully react to real time lighting.
    if your sun does not effect it than i guess you have done something wrong. maybe the culling mask of the sun does not include the layer the water uses. looking into any other solution to change the lighting of the water but just making the light actually effect the water would be ridiculous. so you should spend some more time on finding the bug.
    you may start with checking the layer the water is assigned to and creating a transparent material using the standard shader and setting it to the same layer.
    "Color.red" is the short code for "new Color(1.0f, 0.0f, 0.0f, 0.0f, 1.0f)". it is RGBA.
    many :)
     
    MightyAnubis likes this.