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. Fabraz

    Fabraz

    Joined:
    Sep 15, 2014
    Posts:
    66
    Hi there!
    Love the plugin, its worked/looked great throughout the project! I'm porting my project to Game Core Xbox One and have encountered a few weird bugs though. Neither has happened on any other platforms or in the Editor.

    One is a long pause when first rendering the underwater mask, visible as a really long hiccup in the editor. We have graphics jobs on, and the Semaphore.WaitForSignal call makes me think it could be connected to that, though we haven't encountered other issues with graphics jobs being on:


    The other issue encountered is something causing the underwater rendering to kick in, I think immediately upon entering the collider rather than taking the wave offset into account.

    Just above the collider:
    upload_2021-5-17_11-40-55.png

    Just below:
    upload_2021-5-17_11-40-26.png

    I tried looking for anything platform specific in the plugin, but couldn't find anything. Any ideas what might be the issue or a where to start looking? It's currently using version 1.081 of the plugin if that helps, though I didn't see anything in the change logs that seemed like it might be related.
    Thanks!
     

    Attached Files:

  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    ah, the profiler already tells you what's going on: Shader:CreateGPUProgram.
    so you have to prewarm the underwater shaders.
    maybe the underwater mask is not rendered properly. if at all. you could enable debug to see how it looks.
    or assign it to a cube that is parented under your camera so you will see it in build.
     
  3. Fabraz

    Fabraz

    Joined:
    Sep 15, 2014
    Posts:
    66
    Thanks for the added info!
    Currently the prewarmedShaders field is assigned on the LuxWater_UnderWaterRendering script on the camera, which seems like it should prewarm it on startup. And the variants file is included in the preloaded shaders list in the Graphics settings. Is there some additional way that I might have missed to preload it?

    And I'll try the cube approach with the next build. Which shader would the material use? "Hidden/Lux Water/WaterMask"?
     
  4. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,240
    I'm doing some profiling of our game on Intel integrated graphics, and found that GrabPixel uses 2.3ms on the GPU, from Lux Water, which I assume is required for translucency? I'm wondering if there could be ways to disable that in an alternate water material for low-end computers, and/or disable it for LOD materials (don't need translucency or transparency at a distance). Maybe those are beyond the scope of Lux Water, but any suggestions?

    thx!
    Dave
     
  5. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    that might not work … unity. so adding some rendered using the materials somewhere in the scene might be a more robust solution.
    unfortunately you have to write a custom shader which samples the globally assigned texture _UnderWaterMask
     
  6. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    debug shader attached.

    the result in play mode in editor should look like below.
    the cube should at least show something here...


    debugShader.PNG
     

    Attached Files:

  7. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    see my last answer
     
  8. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    not really. lux water grabs the entire screen using built in functionality. dividing your water meshes into several smaller pieces may issue several grab passes which my even be more expensive.
     
  9. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,240
    Argh, really? I have over a dozen water meshes....
     
  10. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    that should not be the issue here as they all share the same grab pass.
     
    gecko likes this.
  11. Fabraz

    Fabraz

    Joined:
    Sep 15, 2014
    Posts:
    66
    Thanks for the debug shader!

    I tried comparing the masks behavior between the editor and the build, and in basic placement/shape of the plane they seem the same, the issue I think is the build version isn't picking up the shape of the actual waves.

    Seems like the color switch from red/green is based on the masks above/below water state? In the build that value seems to be binary, only appearing fully red or fully green. Additionally, the water I was testing on didn't really have tall waves, but it seemed fully flat in the build vs having some slight ripple in the editor

    This pic is from the editor. I figured out better rotation/viewing since the build below.
    upload_2021-5-19_16-11-22.png

    Heres how it looks in the build. The red/green switch is instant and binary, no partial state like in the above.
    upload_2021-5-19_16-20-22.png
     
  12. TaylorCaudle

    TaylorCaudle

    Joined:
    Feb 8, 2018
    Posts:
    154
    Getting a bunch of errors when trying to build, game works fine in testing, but wont let me build.
     

    Attached Files:

  13. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    have you moved the scripts out of the editor folder? well, the file path still contains "editor" so it should just be ignored?!
     
    Last edited: May 20, 2021
  14. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    hmm, hard to see anything :)
    but if the switch is instant maybe xbox one does not support the format of the render texture used by the under water mask. altho it is just a simple RenderTextureFormat.ARGB32.
     
  15. Fabraz

    Fabraz

    Joined:
    Sep 15, 2014
    Posts:
    66
    Yeah, I was wondering that too when I was looking through the scripts and made a build to test, the format was supported.
     
  16. Fabraz

    Fabraz

    Joined:
    Sep 15, 2014
    Posts:
    66
    I tried making a new project with just the plugin and seeing how it fared, no change unfortunately. I also got a video in one of the example scenes to show the issue more clearly:

     
  17. Fabraz

    Fabraz

    Joined:
    Sep 15, 2014
    Posts:
    66
    Might be a shot in the dark, but I also had compile errors for XRSettings in the Game Core Xbox platform target because it doesn't allow/contain the VR integration. I commented these out and it seemed fine in the editor, but might there be something on the shader side being thrown off by this feature not being supported?
     
  18. TaylorCaudle

    TaylorCaudle

    Joined:
    Feb 8, 2018
    Posts:
    154

    Huh? It’s a fresh import. Nothing has been moved around, everything in the Lux folder is wherever it is on import. No scripts have been moved to different folder.

    many idea why this is happening? Can’t build the game
     
  19. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    no, i have never heard about these errors before und building here works fine. actually the scripts that error shall never land in the build as they are editor only. so maybe something with your project is messed up?!
     
  20. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    at leat underwater rendering looks fine.
    i have no idea what is going on there right now. maybe tomorrow with fresh eyes...
     
  21. Fabraz

    Fabraz

    Joined:
    Sep 15, 2014
    Posts:
    66
    Yeah. I've been trying removing certain passes from the underwater mask and overriding certain values in it and the core shader to see if I can replicate the same look between editor and build. It's hardly conclusive, but I think it might be down to depth values not being correct in the build? For instance I commented out all but the first pass of the underwater mask and the two were still looking different. But I set surfaceEyeDepth in the frag shader for LuxWater_Core.cginc and the two ended up looking about the same. Would depth coming back as always 1 or 0 potentially lead to that visual issue? Though there are Image Effects in the project using depth just fine, so would be an odd issue to run into just here.
     
  22. TaylorCaudle

    TaylorCaudle

    Joined:
    Feb 8, 2018
    Posts:
    154

    I just imported it into a fresh project, and its still doing this. Does this no longer work with 2019.4.11?

    EDIT: errors being thrown seem to be related to NWH Dynamic Water Physics integration.
    Specifically the Assembly Definition files, NWH uses them but if you dont, then just remove all the .asmdef files from the NWH asset folder after importing.
     
    Last edited: May 21, 2021
  23. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    let me explain some basics first :)
    a) the "water mask" mainly is used by the underwater image effects and contains depth of the water surface and if we are looking on the water surface's front or backside.
    b) but it is also used in the water shader to fix some micro cracks to force the water surface shader to go into underwater rendering regardless of the facing sign:
    line 546 in core: facing = (underwatermask.g > 0) ? -1 : facing;

    from what i can see in the video it is a) causing the issues. you can test this by editing the underwater post shader:
    line 302: col.rgb = lerp(bground.rgb, col.rgb, col.a);
    set it to: col.rgb = bground.rgb;
    so it will simply return what is already on screen.
    blur will be added on top but we can leave this for now.
    if this does not "fix" the issue it might be b).

    back to your question: depth coming always back as either 0 or 1 of course would be bad. but from what i can see it looks as if the under water post shader simply ignores the water surface which is stored in red and green of the mask texture. so depth here is not the driving factor.
     
  24. ScorphiusMultiplayer

    ScorphiusMultiplayer

    Joined:
    Nov 10, 2018
    Posts:
    66

    Attached Files:

  25. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    hmm, i can not really see anything...
     
  26. Fabraz

    Fabraz

    Joined:
    Sep 15, 2014
    Posts:
    66
    Hiya! Thanks for the explanation and suggestions! I was definitely going in blind with the ins and outs of the system haha. Helps to have a bit of context.

    I tried out option a, didn't fix it sadly. I also added the debug material to track the mask in the isolated example scene.

    Here's in the editor:


    And in the build:


    Theres a difference from trying it in my project of it disappearing at a certain distance, but not sure if that might be tied to how this instance is setup for the ocean example. As far as I can tell its picking up the shape of the mesh properly in both, you can see the curve of the wave is visible. The main thing not right seems to be picking up green (i.e. thinking its underwater) immediately. This seems like its upon entering the box collider trigger and the underwater rendering logic kicking in from the script. Not sure where that would be determined to check though.

    Would that line up with option b? Would the solution be changing line 546 that you mention, or is the mask itself potentially the issue?
     
  27. Fabraz

    Fabraz

    Joined:
    Sep 15, 2014
    Posts:
    66
    Some more test examples. I tried another comparison, this time with the option a change reverted and the option b facing override line commented out.

    Editor:


    Build:


    This seems like a more promising change in behavior! The above water blur is off, which is the kind of behavior I think read as a depth/distance issue to me before. And the underside of the water seems like there's the mask not being applied, though presumably thats to be expected removing the line.
     
  28. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    i think it is a combination of a) and b).
    water surface goes into backside rendering b).
    but blur also gets applied to the above water surface which is a).

    and if you compare that last 2 videos you can see that the water mask simply does not contain any red (above water surfaces).
    the mask it just green as soon as you entre the volume so all shaders expect to be below the water surface.
    so the water mask shader and here the pass the renders the above water surface seems to not work properly in the build.
     
  29. Fabraz

    Fabraz

    Joined:
    Sep 15, 2014
    Posts:
    66
    Hmmm, interesting. At least thats some more to work with. I was thinking something similar with the mask being wrong and I was digging in the water mask shader more. Tweaking some values to test, I'm pretty sure the VFACE semantic value "facing" in the surface front/back passes of the shader seem to always return -1, which is causing it to be permanently green like we saw. Does this seem like a viable culprit? And if so, is there anything that could be done to correct for it, or might this be an engine bug with the platform (Game Core)?
     
  30. Fabraz

    Fabraz

    Joined:
    Sep 15, 2014
    Posts:
    66
    Ooookay, so I made a workaround that bypassed the VFACE issue by directly assigning an "isUnderwater" value based on a Gerster displacement check when assigning the mask values in LuxWater_UnderWaterRendering.cs. Not ideal, but at least seems to approximate the effect in the build!



    So if this really is more of a platform bug, there's a workable fallback.
     
  31. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    not sure but xbox uses dx12 by default? and maybe another hlsl shader compiler than dx11 on pc.
    so i guess it ould be worth testing "SV_IsFrontFace" instead of "VFACE".
    "SV_IsFrontFace" is a bool.
     
  32. Fabraz

    Fabraz

    Joined:
    Sep 15, 2014
    Posts:
    66
    Alright, changing it to "SV_IsFrontFace" worked! Thanks for all the tips on tracking down the issue.
     
  33. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    Coool!
     
  34. Fabraz

    Fabraz

    Joined:
    Sep 15, 2014
    Posts:
    66
    So I'm still looking into the other issue I wrote about with the initial post, the loading hitch when first rendering the underwater mask. I'm trying out different approaches to trigger the load on startup, but so far no luck. Looking into the shader variant collection warm up logic though, seems like there might be a similar DX12 issue at play:

    Seems like there's an alternative api that would work for all platforms, but I don't know the right data to pass in for the mask for the last argument. Have you used this approach before, or know how it might be used to see if that bypasses the loading issue?
     
  35. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    nope.
    brute force: trigger the watervolume, underwaterrendering and mask in the first frame e.g. by adding a volume right in front of the camera and destroy it in the 2nd or 3rd frame.
     
    Fabraz likes this.
  36. KarloE

    KarloE

    Joined:
    Aug 26, 2013
    Posts:
    175
    Hello,

    glad to see this asset still alive and kicking. I am fiddling with it at the moment and I'm wondering if you can point me in the right direction. I am trying to modify it to achieve a sort of depth of field - like effect, where blur would only start at a certain distance while the stuff close to the camera is clear.

    I've done that by sampling depth texture in underwaterpost shader doing:

    float eyeDepth = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv));

    and then at the end of the shader doing

    col.rgb = lerp(col.rgb, underWater.rgb,
    saturate(eyeDepth*8.0f)
    );

    This is the result:
    https://prnt.sc/13ir9qm

    As you can see I have a problem where surface is not really written in the depth buffer (I assume so?) and its either completely blurred off or in case of an object sticking out, its depth writes are used and that produces this sharp cutoff.

    What would be the best solve for this? Is there a way to use the masks to compensate for it? Im a bit rusty shader writing wise so I thought it best to ask, also some of my observations might be wrong so feel free to correct me.

    Thank you.
     
  37. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    i can't see any image following the link provided . just upload it it here directly in the forum.
     
  38. KarloE

    KarloE

    Joined:
    Aug 26, 2013
    Posts:
    175
    Sure, here it is.

    Object is sticking out of the water. download2.jpg Just realized my "underwater blur" triggering is broken now because I changed your formula, I gotta fit this in the old formula itself basically somehow.
    download3.jpg This is the problem, the surface itself is not recognized depth wise, just the object sticking out. Which is normal I guess, just wondering whats the best way to go around it to achieve the desired effect.
    download.png Obj
     
  39. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    the water surface is not in the depth buffer which gets grabbed before the water renders (transparent).
    but is is coded into the underwater mask so you can get it from there.
     
  40. KarloE

    KarloE

    Joined:
    Aug 26, 2013
    Posts:
    175
    Ok, thank you I will figure out how to get it from there.
     
  41. KarloE

    KarloE

    Joined:
    Aug 26, 2013
    Posts:
    175
    No clue how to solve it except to write the surface to the depth buffer before postprocessing is applied, but maybe Im not seeing it.


    1. Sccene, visible part where it doesnt blur out the surface because of the thing popping out.
    1.jpg

    2. Underwater mask
    2.jpg
    3. Underwater mask+scene combined
    3.jpg

    Basically, the problem is I can't differentiate between the object being below and above water.

    So if I decide, it's fine for the whole surface to be blurred, no biggie - can't do that because any object in front of it is also gonna be blurred out:
    upload_2021-5-30_20-25-5.png


    And if I say ok but except for the parts in front of it, then the part of the surface in front of the part of the object sticking out will again get unblurred like this, since I can't know that I gotta ignore that piece.

    upload_2021-5-30_20-25-21.png

    Ideally, id blur or unblur the surface properly, with close parts being unblurred and far away ones being blurred, but currently see no way to do it except to write to the depth buffer.

    Can you help me out bit more with it Lars? What is your take on it.

    Literally I managed to fix up everything I need in regards to water except for this part.

    Thank you.
     
  42. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    in the underwater post shader you will find e.g.:

    // watersurfacefrombelowdepth comes in as Linear01Depth
    float watersurfacefrombelowdepth = DecodeFloatRG(underwatermask.ba);
    // Combine sceneDepth and depth of watersurface based on mask
    sceneDepth = (underwatermask.g < 1.0) ? min(watersurfacefrombelowdepth, sceneDepth) : sceneDepth;
    // Distance to eye in units
    float dist = sceneDepth * _ProjectionParams.z;

    that should be all you need here...
     
  43. KarloE

    KarloE

    Joined:
    Aug 26, 2013
    Posts:
    175
    Thanks a ton, works like a charm. A lot of code, completely missed those parts.

    blurgg.jpg
     
  44. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    great, congrats!
     
    KarloE likes this.
  45. KarloE

    KarloE

    Joined:
    Aug 26, 2013
    Posts:
    175
    Any tips how to go about implementing sunshafts such as these seen in subnautica?

    upload_2021-5-31_11-1-5.png

    I know lux water doesn't support them but I was wondering how come and if you have any resource/tip for implementation that would be very helpful.

    The way I see it I need to vary fog color, possibly use a texture for it and apply some time based animation similar to how caustics are made.

    Thanks!
     
    Last edited: May 31, 2021
  46. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    sorry, but i have not looked into this.
     
  47. KarloE

    KarloE

    Joined:
    Aug 26, 2013
    Posts:
    175
    Thanks for the quick answer. No worries.
     
  48. KarloE

    KarloE

    Joined:
    Aug 26, 2013
    Posts:
    175
    Lars, Im guessing caustics shouldn't be visible if the sun is blocked (by a roof in this example) from reaching the surface directly. Any suggestions on how to make it happen - I'm not sure how to get the shadow/light data for a fragment so I can say something like, if there is any shadow probably mask out caustics.

    Thank you.
     

    Attached Files:

  49. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    lux water does not support shadows right now, sorry.
    my lit particles do but that is another package :)
     
  50. KarloE

    KarloE

    Joined:
    Aug 26, 2013
    Posts:
    175
    Can I use that package to achieve this here? I have no problem with getting it if that is the case, I just want this to look bit more realistic.