Search Unity

Stylized Water 2 [URP] ☑️ Desktop/Mobile/Consoles/VR

Discussion in 'Assets and Asset Store' started by StaggartCreations, Nov 3, 2020.

  1. frogwise

    frogwise

    Joined:
    Nov 27, 2009
    Posts:
    100
    Hey all,

    Not sure if I have everything working to get reflections enabled. I'm trying to get the hotspot (the sun) in my skybox to reflect off the water. It doesn't seem to be working. I have one reflection probe around the scene as well.

    upload_2021-6-16_15-38-20.png
     
  2. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,627
    I see some reflected color, but it's not very strong. You could increase the strength under the "Reflections" tab and pull down the Curvature Mask value
    upload_2021-6-17_11-24-0.png

    The "Horizon Color" under the Color section lays over the reflection, if you bring down the alpha value of the color to 0, the effect is removed entirely.
     
  3. frogwise

    frogwise

    Joined:
    Nov 27, 2009
    Posts:
    100
    I have tried all these settings, including removing the horizon color. I just can't seem to get mirror-like reflections of the skybox.
     
  4. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,627
    If the strength is turned all the way up, and the curvature mask down to 0.01, the water practically becomes a mirror
    upload_2021-6-18_12-38-28.png

    But if you're only looking to have the skybox reflected, you don't necessarily need a reflection probe (it may not be baked, or touching the water). Instead, you can enabled "Auto generate" in the Lighting window, which will create a global reflection probe that refreshes when the skybox is modified, or the sun changes.
     
  5. frogwise

    frogwise

    Joined:
    Nov 27, 2009
    Posts:
    100
    All of a sudden, I am having trouble building my game. It was working fine, and I'm pretty sure I haven't touched anything with the shaders, yet I am getting this build error (Android)

    upload_2021-6-18_10-28-27.png
     
  6. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,627
    Thanks for the headsup! This seems to be caused by last update, I ran a number of test builds to ensure this wouldn't happen, but alas.

    I've submitted an update that rectifies this, but that likely won't go up until next Monday. In the meantime you can double-click the errors and remove the offending code lines.
     
  7. RoyorGames

    RoyorGames

    Joined:
    Mar 14, 2017
    Posts:
    22
    Hi,
    I have bought this and so far like the look.
    However one thing is puzzling me, how to do a OnTriggerEnter with high waves?
    Adding a MeshCollider on the water, then requires it to be a convex (and then it is planar over the water at the top level of the water). I just wan't to be able to make a few splashing effects and kill the player =(

    I hope I am just missing something =)
    Will you point me in the right direction?

    Best regards Povl
     
  8. frogwise

    frogwise

    Joined:
    Nov 27, 2009
    Posts:
    100
    A

    After commenting out the whole ifdef section (I tried just commenting out the offending two lines but it also didn't work):


    upload_2021-6-21_22-9-7.png


    I now get these compile errors:

    upload_2021-6-21_22-8-37.png
     
  9. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,627
    The wave animations are done in the vertex shader. Since the actual mesh isn't being modified directly, a mesh collider would end still being entirely flat. The only way to read the wave height on the scripting side is through buoyancy API. But Unity physics only works through colliders, which means there's unfortunately no way to piggyback on functions like OnTriggerEnter.

    I've dabbled with this before, trying to recreate the OnTriggerEnter and OnTriggerExit behaviours. For exactly the same purpose! Splashes on the bow of a boat, or rocks at the shore in my case. Right now this works... sometimes. If I can manage to get this working consistently I'll consider adding to the asset.

    The update with the hotfix went up yesterday. If you don't feel like updating, you can comment out the line that reads
    #pragma multi_compile _ UNDERWATER_ENABLED to the same effect. Sorry for the hassle!
     
  10. RoyorGames

    RoyorGames

    Joined:
    Mar 14, 2017
    Posts:
    22
    So the algoritme would be something as
    • Do raycast from somewhere above the base of the mest downwards a few units, to see if there are water near it.
    • If the water is near, get the height from the Bouancy Api.
    • Compare the base height to the wave and 'trigger' if the wave height is highest.
    What problems did you encounter? and I guess all wave water asset will have a similar problem, or am I mistaken? Just for my understanding =)
     
  11. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,627
    Exactly that! The problem is that it doesn't work consistently, some times the trigger doesn't fire when the object enters or leaves the water. I'm assuming since this is trying to do physics, without actually using the physics engine.
     
  12. Caetleo

    Caetleo

    Joined:
    Mar 19, 2019
    Posts:
    5
    I'm having trouble with getting particles system or billboards to appear over the water, Do you guys have a discord?
     
  13. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,627
  14. Bwacky

    Bwacky

    Joined:
    Nov 2, 2016
    Posts:
    31
    Hi Staggart, any new progress on the underwater effect or can I just buy the unfinished work-in-progress somewhere already? :D Using the post processing stack volumes as a replacement but I can't look at it anymore.
     
  15. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,627
    Appreciate the interest! Coincidentally working on it right now, everything is functional, so I'm down to window dressing in terms of a demo scene, trailer video and screenshots. So I expect it to go up some time next month.

    The documentation can already be previewed here, to give you an idea https://staggart.xyz/unity/stylized-water-2/sw2-underwater-rendering-docs/
     
    Bwacky likes this.
  16. Bwacky

    Bwacky

    Joined:
    Nov 2, 2016
    Posts:
    31
    If it were possible I'd smooch you through the screen man, amazing job. I used Crest for my oceans and SW for rivers/lakes, but with this I might as well just swap to SW2 for all my needs. Absolutely beautiful.

    While I have the chance I'll also ask - have you considered ever making a stylized shader for HDRP? Stylized HDRP games are something I was interested in for a while and I wonder if making a water asset like SW2 would be possible for HDRP, if only for the water surface visuals.
     
  17. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,627
    Thanks, appreciate it!

    HDRP is far too complex to write shaders for unfortunately, it would be a nightmare keep in a working state too. Would be possible using Shader Graph, but things can get slow and messy real fast for something as complex as water. HDRP isn't really on my radar, extending URP is a lot more interesting to me :)
     
  18. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    For some reason, I cannot get the post effects on my minimap camera to stop getting fog from the main camera. Whenever I see the stylized water in the view of my minimap camera all i see is the fog color. but the minimap cam is using a separate forward renderer! i think URP is just broken.
     
  19. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,627
    This is technically still correct, so nothing exploded! The water renders the fog on its own, so if the render feature isn't active for a specific camera the fog is applied using the last known settings (from the other camera). What I can do is implement an override, that can simply hide the fog when set. This would work with any third party fog effect in the end and could be toggled on or off for a specific camera with a simple script.
     
  20. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,627
    Took another stab at it, and managed to get tessellation working. It dynamically subdivides the triangles based on camera proximity. In turn, this allows for higher detailed waves without needing a super high-poly mesh.

    Will be added in v1.1.2 as a preview feature. Since it needs some further battle-testing. Not every device/GPU will support this, only GPU's supporting Shader Model 4.6 (after 2018), should it fail, it will fall back to the non-tessellation shader.



    The Underwater Rendering extension is under review, but review times are currently drastically long, so may be over a month before it's released.

    SWS2_Underwater_Screenshot_2048x11522.png
     
    AlphaLulz, Mister-D, Padilha and 2 others like this.
  21. RoyorGames

    RoyorGames

    Joined:
    Mar 14, 2017
    Posts:
    22
    Hi again,

    First off, the tessellation feature looks awesome!

    I have now made a few things that work acceptable for keeping a particle system level with the waves (narrow situations). You probably have something similar, but in case somebody else needs it:

    Code (CSharp):
    1. public class WaterLeveler : MonoBehaviour
    2. {
    3.     public LayerMask WaterMask;
    4.     public Transform TransformToUse;
    5.     public GameObject EffectToMove;
    6.  
    7.     public bool HideWhenWaterNotHit = true;
    8.     public float searchDistance = 4;
    9.    
    10.     void Update()
    11.     {
    12.         if (Physics.Raycast(new Ray(TransformToUse.position + 0.5f * searchDistance * TransformToUse.up, -TransformToUse.up), out RaycastHit hitInfo, searchDistance, WaterMask))
    13.         {          
    14.             EffectToMove.SetActive(true);
    15.             var waterObject = hitInfo.transform.GetComponent<WaterObject>();
    16.             var wavePos = - Buoyancy.SampleWaves(hitInfo.point, waterObject, 0, false, out Vector3 normal);
    17.            
    18.             EffectToMove.transform.position = hitInfo.point + wavePos * normal;  
    19.         }
    20.         else
    21.         {
    22.             if (HideWhenWaterNotHit)  
    23.                 EffectToMove.SetActive(false);
    24.         }
    25.     }
    26. }
    27.  
    upload_2021-7-16_21-31-31.png
    The I started setting up the integration with Dynamic Water Physics 2. It didn't work quite as expected, it works better when I changed the sign in StylizedWaterDateprovider.cs at line 74.
    So I added this minus sign:
    upload_2021-7-16_21-20-31.png

    Finally, I like the way the ripples are looking and actually tried doing a foam after the ship based on it. But it either looks way flooded with circles or to thin and random. I tried to copy paste/hack and saw the texture and normal map for it, without great success. Can you point to a tutorial, where that specific technique is used? or maybe include it in a future update *fingers crossed*.

    Best regards Povl
     
    StaggartCreations likes this.
  22. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    new features look cool! I think this might be impossible but i will ask just in case... is there a way to reduce tranparency as the depth gets higher? here's my issue, the transparency looks great on the shore where you can see underneath a few feet. but this becomes a problem in the deeper areas of the ocean when using fog because the distance underwater shapes are very clearly defined. it would be nice if very far away or very deep water would be opaque. or if the water could be completely opaque that could work for me to.

    Attache screen shows the underwater terrain geometry showing through the water.
     

    Attached Files:

    Last edited: Jul 17, 2021
  23. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,683
    is there a way to set a layermask for the water to exlude to render?
     

    Attached Files:

  24. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,627
    I haven't had much success making a boat wake effect myself. Depending on the style you're going for, modifying one of the waterfall effects may be a better option.

    Based on the screenshot, it doesn't appear like fog is rendering correctly, since it's rendering through the water itself. Depending on which fog effect you're using, it should render before transparent materials are. Which one are you using? It's required to be supported, so the fog can be applied directly in the water.

    Received your email ;)

    If you're rendering objects using the Render Objects render feature, it needs to render after opaque materials are. On the render feature the event should "After Rendering Opaques". So that by the time the water renders, these objects are already included in the camera's depth and opaque textures. The water in turn uses this to check if something is above the water, and tries to exclude it from refraction (requires some extra calculations, so only when the Advanced shading mode is enabled).

    You can clearly tell the difference between rendering after opaque geometry, and before transparents:
    upload_2021-7-19_11-26-50.png

    If objects render after the water/transparent materials are, the shader won't receive any information about them, so won't be able to do any filtering for them.
     
  25. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,683
    could u provide a screenshot with the correct renderobject settings. my weapons need to be set to render before rendering opaques, otherwise they dont render correctly(culling and shadows). setting them to renderafteropaques doesnt make the water exclude the weapons for refraction. tnx. or maybe i misunderstood something ;)
     
  26. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,627
    Sure! This is what I've set up:
    upload_2021-7-19_14-31-46.png

    Any events between After Rendering Opaques and After Rendering Transparents will have the weapon also be refracted.

    In the Frame Debugger the objects should be rendered before transparent objects are, since that's when the water is rendered:
    upload_2021-7-19_14-32-35.png

    Though this set up won't avoid the weapon from clipping through other opaque geometry. I think there will in any case be a set up that works better for one thing, but has a drawback for another.
     
  27. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,683
    no that doesnt work,
    weapons still get refracted and i also loose the ability to avoid weapon clipping wich is why i use the render objects in the first place.
    any chance of having the ability in your setup to set the ability to exlude certain objects(layermask)?
    other than that, its the best water solution ive bought for urp, and ive tested quite a few.
     
  28. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    Im actually using your SCPE screenspace fog. With the water configured to use it. I also just updated SCPE to the latest version.

    Yeah looks like the fog is drawing after transparents from some reason: (see screen attached)
     

    Attached Files:

    Last edited: Jul 19, 2021
  29. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    Whoops nevermind, I just checked the skip transparents option in the feature. Thanks anyway!
     
    Last edited: Jul 20, 2021
  30. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,627
    I don't think it can be worked around entirely unfortunately, without making a compromise on something, given how rendering works in Unity.

    The water uses the depth and opaque texture rendered by the camera, so anything rendered into those textures gets used by the water as well. Hence it wouldn't be possible to use a culling mask for something like refraction or the intersection foam effect, since culling specific layers makes them simply not render at all.
     
  31. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,683
    too bad, wasted money then.
     
  32. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,627
    Well to be frank, you'd run into the same obstacle with any transparent shader that uses refraction, it's an inherent limitation of realtime 3D rendering.
     
  33. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,683
    i didnt want to be rude. im just trying to find a good solution. i really need the weapons to not be culled by geometry and receive shadows. there must be a way to do it, i just dont have much understanding of rendering, im just an artist ;)
     
  34. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,627
    Submitted v1.1.2

    This version includes some changes required for the Underwater Rendering extension, this was approved yesterday, so I'll be able to submit an updated version. I expect it to go live next week!

    Added:
    - Tessellation support (preview feature). Can be enabled under the "Advanced" tab.
    - Added menu item to auto-setup Planar Reflections or create a Water Grid
    - Hard-coded file paths for third-party fog libraries are now automatically rewritten
    - Fog can now be globally disabled for the water through script (see "Third party integrations" section in docs)
    - Support for reflection probe blending and box projection. Requires 2021.2.0b1+, will break in an alpha version
    - (Pre-emptive) Support for rendering debug window in 2021.2.0b1

    Changed:
    - Menu item "Help/Stylized Water 2" moved to "Window/Stylized Water 2/Hub"
    - Improved refraction, this now takes the surface curvature into account. Maximum allowed strength increased to x3

    Fixed:
    - Fog integration for SC Post Effects and Atmospheric Height Fog (v2.0.0+)
     
    kennyb and Acissathar like this.
  35. ununion

    ununion

    Joined:
    Dec 2, 2018
    Posts:
    155
    Hey bro,
    bug report here
    when i using my own create mesh as water the refraction and reflection also return incorrect effect like pic i posted.
    but if i m using a single quad/plane everything looks fine.
    upload_2021-7-26_13-27-4.png
    own created mesh

    upload_2021-7-26_13-28-47.png
    quad/plane
     
  36. ununion

    ununion

    Joined:
    Dec 2, 2018
    Posts:
    155
    upload_2021-7-26_13-30-16.png
    quad/plane mesh

    upload_2021-7-26_13-30-49.png
    code generated mesh/
     
  37. ununion

    ununion

    Joined:
    Dec 2, 2018
    Posts:
    155
    solution here if someone hit this problem.
    notice that tangent of vert should be v4 not v3,so if new v4.up=(0,0,1,1) but v3.up convert to v4 is (0,0,1,0) then....
     
  38. kennyb

    kennyb

    Joined:
    Feb 23, 2015
    Posts:
    14
    Hello,

    I'm having an issue with configuring the shader, using version 1.1.2, this is mostly the same as the one from the demo (I can post the material itself if needed) but I can't find a setting that disables an effect that I don't want.

    When the camera is rotated roughly around 0 or 180 degrees, I see what I want the water to look like


    But when it's rotated roughly +/-90 degrees, everything gets really bright and desaturated and the water just looks like a solid colour. I don't want this to happen, or I want it to happen at much, much lower strength.


    I've gone through all of the material settings and disabled them or adjusted their values to see if it is causing this behaviour, but I haven't managed to find it. Any tips?
     
  39. JonathanBartel

    JonathanBartel

    Joined:
    Jun 24, 2019
    Posts:
    23
    I'm having a terrible time with these shaders. I got your shaders working and they looked beautiful. They're absolutely perfect for what I'm trying to accomplish. I decided to do some reorganizing and moved the shader to a new folder and all of a sudden the material reflected light way more strongly and was completely blown out. If I reduced the light intensity to near zero, the shader for the water looked good but everything else in the scene was basically unlit. I thought maybe it lost the link to the libraries or something so I moved it back to its original folder. This had no effect. I tried deleting the assets and re-importing them. No effect. Then you released the update this past week, so deleted the assets from my project and I tried downloading that fresh, but now I get errors on the script, like "failed to open source file: 'Libraries/Pipeline.hlsl'" Basically all of the files in the Libraries folder are there but can't be read. The shader now renders pink. It was the best water shader I've seen for my project and I somehow broke everything when I moved the shader to a different folder and I can't fix it. Any thoughts?
     
  40. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,627
    It could be the horizon color or translucency shading you're seeing (though in the extreme it seems), these are dependent on the viewing angle. You could also trying putting the material on a default Plane object, the mesh used requires to have normals, if you're using a custom mesh you'd have to ensure this is the case.

    You can generally move the shader anywhere, but only when moving the entire "Shaders" folder, since shaders use relative file paths to look for other dependencies. Moving just the shader file may appear to work at first, until the shader is modified or reimported.

    Unity does some form of shader caching, which can be misleading, usually "failed to open source file" errors (even though it's really there) require to give a shader a kick. You can right-click on the Shader folder and choose "Re-import". This'll force everything to recompile. If all else fails, you can close Unity and delete the Library/ShaderCache folder
     
  41. kennyb

    kennyb

    Joined:
    Feb 23, 2015
    Posts:
    14
    Thanks for the reply!

    I am in fact using the default Plane mesh, however I was scaling it up to 1024 on the X and Z axes. Reducing this to 256 reduces the effect to something a lot nicer-looking.

    I haven't got waves enabled but it just occurred to me I'll probably want to use multiple planes anyways if I want to turn that on! Thanks for the help, I personally wouldn't consider this a bug, what I was doing was really strange from a shader's standpoint.
     
  42. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,627
    Ah, that's certainly a possible explanation. A few effects rely on the mesh's vertex normals, so if they're very wide apart, it's not possible to accurately determine what's in between them. Trying this now, I can reproduce what you described. Using the URP Lit shader has the same effect, turns out it's fog that's giving off the color, which is applied on a per vertex basis.

    If you need a denser vertex count, you can try out the Water Grid component
     
  43. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,683
    could u use the depth texture to check if a pixel would be under the water surface and only distort(refract) the ones that are? to prevent fps objects from refracting.
     
  44. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,627
    This is how that currently works, but it requires objects to be filtered to be in the depth texture, before transparent materials are rendered (eg. water). If you're rendering a specific layer using a Render Objects feature, it'll only render into the screen's color (which is refracted). Adding another feature with only the "DepthOnly" LightMode tag ensures this layer is also rendered into the depth texture.
     
  45. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,683
    im no shader expert .
    so there must be a render objects setting to fix it.
     
  46. WizardingStudios

    WizardingStudios

    Joined:
    Mar 4, 2017
    Posts:
    13
    Hi, I really love to buy and I'm searching this type of shader:

    Need about same type of waves (height, direction etc. etc).
    As I can see you have a similar shader/effect, how similar it should be?
    Second ^^ you are talking about api to buoyance... But no videos about that (less the fantastic boat), then my questions:
    Will meshes (like boats) be able to make the same buoyance as the youtube I posted?
    Will the objects (boats) continue to receive wave heights also if moved from the first position?
    Many thanks for your support.
     
    Last edited: Aug 4, 2021
  47. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,627
    The water uses the same wave technique (gerstner waves). The StylizedWater2.Buoyancy.SampleWaves allows you to get the wave height and normal at any given position, much like a raycast. Similar to how that scripts uses the "GetWaveHeight" function. But what you with the information would be up to you.

    Note that the asset contains only this function, which is necessary for a buoyancy system to work. But it doesn't include an actual buoyancy system, since this is an entirely different focus. Instead, there's an integration for the Dynamic Water Physics 2 asset, which uses the same function as a starting point.
     
  48. WizardingStudios

    WizardingStudios

    Joined:
    Mar 4, 2017
    Posts:
    13
    Many thanks for the reply. As I understand I should use your gerstener waves as shader like my youtube video example (waves height, speed, direction... and so on) and apply to a object the script provided by WP2 (changing the data provider) and it will works? Many thanks for your patience.
     
  49. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,627
    That's correct, the data provider component will act as a bridge, allowing DPW2 to read the wave height.

    From the docs:
    • Set up the scene as per quick start guide for flat water, minus FlatWaterDataProvider.
    • Go to Window → Stylized Water 2 → Hub, and click the “Install integration” button. Wait until scripts have finished compiling.
    • Add StylizedWaterDataProvider to the object containing OceanRenderer script.
    • You will have to assign the water material you are using in the scene, since this script requires to know what kind of parameters are used for the waves.
     
  50. WizardingStudios

    WizardingStudios

    Joined:
    Mar 4, 2017
    Posts:
    13
    Many thanks for that fast reply. Please last question, are you planning to release v3 of that script? If yes, when? Just to know for how many time you will support this one (v2).
     
unityunity