Search Unity

Official Water System for the High Definition Render Pipeline

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

  1. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,300
    The shore water deformers seem to be dedicated objects. Multiple ones. Even for the small island example scene there are 3 needed. Here's 1 of them:

    swd.jpg

    Either an automatic placement or another solution would be preferred for a big island. Nobody wants to create and place that by hand.

    Shore foam works fine, but it looks like plastic:

    foam.jpg

    Where can I change that? And is it possible to give it more deformation? Currently it looks like a line.

    All in all very impressive what you provide :)
     
    Ruchir likes this.
  2. adrien-de-tocqueville

    adrien-de-tocqueville

    Unity Technologies

    Joined:
    Mar 16, 2020
    Posts:
    270
    This is not an easy scenario :D
    First since you have vertical overlap on your two surfaces, you would need to actually have two water surfaces (one for the large surface above, and a smaller one for the pool inside) but that's the easy part
    For rendering underwater absoprtion through the window, there's currently no way tough. We could maybe reuse the water excluders to mark in the stencil which pixels cannot receive underwater, so you would mark all your walls except the window as excluders.
     
    chap-unity likes this.
  3. adrien-de-tocqueville

    adrien-de-tocqueville

    Unity Technologies

    Joined:
    Mar 16, 2020
    Posts:
    270
    You can change the smoothness of the foam, maybe that will help with the plastic look.
    To deform the line, you can tweak the shadergraph (i assume you are using the one from the sample) to add some noise on the depth threshold to make it a bit more random

    Finally automatic placement of shore waves deformers would require a sdf of the terrain to be done properly but it's not for now
     
  4. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Hence why i'm asking :D
     
  5. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,300
    Thanks, was just some unexposed settings. I'd prefer if you'd expose as many as possible :)

    Before with the hard line towards the ocean:

    bef.jpg

    After the tweaking:

    after.jpg
     
  6. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    To piggyback on this, this is indeed theoretically possible, the one brick we're missing is supporting excluder underwater as @adrien-de-tocqueville said.
    It's not out of the question that we add this brick soon if it's simple enough.
    Cheers !
     
    Gooren, Ruchir, Rowlan and 1 other person like this.
  7. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Say, can we get repetition/tilling size parameter for the ripples? for me the current ripples looks to large , also for the Swell wave can we get parameter smaller than 250? i know that the current setup are locked for physical based setup, but at least let us choose though.
    Also still waiting for unlocked IOR Settings
     
  8. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    Hey, it's not completely out of the question but can you expand a little bit on the use case so that we fully understand why you want to go lower on those values ?

    About that, we added the possibility to disable refraction underwater, would that fit your goal ?

    upload_2023-4-20_15-40-1.png
     
  9. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Purely aesthetic mostly, as you can see that the wave lacking of small waves detail (microwaves?). Basically i would like to get more smaller ripples details on the water.
    upload_2023-4-20_23-24-39.png
    and that make me wondering can we fetch the ripple normal maps data on shadergraph? that way we can blend additional smaller ripples?
    For the underwater refraction even without ScreenSpaceRefraction i'm still getting windowing effect, i would like to remove that completely to be honest.
    upload_2023-4-20_23-28-45.png
     
    Wattosan, meanmonkey and bdb400 like this.
  10. meanmonkey

    meanmonkey

    Joined:
    Nov 13, 2014
    Posts:
    148
    @chap-unity Sorry to bug you again but I really would like to see an option to provide an UV offset to your water shader (so floating point origin technique won't be obvious). Any chance we'll see that in the future ? Thank you
     
    Last edited: Apr 21, 2023
    bdb400 likes this.
  11. adrien-de-tocqueville

    adrien-de-tocqueville

    Unity Technologies

    Joined:
    Mar 16, 2020
    Posts:
    270
    You can combine the water normal with a custom normal map in the shadergraph if you want, i think that's a better solution for very small ripples.

    Regarding what you call windowing effect, it was left on purpose, it's called total internal reflection, but yeah having a flat color is not great either
     
    chap-unity and Reanimate_L like this.
  12. adrien-de-tocqueville

    adrien-de-tocqueville

    Unity Technologies

    Joined:
    Mar 16, 2020
    Posts:
    270
    You can add an offset here, does that fit your need ? upload_2023-4-24_11-56-35.png
     
    meanmonkey and Reanimate_L like this.
  13. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    I'm looking to achieve this kind of under the water refraction looks
     

    Attached Files:

  14. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    We could technically when you uncheck "Screen Space Refraction" also disable total internal reflection to allow gameplay interactions like this even though it's not physically correct.
    Thanks for the feedback, it's noted on our side and we'll keep you posted if it ends up being implemented.
     
    Gooren, Reanimate_L and Ruchir like this.
  15. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    upload_2023-4-24_23-27-13.png
    blending custom normal map work great, Thanks for the idea.
    still waiting for the clean underwater refraction :D
     
  16. Kreshi

    Kreshi

    Joined:
    Jan 12, 2015
    Posts:
    446
    SSR artefacts look like there is something broken. I don't know if this is a bug with SSR or an issue with the water system (I experience the same SSR artefacts in the latest 2023 beta version [2023.1.0b13])
     
  17. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Which artefacts?
     
  18. Kreshi

    Kreshi

    Joined:
    Jan 12, 2015
    Posts:
    446
    The aliasing artefacts on the water reflections :D.
     
    Last edited: Apr 24, 2023
  19. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    That's because i disable AA in my scene view
     
    CaseyHofland likes this.
  20. meanmonkey

    meanmonkey

    Joined:
    Nov 13, 2014
    Posts:
    148
    Thank you for your answer! I can achieve the desired result (= countering the origin reset movement) with the solution as shown below in my screenshot. However, after just a few units of movement the boundaries (water meshes disappear with camera movement) and the LOD system (water becomes very simple) seem to get messed up. Other than that it would be perfect.

    I don't know what's happening under the hood but I guess it's out of reach for me ? Maybe I would need to apply the offset to the camera distance too somehow ?

     
  21. adrien-de-tocqueville

    adrien-de-tocqueville

    Unity Technologies

    Joined:
    Mar 16, 2020
    Posts:
    270
    Ah right, we perform frustum culling on CPU, so if you move the surface in the shader we can't be aware of it on CPU.
    I would need to have a bit more info on your use case. Are you using an infinite ocean ? and what you want to do is shift all objects when camera if far from origin to avoid floating point precision issues ?
     
  22. meanmonkey

    meanmonkey

    Joined:
    Nov 13, 2014
    Posts:
    148
    Yes I am using the infinte ocean. Using the quad mesh at least eliminates the frustrum culling problem, but the degraded LOD is still present when applying the offset.

    I am going with the floating origin approach because my procedural generated worlds are quite big (around 512x512 km). After passing a certain movement threshold, the avatar/camera is reset to zero and the whole world is moved along with it.

    Of course that reset is a movement at the end and environment shaders like terrain, water, grass etc, which depend their rendering on their position/uv/heightmaps etc, have to counter that movement with an offset, else it would be obvious.

    Here are a few screenshots:

    Everything is ok at the beginning, no movement yet. The offset itself works fine when moving. (EDIT: Sorry but for what ever reason it won't show the first pic)

    After a few units of movement, culling problems occur when using the offset

    The further I go, the more the LOD gets degraded (at least I think it's the LOD)

    I'd prefer using the infinte ocean mesh, but as I mentioned above, I could solve the culling problem with the quad mesh. The LOD (or what ever the problem is) is still an issue for me though. The caustics are fine in any case.

    Thanks a lot!
     
    Last edited: Apr 25, 2023
  23. Onigiri

    Onigiri

    Joined:
    Aug 10, 2014
    Posts:
    486

    is it possible to make this effect with unity water and raytracing? Tried recursive rendering without any luck
    upload_2023-4-28_14-58-18.png
     
  24. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    If by this effect you mean having raytraced reflection above and below the water surface, yes, you just need to add a Screen Space Reflection, enable raytracing there and make sure SSR on transparent is checked there, on the HDRP asset and on the Global Frame settings.

    Recursive Rendering is not compatible with water and is clearly not meant to render such a large refractive transparent anyway :)
     

    Attached Files:

  25. Onigiri

    Onigiri

    Joined:
    Aug 10, 2014
    Posts:
    486
    No, i meant how objects distorted below water surface and looks almost flat. I thought enabling Recursive Rendering will add physical raytraced refraction to the water to make such effect possible. The built-in underwater screen space refraction working only when camera below water plane. Volume system's screen space refraction doesn't do anything to the water.
    upload_2023-4-28_16-19-20.png
     
  26. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    613
    Is that physically correct?! I have been in a lot of water and while object get distorted… maybe it’s because it’s in a game but it feels really weird. Generally you can still tell depth relatively accurate, but this one trips me up, when you dive the water turns much much deeper than what I would expect
     
  27. Onigiri

    Onigiri

    Joined:
    Aug 10, 2014
    Posts:
    486
    Maybe IOR value in video is a bit bigger than real water IOR not sure, but it's roughly how it's should behave.
    upload_2023-4-29_2-1-18.png
     
  28. impheris

    impheris

    Joined:
    Dec 30, 2009
    Posts:
    1,670
    yes it is, although it looks a bit exaggerated on that video (i guess to make it more obvious) and i do not think that effect would be relevant on a game like half life 2
     
  29. kripto289

    kripto289

    Joined:
    Feb 21, 2013
    Posts:
    505
    Yes :)
     
  30. Onigiri

    Onigiri

    Joined:
    Aug 10, 2014
    Posts:
    486
    Why changing water smoothness doesn't change reflection? It's should be more blurry on surfaces with low smoothness. Example water with 0-1 smoothness range
    upload_2023-4-30_12-42-27.png
    And water with 0-0.5 smoothness
    upload_2023-4-30_12-45-12.png
    Notice how reflections looks exactly the same, the surface just more darker.
    Edit: I think raymarched reflections works as they should be. Its just raytraced reflection doesn't change
     
    Last edited: Apr 30, 2023
  31. Onigiri

    Onigiri

    Joined:
    Aug 10, 2014
    Posts:
    486
    Bug: while in playmode raymarched reflections stops working after switching from game view to scene view and back. 2023.2a12
     
  32. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Another question about the current water system,
    • For the Mask System, for current and waves.
      in the glacier river system one map handle the entire scene, what's the workflow to handle big scene?
      because high chance one map wouldn't be enough
    • How to handle/blend water body with different colors?
      let's say a river blending to a swamp which also connected to a clear water lake or ocean? the last part would also blend the current direction. And the same scenario as above let's say it's a big scene
     
  33. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    Thanks for clarifying, I see what you mean now.
    The problem is always the same with refraction in screen space, if we change the viewDirection when entering the waterSurface we may have missing informations (artifacts) so we have to fallback on something (same issue with the refraction when underwater). So by default, there's no ray deviation due to IOR when the camera is above the water surface, only distortion depending on the agition / ripples.
    We also have the same kind of issue with classic refraction models.

    We'll still take that in mind as a feedback and see what's possible but can't promise anything on that matter.

    EDIT: sorry, just realized in your original video the refraction is pathtraced / raytraced compared to the original HL2 water (which doesn't have IOR refraction, only distortion), so of course they don't have artifacts from screen space refraction.
    Support from this in raytracing is not on the roadmap indeed.
     
    Last edited: May 4, 2023
    Onigiri likes this.
  34. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    Reducing water smoothness will make reflections coming from the Skybox more blurry by using the higher mips of the skybox. (So when you are using clouds, HDRI Sky or PBR Sky for exemple).

    For geometry on screen, SSR on transparent default to the approximation algorithm which do not "blur" reflections.
    It's the same if you have an opaque plane. (see limitations in documentation)
    The only way to have a rough reflections with SSR is to use PBR Accumulation algorithm but this one is not available for SSR on transparents and Water Surface is considered a transparent.
    Even Ray Traced reflections on transparents behave the same way.
     
    Onigiri likes this.
  35. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    For now, there's no specific workflow for it. One thing that comes to mind is depending on where you camera is, you can swap / blend maps to mask relevent part of your surface.

    This is tracked on our side but hasn't been taken care of yet since there's no simple solution to do it right now.
     
    hugokostic likes this.
  36. adrien-de-tocqueville

    adrien-de-tocqueville

    Unity Technologies

    Joined:
    Mar 16, 2020
    Posts:
    270
    I've modified the procedural geometry (instanced quads and ocean) to now take the world position of the water gameobject into account, so you should be able to simply move it like any other object.
    Additionally i cleaned up a bit the shadergraph code so all nodes for position should work now (like using the node for object space position, or accessing the transform matrices)
     
  37. yinyuLEO

    yinyuLEO

    Joined:
    May 6, 2023
    Posts:
    3


    Transparent objects in new water surface seem to get a BUG.
    Does anyone have a good solution to this problem? Thank you~
    Editor version :2022.2.15f1c1
     
  38. Kreshi

    Kreshi

    Joined:
    Jan 12, 2015
    Posts:
    446
    upload_2023-5-7_20-52-37.png

    Waterline is broken and is applied if I am over water. Judging by my debugging, the issue is probably inside "IsUnderWater" HD Sample Buffer.
     
    chap-unity likes this.
  39. meanmonkey

    meanmonkey

    Joined:
    Nov 13, 2014
    Posts:
    148
    That's great news, thank you a lot!
     
  40. adrien-de-tocqueville

    adrien-de-tocqueville

    Unity Technologies

    Joined:
    Mar 16, 2020
    Posts:
    270
    This is currently expected, we're working on providing a solution to make it work for 23.2 but this will come with a performance cost
     
    chap-unity likes this.
  41. Kreshi

    Kreshi

    Joined:
    Jan 12, 2015
    Posts:
    446
    The buggy waterline i was talking about is the blured line at the bottom just in case it was not clear :D.
     
  42. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    Thanks, it was clear indeed :p.
    We've talked with @adrien-de-tocqueville about this and this is a complicated problem, and here's multiple ways we can "sort of solve it" but first, some context about the current issue:

    When the waterline is like this, left is underwater and right is over, you don't want to have full black on the right because otherwise you get a very hard vertical line on the blur so it's not ideal either, this is why we still have that white one pixel height line, which when blurred translates to the blur on the bottom you are seeing.
    upload_2023-5-9_15-57-56.png

    Now, Underwater/Waterline effect is evaluted when the camera is between -Y and +Y of the water surface where
    Code (CSharp):
    1. Y = waterSurfacePosition.y + totalAmplitude + volumeHeight (inside Underwater section)
    So if the camera is outside this range, the buffer will be completely white or black (below or above water surface), and you will see the blur line "pop" in or out. (which is not ideal either)

    The first and easy solution if you don't want the blur to appear when above, is to reduce this Y by reducing the volumeHeight. (this volumeHeight is there for underwater to work correctly if you have deformers).

    One other solution would activate Script Interactions on your water surface and to modulate the opacity of the customPass effect depending on the camera distance to the water surface, this would mostly work and would cost a little since script interactions is not cheap.

    Last solution would require to output the elevation (in meters) in addition to the distance in screen space, in the HDSampleBuffer node on our side and modulate the opacity of the customPass effect depending on this value without having to replicate the simulation on the CPU (which is a win perf wise). We can evaluate the implications of that but it's not out of the question.

    Lastly, this doesn't solve the case where the camera is just above the water surface but looking at the sky, but this can be solved by using a dot product between viewDir and up vector (assuming water is a plane) and modulating the customPass effect depending on this as well, this can be added to the sample later.
     
    Kreshi likes this.
  43. Kreshi

    Kreshi

    Joined:
    Jan 12, 2015
    Posts:
    446
    My workaround at the moment is as follows:

    1) I wrote a WaterlineTransition.cs script and attached it to the CustomPassVolume used for drawing the Waterline (I basically attached it to the Waterline GameObject) and assigned the Target Surface and Water Material
    2) I added a Blend factor to the Waterline_FullScreenCustomPass shadergraph

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Rendering.HighDefinition;
    3.  
    4. public class WaterlineTransition : MonoBehaviour
    5. {
    6.     [SerializeField] WaterSurface m_targetSurface = null;
    7.     [SerializeField] Material m_waterMaterial = null;
    8.     [SerializeField] float m_relativeUpVecOffsetLengthForBlending = -0.2f;
    9.  
    10.     // Internal search params
    11.     WaterSearchParameters m_searchParameters = new WaterSearchParameters();
    12.     WaterSearchResult m_searchResult = new WaterSearchResult();
    13.  
    14.     CustomPassVolume m_customPassVolume;
    15.     Transform m_cameraTransform;
    16.  
    17.     void OnEnable()
    18.     {
    19.         m_customPassVolume = this.GetComponent<CustomPassVolume>();
    20.         m_cameraTransform = m_customPassVolume.targetCamera.transform;
    21.     }
    22.  
    23.     // Start is called before the first frame update
    24.     void Start()
    25.     {
    26.        
    27.     }
    28.  
    29.     // Update is called once per frame
    30.     void Update()
    31.     {
    32.         if (m_targetSurface == null) return;
    33.        
    34.         // Build the search parameters
    35.         m_searchParameters.startPositionWS = m_searchResult.candidateLocationWS;
    36.         m_searchParameters.targetPositionWS = m_cameraTransform.position;
    37.         m_searchParameters.error = 0.01f;
    38.         m_searchParameters.maxIterations = 8;
    39.  
    40.         // Do the search
    41.         if (m_targetSurface.ProjectPointOnWaterSurface(m_searchParameters, out m_searchResult))
    42.         {
    43.             float compareY = m_cameraTransform.position.y + m_relativeUpVecOffsetLengthForBlending;
    44.  
    45.             if (compareY < m_searchResult.projectedPositionWS.y)
    46.             {
    47.                 float blend = Mathf.Min((m_searchResult.projectedPositionWS.y - compareY) / Mathf.Abs(m_relativeUpVecOffsetLengthForBlending * 0.5f), 1);
    48.                 m_waterMaterial.SetFloat("_Blend", blend);
    49.                 m_customPassVolume.enabled = true;
    50.             }
    51.             else
    52.             {
    53.                 m_customPassVolume.enabled = false;
    54.             }
    55.         }
    56.     }
    57. }
    58.  
    upload_2023-5-11_23-34-25.png


    It works and solves the waterline problem for now - however it's a dirty workaround.


    Some more questions:

    1) Wouldn't it make more sense to set the blending through the fade value from CustomPassVolume (right now this parameter has a private set therefore can't be assigned) instead of adding a custom Blend parameter to the shader graph? Would this even work as expected?

    2) Accessing the material through the WaterSurface directly was not possible (using customMaterial parameter didnt work for me)

    3) The script doesn't work for multiple waters, for example when having 1 infinite and 1 quad water on different waterlevels, it is not going to work. Is there a way to make this work using the current available scripts without the need of using custom trigger-colliders to correctly switch between water surfaces?

    4) Will an option be added in the future with which we can have an optional animated and continued fullscreen distortion effect when the camera is underwater?
     
    chap-unity likes this.
  44. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    Smart thinking, completely forgot about this awesome feature but yes, as long as your effect is localized on your scene, that should work and it should be easier to control the local area and the fade distance.

    If the material you are referring about is the material in the custom pass, it's completely normal, it's not related to the water surface and you'll have to create a script that you stick onto anything and pass the reference of that custom pass material to it ! Sorry if I misunderstood the question (Or use the method you stated on #1)

    That's a complicated setup but underwater/waterline effect works for only one water surface at a time (there's only one buffer anyway), so your best bet would to check if you are within the bounds of finite water surface with a collider and a higher priority, no better way to do it currently.

    Not sure what you are asking here, but you can already do it yourself with the custom pass and the "isUnderwater" node, just have to fiddle with the graph and activate some distortion to the scene color depending on if you are underwater or not, like blurring only underwater like this.

    Hope this helps !

    upload_2023-5-15_9-47-36.png
     
    hkalterkait likes this.
  45. impheris

    impheris

    Joined:
    Dec 30, 2009
    Posts:
    1,670
    that is very nice! is there a way to blur underwater but based on distance? (i know nothing about shadergraph sorry if is a dumb question)
     
  46. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    Well, you have access to the depth buffer (Node HDSceneDepth), so you could modulate the LOD of the scene color only underwater depending on "how far" the stuff underwater is.
    Keep in mind that this will only contain the depth of Opaque objects, so this might create some unexpected issue and would work only if you stuff underwater.
     
  47. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    there's a new depth buffer that should fix that if i'm not mistaken
    Edit : https://github.com/alelievr/HDRP-Custom-Passes/tree/master
    ah you need custom pass
     
  48. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,300
    Any ETA when this might be released?
     
  49. Xaron

    Xaron

    Joined:
    Nov 15, 2012
    Posts:
    382
    Just tried the new water with Unity 2022.2.20f1 and the waterline still seems to be a bit buggy? I know I haven't

     
  50. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    By "this", if you mean, the github project with real world assets, the request to make the github repo poublic is still processing so, I want to say "soon", even though that does not help you a lot :)

    The rest of the samples is already out via the HDRP Package Manager
     
    Rowlan likes this.