Search Unity

Official Water System for the High Definition Render Pipeline

Discussion in 'High Definition Render Pipeline' started by auzaiffe, Nov 26, 2021.

  1. Crazy34

    Crazy34

    Joined:
    Jul 14, 2019
    Posts:
    69
    That's good to hear. Then we'll be testing the integration with our players in the coming days.
     
    chap-unity likes this.
  2. soleron

    soleron

    Joined:
    Apr 21, 2013
    Posts:
    582
    mmm it wasn't but you had me look closer and It was turned off in the quality level that was enabled in the editor...
     
    Last edited: Feb 1, 2024
    adrien-de-tocqueville likes this.
  3. edvart-ros

    edvart-ros

    Joined:
    Aug 15, 2023
    Posts:
    17
    I've worked on my ASV simulator and now have a decent buoyancy and hydrodynamic drag model going. Really awesome water system, i love how customizable it is and the ease of scripting. I've yet to play with water deformation, foam and other effects, since I'm not a shader/graphics guy. For my implementation im basically following Kerner's water interaction article, with some slight modifications to the buoyancy calculation.


     
  4. SomerenV

    SomerenV

    Joined:
    Dec 20, 2011
    Posts:
    83
    That second clip looks really good. It's a shame the included buoyancy script with the sample from Unity is so basic and not really useable on a boat as is. For someone with too little understanding of C# to modify it, or create something better, it's a shame it's . I'd think that making a boat float is one of the fundamentals of a package like this one because it's probably what a lot of people are going to use it for.

    Here's to me hoping that some day a little more fleshed out buoyancy script gets added (or you share yours). Right now I'm using a floater script that was dropped here a while ago. It's fine for now, but it's not very accurate in terms of physics.
     
  5. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    The thing is, there's as many buoyancy implementation as there is games. Some implementations will bottleneck on perf, some will want some artistic control, some will want perfect physical buyoncy for primitives only.. etc so we can't really provide something that works for everyone.
    In the water samples there's already one really simple script that makes an object stick to the water surface and a simple buoyancy script working for a sphere in the pool scene you can try in 2023 versions. (cf gif)

    Impact_Pool_VFX.gif

    Then from there you already have a good headstart to create your own depending on your needs.
     
    VOTRUBEC likes this.
  6. edvart-ros

    edvart-ros

    Joined:
    Aug 15, 2023
    Posts:
    17
    I can vouch for this! buoyancy is a hard thing to nail. As u can sort of tell from the video, mine uses linear interpolations between a set of water samples around the object and iterates over the entire mesh to precisely determine the subset of it that is actually submerged. This has to be done for realistic buoyancy, and it scales very poorly with huge/many meshes, at least the way ive implemented it. U can do voxel-based methods, surfacic methods and the "primitives" idea (floaters) chap mentioned. These all suffer from different problems and there really is not straight forward, universal way to choose between them.

    The easy and fake way to do buoyancy is to take samples at discrete points around the boat, typically where u want the water line to lie. Then by querying the water depth at these points u apply an upward force proportional to the depth at the point. This is totally fake, but very easy to implement. Just base your script on the water query example made by unity.
     
    chap-unity likes this.
  7. SomerenV

    SomerenV

    Joined:
    Dec 20, 2011
    Posts:
    83
    You know, my first reaction was 'why not just provide a simple script for a boat...' but, after giving it a second thought and after reading the comment from edvart-ros I now understand that there is no such thing as a simpel script for a boat. I mean, there is, but there also isn't. My issue was that coding a physics related thing like this felt a bit daunting. Coding itself isn't exactly my cup of tea, but physics calculations are way outside of my ballpark.

    But... I thoroughly checked the provided buoyancy script, looked at what the different variables did and how the water was sampled and just started making something. I then remembered seeing a nice buoyancy script on GitHub a while ago, so I incorporated those calculations into my own script to see how that would turn out. Changed some things, added some things, et voila, a simple buoyancy script for a boat!



    Once I'm happy with the end result I'll post a (simplified) version of the script here for others to use :)
     
  8. edvart-ros

    edvart-ros

    Joined:
    Aug 15, 2023
    Posts:
    17
    So i know we have the CPU scripting method of querying water heights, which is kind of expensive due to the iterative nature of the method. Is there a way to access the "height field" of the ocean more directly by using shaders? Say i wanted to do buoyancy work on the GPU (not a script), what would be the most efficient way of querying the water height at a given position?
     
  9. adrien-de-tocqueville

    adrien-de-tocqueville

    Unity Technologies

    Joined:
    Mar 16, 2020
    Posts:
    270
    You can look at WaterEvaluation.compute, it computes the height of the camera relative to the water surface
    You should be able to copy it and reuse it to sample the surface at different positions, but it's also iterative, it's just on the gpu instead of cpu so it's faster
    It's possible to project the water displacement maps to generate a 2D heightmap of the surface and avoid the iterative part, but you'd have to do it yourself and that probably won't be more efficient unless you do a lot of samples (doing the projection is quite expensive i expect)
     
  10. IAndrewNovak

    IAndrewNovak

    Joined:
    Nov 29, 2013
    Posts:
    118
    Hi. Water excluder does not work for my case where an excluder like a hole end needs a depth.
    Video example


    How can I fix that or modify it for my purposes?
     
  11. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    I'm not entirely sure what you mean by "needs the depth" but assuming your water surface is around your hole in the ground here, it would be best to create a water deformer (like a simple box) and push the water down a few meter here so that there's no interaction between the camera and the water surface itself.

    upload_2024-2-18_16-43-34.png
     
  12. IAndrewNovak

    IAndrewNovak

    Joined:
    Nov 29, 2013
    Posts:
    118
    Thanks for your reply. I will try this workaround

    I mean, there is 100% no any water/water lines in the bounds of the excluder mesh. No matter if this box/mesh height is 1sm or 10m.




    In my attached video you can see a water line if the camera stays in excluder bounds and camera Y pos equals water line Y pos.

    In the game I have an underwater station with a pool and a Ship. I need to cut the water where the ship has a hatch but there is still water around the ship
     

    Attached Files:

    Last edited: Feb 18, 2024
  13. edvart-ros

    edvart-ros

    Joined:
    Aug 15, 2023
    Posts:
    17
    Does the water system write to the depth buffer at all?
     
  14. Jack_Martison

    Jack_Martison

    Joined:
    Jun 24, 2018
    Posts:
    143
    Any chance we can see your script? I also bashed my head around simple floating mechanic, but it's also way out of my scope
     
  15. edvart-ros

    edvart-ros

    Joined:
    Aug 15, 2023
    Posts:
    17
    I'm guessing this is what the poster did:
    Define some points on your object (on the corners, or around the object where u want the waterline to be). At each fixed update, query the height of the point relative to the water surface, using the HDRP water system API. If a point is underneath the water (negative y relative to the surface at that point), apply an upwards force there (AddForceAtPosition), proportional to the water depth of the point.

    This gives u a very fake but somewhat convincing buoyancy effect. Add some damping to the object to avoid bouncy behaviour.
     
  16. adrien-de-tocqueville

    adrien-de-tocqueville

    Unity Technologies

    Joined:
    Mar 16, 2020
    Posts:
    270
    yes, same as a refractive transparent
     
  17. edvart-ros

    edvart-ros

    Joined:
    Aug 15, 2023
    Posts:
    17
    I see. For integrating with my robotics-side of things, I'm transmitting a depth image from a camera. I'm doing this by rendering the depth buffer of the camera view into a color buffer (i can easily read this with asyncgpureadback later). When i look at the resulting color buffer (which encodes depth), the water is not visible.

    The function i use for sending the depth data to the color buffer is this: https://docs.unity3d.com/Packages/c...on.CustomPassUtils.RenderDepthFromCamera.html

    in code, im doing:

    Code (CSharp):
    1.         var overrideDepthTest = new RenderStateBlock(RenderStateMask.Depth) { depthState = new DepthState(true, CompareFunction.LessEqual) };
    2.  
    3.         // Depth
    4.         if (depthTexture != null)
    5.             CustomPassUtils.RenderDepthFromCamera(ctx, bakingCamera, depthTexture, ClearFlag.All, bakingCamera.cullingMask, overrideRenderState: overrideDepthTest);
    6.  
    All object depths are fine on the output, but i cannot see the water. Is it due to the override? or culling mask?
    I copied this technique from https://github.com/alelievr/HDRP-Custom-Passes btw

    upload_2024-2-21_14-23-10.png
     
  18. adrien-de-tocqueville

    adrien-de-tocqueville

    Unity Technologies

    Joined:
    Mar 16, 2020
    Posts:
    270
    RenderDepthFromCamera only draws regular renderers, watersurfaces are rendered using custom draws so they are not taken into account here. I'll fix it cause it should work
     
    chap-unity and edvart-ros like this.
  19. edvart-ros

    edvart-ros

    Joined:
    Aug 15, 2023
    Posts:
    17
    Any update on this?
     
  20. Bungarra

    Bungarra

    Joined:
    Jul 29, 2019
    Posts:
    14
    Hey there, is there any further ETA on this? How far away is it?
     
  21. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    Hey, thanks for your interest, but for both of the latest questions, we don't have any ETA yet sadly.
    We'll keep you posted here once we do :)
     
  22. D1234567890

    D1234567890

    Joined:
    Aug 11, 2019
    Posts:
    65
    The water system is leaking uniforms. For example if you create a Shader Graph with the property "Foam Smoothness" and set the reference to _FoamSmoothness they will conflict. This happens even if the water feature is completely disabled in the HDRP settings. I do not know the earliest this has been a problem but reproducible in the latest Unity 6.0 beta and it is a problem in 2023.2.
     
    chap-unity likes this.
  23. soleron

    soleron

    Joined:
    Apr 21, 2013
    Posts:
    582
    It is better to provide something that is great for many people than something that is underwhelming for all people.

    Sadly the later often happens lately from Unity.
    You can't please everyone. Please those who care for you most and would be impacted most.
     
  24. edvart-ros

    edvart-ros

    Joined:
    Aug 15, 2023
    Posts:
    17
    You should be able to code up a floater script on your own, frankly. There's tons of tips online, it's a very simple thing if you're not looking for physically accurate simulation.
     
    chap-unity likes this.
  25. soleron

    soleron

    Joined:
    Apr 21, 2013
    Posts:
    582
    Nope.
    I should be able to mark one thing as a floater and it works. Either through layer or a tag or something like that. Simple straight forward, no brainer. Because that is what kind of thing that should be. A no brainer.
     
  26. silverx69

    silverx69

    Joined:
    Nov 8, 2019
    Posts:
    4
    Hello!

    I am relatively new to using Unity and I'm trying out some experiments with the HDRP Water system (2022.3 LTS) and I thought it would be cool to render the water to a sphere. 6 plane spherical cube. It looks really really cool from the top and the bottom of the sphere, but at the sides it does this:


    How would I go about fixing that? If someone could just point me in the right direction instead of me just poking around in the dark I would be very thankful!
     
  27. Onigiri

    Onigiri

    Joined:
    Aug 10, 2014
    Posts:
    484
    Triplanar mapping is the way to go(I don't know if it's can be used with water shader or no)
     
  28. adrien-de-tocqueville

    adrien-de-tocqueville

    Unity Technologies

    Joined:
    Mar 16, 2020
    Posts:
    270
    Sorry i was a bit busy, i did the fix, it's in review
     
    edvart-ros likes this.
  29. adrien-de-tocqueville

    adrien-de-tocqueville

    Unity Technologies

    Joined:
    Mar 16, 2020
    Posts:
    270
    indeed we should rename the water specific variables in the global constant buffer to have less generic names, thanks for reporting
     
  30. adrien-de-tocqueville

    adrien-de-tocqueville

    Unity Technologies

    Joined:
    Mar 16, 2020
    Posts:
    270
    This is not possible currently as the water simulation is done on square patches and there is no straightforward way to map that on a sphere without distortion
     
  31. silverx69

    silverx69

    Joined:
    Nov 8, 2019
    Posts:
    4
    Darn that's a bummer, because it only looks weird around the equator. Thanks.
     
  32. soleron

    soleron

    Joined:
    Apr 21, 2013
    Posts:
    582
    That would be super important for VFX/Animation work.
     
    Last edited: Mar 27, 2024
  33. D1234567890

    D1234567890

    Joined:
    Aug 11, 2019
    Posts:
    65
    Thank you. Will this be fixed for Unity 6 preview? It is currently breaking Crest.
     
  34. adrien-de-tocqueville

    adrien-de-tocqueville

    Unity Technologies

    Joined:
    Mar 16, 2020
    Posts:
    270
    Last edited: Mar 27, 2024
    D1234567890 and chap-unity like this.
  35. Kabinet13

    Kabinet13

    Joined:
    Jun 13, 2019
    Posts:
    129
    Is it still there in the latest version? I've never run into something like that.
     
  36. seoyeon222222

    seoyeon222222

    Joined:
    Nov 18, 2020
    Posts:
    187
    I'm sorry. I deleted the post because I thought it would be right to solve the problem by answering it first through related issues traker reply
    I'm experiencing a problem with 22.3.13, and I haven't tested the latest 3.22f1. However, I don't think it makes any difference as I haven't seen any comments in the patch notes

    test provided by "Domantas Bacius" is as follows
    Reproducible with: 2022.3.17f1, 2023.1.0a16
    Not reproducible with: 2023.2.5f1, 2023.3.0b2
    Fixed in: 2023.1.0a17


    Given that it is reproduced in 2023.1.0a16, and fixed in 2023.1.0a17, isn't the problem with it clearly present?
    Anyway, I think it's still a meaningful report with problems in 2022 ver
     
  37. impheris

    impheris

    Joined:
    Dec 30, 2009
    Posts:
    1,667
    i'm late but, that is cool!
     
    chap-unity likes this.
  38. adrien-de-tocqueville

    adrien-de-tocqueville

    Unity Technologies

    Joined:
    Mar 16, 2020
    Posts:
    270
    ah sorry, when talking about volume you meant the volume from the volume system, i thought the underwater volume. But indeed it reproes on 22.3, i'll make a fix for this version
     
    seoyeon222222 and chap-unity like this.
  39. edvart-ros

    edvart-ros

    Joined:
    Aug 15, 2023
    Posts:
    17
    I'm making my own simple water system, just to learn some graphics programming. Is there a reference on how the LOD system works in the HDRP water system? I tried doing a simple distance-based LOD only using tessellation, but it resulted in cracks at the resolution boundaries.
     
  40. adrien-de-tocqueville

    adrien-de-tocqueville

    Unity Technologies

    Joined:
    Mar 16, 2020
    Posts:
    270
    i used a modified version of geometry clipmaps, you can find information about that on internet. It's more or less the same problems as for terrain rendering
     
    hugokostic and edvart-ros like this.
  41. Mirkle

    Mirkle

    Joined:
    May 13, 2022
    Posts:
    8
    I made a post in the HDRP forum, but I am not quite sure if I should ask my question here: All my underwater objects end up looking blue, because of my HDRP ocean refraction settings. I love how it looks underwater, however, I would like to exlude some objects (or object layers) from the underwater effect, to see their full color. Is there a way to do this?
     
  42. adrien-de-tocqueville

    adrien-de-tocqueville

    Unity Technologies

    Joined:
    Mar 16, 2020
    Posts:
    270
    The only way currently is to make it transparent (with opacity = 1 so it's still opaque) and disable the 'receive fog' option
     
    Mirkle likes this.
  43. Mirkle

    Mirkle

    Joined:
    May 13, 2022
    Posts:
    8
    Thank you adrien-de-tocqueville, that worked well! Btw, I love the new HDRP water system, it looks great!