Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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

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

  1. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,209
    I'm in the process of preparing a demo scene for the upcoming Dynamic Effects extension, as well as drafting the documentation.

    I think the most fun corner of the scene is here:


    Here a generic splash particle effect (WaterSplash_Up.prefab) is paired with a child particle system that uses a Dynamic Effect shader. As a result, the particle effect can also create local displacement and foam.

    (Note that the effect is scaled up x3. It is rather difficult to create super small displacement details, unless the water geometry is very high-poly.

    The crates particle system is configured to use collision detection on the Ocean plane object. Whenever a particle collides with it, the splash effect is played. This is built-in Unity functionality)
     
  2. Bwacky

    Bwacky

    Joined:
    Nov 2, 2016
    Posts:
    192
    Looks incredible!
    Could I perhaps attach it to players who run into the water and simulate a splash effect on the initial surface collision, then play wave effects around them as they remain in the water body with this new system?
     
    StaggartCreations likes this.
  3. kevindaluz

    kevindaluz

    Joined:
    Nov 8, 2014
    Posts:
    7
    Hi. I'm trying to create a basic transparent shader which works identically to Universal Lit and that works with fog and caustics. I was able to follow the documentation to create a shader graph with transparency and working fog (based on Universal-Lit material). However, caustics do not appear on the material, only the manual fog does. Is it possible to make transparency work with caustics? I attached an image of my shader graph below.
     

    Attached Files:

  4. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,209
    The system will handle processing specific particle systems to inject them into the water surface. That means that functionality like triggers and events controlling such objects still rely on generic Unity functionality/scripting.

    The way I've personally handled this is to attach a Box Collider trigger to a water body, and handle such logic on an OnTriggerEnter/OnTriggerStay function in the character controller.

    The underwater caustics are also based on the scene's depth information, which is why they aren't projected onto transparent materials, much like the underwater fog.

    That's not something the "Apply Underwater Fog" function handles. I've made a note to incorporate caustics into this function, it will require some refactoring
     
    Bwacky likes this.
  5. benjamin_flashbulb

    benjamin_flashbulb

    Joined:
    Aug 4, 2020
    Posts:
    25
    Hello.

    Wonderful plugin.

    Any chance of getting some toggle/overrides for fog integration? I'm not using the SC Post Effect Fog resulting in scene (built in) fog not being applied to water.

    Secondly (when using fog) wouldn't it make sense to have the horizon color match the fog color or at least be a toggle ("Use Scene Fog Color")?
    upload_2023-9-5_10-37-32.png
     
  6. benjamin_flashbulb

    benjamin_flashbulb

    Joined:
    Aug 4, 2020
    Posts:
    25
    EDIT: I solved this by moving the SC Post Effect fog renderer to before the Underwater Render Feature in the stack.

    One more thing. If I'm use the SC Post Effect fog, then the underwater fog is not overridden.
    upload_2023-9-5_12-9-52.png

    Using built-in fog the the color is correctly overridden.
    upload_2023-9-5_12-10-24.png
     
    Last edited: Sep 5, 2023
  7. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,209
    Thanks! :D

    The fog integration gets automatically selected in case a third-party fog effect is installed in the project. You can however select the shader file and disable automatic detection, after which you can specify which fog technique to use.
    upload_2023-9-5_15-59-7.png

    When the built-in fog is enabled you'll find that the water will already take on the fog color on the horizon.
     
  8. sacb0y

    sacb0y

    Joined:
    May 9, 2016
    Posts:
    856
    upload_2023-9-7_19-4-56.png

    The water intersection effect seems off. It looks fine from under water but above water the distortion is on top of the non distorted model.

    upload_2023-9-7_19-6-6.png

    It doesn't seem to be my shader either since I tried other objects
    upload_2023-9-7_19-6-31.png
    But again it doesn't occur from under water.
    upload_2023-9-7_19-6-57.png
     
  9. benjamin_flashbulb

    benjamin_flashbulb

    Joined:
    Aug 4, 2020
    Posts:
    25
    This looks very cool. Will it be for the entire water body or just some defined areas? And will it also have the "style" options like the intersection foam?
     
  10. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,209
    Ah yes, while it may looks out of place, this is actually by design. The foam is supposed to be something that sits on the water surface, hence isn't being refracted like underwater objects are. With the foam actually being based on geometry behind/under the water it ends up suggesting otherwise.

    A bit of both! Rendering takes place in an area inside the camera frustum, up to a certain distance, so it is always where it needs to be.

    These effects "paint on" an added intensity for the Surface Foam effect, so the settings used on the water material end up defining the appearance.
     
  11. sacb0y

    sacb0y

    Joined:
    May 9, 2016
    Posts:
    856
    Oh i see, so the issue is the depth isn't correct for the water and scale i'm using?
     
  12. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,209
    Everything is working as it should :) It's just that the effect is based on the non-refracted depth information.
     
  13. leonardo_mixedbag

    leonardo_mixedbag

    Joined:
    Aug 3, 2022
    Posts:
    3
    Hey StaggartCreations,

    we're using Stylized Water 2 in our game and it's awesome! The only problem we're facing is that the Buoyancy API gives back -very- inaccurate results, which kinda of prevents us from making our player character swim realistically.

    As mentioned in other messages in this thread, it seems to be a desynch between the rendered vertices and the actual underlying simulation (which is represented by the result of SampleWaves and is much more accurate if I understood correctly). This problem occurs with your component as well, the FloatingTransform.

    We've really tried everything, but the inaccuracy is too much for us because the character floats in the water in strange way, sometimes swimming well above the water (almost like flying), sometimes almost completely submerged up the head. Do you have any suggestion in this regard, because if we can't link the buoyancy to the player's character controller in a stable and meaningful way we'll have to do without it and come up with a solution to actually have waves in the sea but avoid the character swimming in just a "flat" motion, because that would look bad obviously.

    Thank you very much,
    LF
     
  14. benjamin_flashbulb

    benjamin_flashbulb

    Joined:
    Aug 4, 2020
    Posts:
    25
    Hello again.

    I've switched to using SC Post Effects' fog feature but the planar reflections does not seem to "know" about this?
    upload_2023-9-14_11-29-27.png
     
  15. ZliVuk

    ZliVuk

    Joined:
    Mar 24, 2018
    Posts:
    61
    What is workflow for creating multiple water volumes with underwatereffect in one scene?
     
  16. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,209
    The buoyancy calculations on both the CPU end and how they're performed in the shader should line up 1:1. Though, on the C# side, the calculations effectively have infinite accuracy, whilst on the geometry they're performed (and represented) by a limited number of vertices.

    For example, when using an ocean-like material on a default Plane object, scaled up x1000, it'll appear to just move up and down as a whole. Whilst if you were to sample the wave height in a script, you'd get very accurate wave information back. As a result, it'll appear to not match, but this is to be expected.

    In this case, to get more accuracy, a more accurate mesh must be used. Either using more subdivions/vertices as a whole, or by enabling Tessellation.

    If using a higher vertex count isn't viable, the wave "Count" parameter on the water material should at least be reduced to 1.

    A long shot would be to sample the wave height at 4 points around the player (snapped to the nearest vertices), then use bi-linear interpolation on the result. You'd be replicating the interpolation of the vertex height information.

    Ah, when talking about fog here, the default Unity fog is being referred to. Any render features (third-party fog or otherwise) you'd also want to render into the reflection should be set up on the renderer you're using.

    There's an example outlined in this post, with an example scene attached.
     
  17. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,209
    On another note, the weekend is here, and I'll be away traveling until October 4th. An "out of office" message is set up on the support email, but I figured I'd mention it here as well.

    I'll be be in the area of plenty of natural water, and bringing my recording equipment with to make use of that. I've been slowly building up a library of water sound effects (oneshots and loops), hopefully in a while it'll be ripe enough to offer on the asset store :)
     
    Last edited: Sep 19, 2023
    OregonGhost and Lars-Steenhoff like this.
  18. ZliVuk

    ZliVuk

    Joined:
    Mar 24, 2018
    Posts:
    61
    There is missing Script on
    - StylizedWater_Desktop
    - StylizedWater_Desktop (1)
    ?
    Does that script make a change in Underwater Renderer/Water Level Transform according to trigger? If that is the case, my problem is solved.
     
  19. benjamin_flashbulb

    benjamin_flashbulb

    Joined:
    Aug 4, 2020
    Posts:
    25
    Just FYI "Always Enable" needs to be checked for the SC Post Effects Fog to work in planar reflections:
    upload_2023-9-15_12-10-8.png
     
  20. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,209
    It does! The missing script is most likely the same example script as linked in the documentation here.

    That does make sense! Post processing is disabled on the internal reflection camera, which the fog effect checks for to decided if it should render or not.
     
    ZliVuk likes this.
  21. lloydhussell

    lloydhussell

    Joined:
    Apr 21, 2019
    Posts:
    16
    Hello. I am having an issue where the intersection foam is jumping when the camera has a sudden change in movement, but also the foam moves when I move slightly as well. As shown in the attached video.

    I am using Easy Movement 2 for movements alongside the Stylized Water 2 package.

    Thanks for any help or pointers.



    I also tried to use the polybrush and paint them on, but it gave the same effect.

    I then removed the intersection foam and notice the whole sea plane somehow clips the island.

    More info: I have asked around on Discord as well and people seem to say that the shader is affected by the z depth of the camera. Is there a way I can remove this in the shader without breaking anything? I did look through the shader file for suitable variables or functions that affect the z depth, but couldn't find anything related.
     
    Last edited: Sep 18, 2023
  22. lloydhussell

    lloydhussell

    Joined:
    Apr 21, 2019
    Posts:
    16
    We are probably going to go with a static camera over the scene. But this really shouldn't be happening, should it? I have been trying to figure out how to fix it given the public variables exposed in the components of related objects, but it's not making any difference in this respect. the water shader always breaks through the ground.
     
  23. neocheuf

    neocheuf

    Joined:
    May 23, 2021
    Posts:
    3
    Hi there ^^

    Can we use the assets provided in your demos in our games ? Specially trees and rocks ?
     
  24. Jelmer123

    Jelmer123

    Joined:
    Feb 11, 2019
    Posts:
    241
    Hi, on iOS with stylized water2 + the underwater plugin, after following performance tips from the FAQ, I still encouter poor performance when the water surface from below is in view of the camera. So, when you are underwater and you look up. Do you know what the problem might be here?

    iPhone 12 pro. runs 60 fps, but drops to 10 fps when looking upwards from below..
    settings:
    water settings.png

    edit: ah, it seems that the problem only occurs with caustics on. But again, only if caustics are on AND looking upwards. If looking at the ocean floor (which shows a lot of caustics as well), the game runs smoothly. So caustics and the water mesh are creating some kind of issue..
     
    Last edited: Sep 26, 2023
  25. alexandrmail256

    alexandrmail256

    Joined:
    Sep 13, 2022
    Posts:
    1
    Hello, is there a way to enable water reflections for VR?
    I'm aware that they don't work for VR, but I need to find a solution.
    I haven't bought the asset yet because I'm turned off by the fact that reflections don't work in VR.
     
  26. avivoren

    avivoren

    Joined:
    Sep 21, 2014
    Posts:
    42
  27. kaliyo

    kaliyo

    Joined:
    Dec 8, 2015
    Posts:
    7
    This asset doesn't seem to work with Buto. I tried dozens of settings, but none of them displays buto fog above the water.

    The only solution is to render buto fog after transparency, but the buto dev himself says in his documentation that it is not recommended.


    Screenshot 2023-10-03 074242.png Screenshot 2023-10-03 074254.png
     
  28. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,209
    What you're seeing is indeed depth-related, similar to z-fighting. It is greatly exaggerated when using an orthographic camera because of floating point precision errors. It's unfortunately inherent to how 3D rendering works, but may be mitigated by moving the camera object closer to the world and/or increasing the near clipping plane on the camera.

    Underwater rendering unfortunately isn't support on mobile hardware, solely on account of performance constrains. This is mentioned on the store/compatibility page, I believe you must have unintentionally missed this. A bit more details in this post.

    Reflection probes will still work for reflections in VR, with the exception of Planar Reflections. The reason is both simple and complicated, but boils down to a minor (but important) limitation of Unity's rendering architecture.

    What's most important about reflections is to at least capture the general color of the environment, it doesn't have to be very accurate to look convincing.
    This is quite normal, and relates to how Unity handles transparency rendering. Both the water material, and the material on the cube have the same render queue. So whichever object is closer to the camera gets rendered first, moving the camera around changes this.

    There's more information about this on the troubleshooting page ("Transparent materials (+sprites & particle effects) always appear either below, or in front of water").

    That certainly doesn't seem right. Typically, Buto should indeed render before transparent materials.

    You can select the shader file in the StylizedWater2/Shaders folder and double-check if the Buto integration is indeed active:
    upload_2023-10-4_9-54-16.png
    Or on any water material:
    upload_2023-10-4_9-54-51.png
     
  29. benjamin_flashbulb

    benjamin_flashbulb

    Joined:
    Aug 4, 2020
    Posts:
    25
    Hello again.

    Would it be possible for the Translucency color gradient (in Underwater Rendering) to also draw on skybox/background/far clip? I have a small scene that doesn't extend far and there isn't enough geometry to generate depth beyond a short distance.

    Water surface doesn't extend far and the terrain below dips down (hope it makes sense):
    upload_2023-10-4_12-42-12.png
     
  30. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,209
    With a small code change that would be possible, but it would trade in a dark area for a bright area as the effect can't draw on the void that is the skybox.

    Ideally you would cover up the void with some form of geometry, it being simple boxes or by sloping the terrain up.
     
  31. benjamin_flashbulb

    benjamin_flashbulb

    Joined:
    Aug 4, 2020
    Posts:
    25
    Okay, thanks. That's what I figured ;)
     
  32. Jelmer123

    Jelmer123

    Joined:
    Feb 11, 2019
    Posts:
    241
    Thanks. The underwater effect runs at full 60 FPS on an iPhone 12 pro with caustics off. But performance completely deteriorates with caustics on.
    Now I understand you don't support mobile, but let's say generally spoken, the fake caustics effect shouldn't be so performance heavy should it?
     
  33. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,209
    The caustics effect itself isn't particularly resource intensive, but if you have the "Directional Caustics" option enabled that can certainly be detrimental as this involves additional (relatively costly) calculations.
     
    Jelmer123 likes this.
  34. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,209
    Submitted version 1.5.2!

    Added:
    - Material UI, dropdown menu next to foam/normal map texture slots, to quickly try out different textures.
    - River mode, parameters to control the minimum slope angle and falloff.
    - Translucency, parameter to control effect from direct light, simulates glacial or morene lakes.
    - Option to enable support for light cookies in the shader inspector

    Changed:
    - Improved calculation of light intensity for sun reflection and translucency, now more accurately responds to color.​

    Fixed:
    - Box projected Reflection probes not appearing correctly on the water surface for orthographic cameras.
    - Caustics appearing in shadows underwater when using the Advanced shading mode (regression since v1.4.0)
    - Shader error when Light Probe Volumes was enabled in Unity 2023.1+
    This update also finalize the groundwork needed to support the upcoming Dynamic Effects extension, which is currently pending review by the asset store staff. Pleased to report that VR and low-end mobile hardware are entirely supported and viable.

    The extension will have its own demo scene, where various effects are showcase in a presentation-like style.

    upload_2023-10-10_15-37-39.png
     

    Attached Files:

    Bwacky, adamgolden, Stochfard and 2 others like this.
  35. Jelmer123

    Jelmer123

    Joined:
    Feb 11, 2019
    Posts:
    241
    Thanks, no directional was not on.. (but dang that looks even better haha!).
    PS: update above here looks awesome!
     
  36. Jelmer123

    Jelmer123

    Joined:
    Feb 11, 2019
    Posts:
    241
    Hey, with the latest update I get 60 FPS with caustics on iPhone 12 Pro, and around 45 fps on an iPhone 8. So that's great!


    I'm trying to make an oil spill and have two questions:
    Screenshot 2023-10-16 at 18.07.29.png
    1. Notice that particle systems (traditional and VFX graph) are not affected by the underwater fog. Is there a way to make particles system (with a simple mesh plane) be affected by the under water fog so that it blends in?
    2. I'm trying to project a decal of oil onto the water surface, but the URP decal projector doesn't "see" the surface, and projects on the ocean floor instead. Any way to get some oil textures onto the water surface (something like the foam system)?
     
  37. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,209
    Ah, if you were using a version older than 1.0.4, that may certainly make a difference!

    Regarding transparent materials, please see this page in the documentation.

    Decals will generally never apply to transparent materials, because they aren't rendered into the depth texture. This is possible in HDRP, but it would be up to Unity to implement support for this.
     
    Jelmer123 likes this.
  38. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,209
    Version 1.5.3 submitted!

    Fixed:
    - Material UI, dropdown texture selection not working if the asset was installed as a package
    - Vertex color-based intersection foam not appearing if the "Disable Depth Texture" option was enabled.
    - Caustics not being visible if the "Disable Depth Texture" option was enabled.
    - Surface Foam added through vertex colors not contributing to river slopes
     
    adamgolden likes this.
  39. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,209
    Bwacky and adamgolden like this.
  40. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,741
    Looks great, do you have a demo one can try to look at the water first hand.
     
  41. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,209
    That's an excellent idea! I'll make a standalone build from the demo scene, which has a flyable camera, there's several effects that can be viewed in action there to get an impression.
     
  42. gabrielgonzalez89

    gabrielgonzalez89

    Joined:
    Sep 16, 2019
    Posts:
    22
    Extremely excited for using the trail system :rolleyes:
     
  43. gabrielgonzalez89

    gabrielgonzalez89

    Joined:
    Sep 16, 2019
    Posts:
    22
    any idea on why I'm seeing this bands?Also is there a way to make the foam alpha lower? upload_2023-10-18_10-25-14.png
     
  44. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,209
    Demo scene build can now be downloaded here: https://staggart.xyz/unity/stylized-water-2/sw2-dynamic-effects-demo/

    The limitations of Unity's trail renderer aren't lost on me, but building a custom trail renderer from scratch is too tall an order at the moment. I expect it'll be inevitable in the future as realistic boat wakes will never be possible using it.

    Yeah, its the result of additive blending, it usually isn't visible when the foam isn't full white, I'd recommend assigning a foam-style texture to the material there (currently a caustics texture).

    I see it can also be largely mitigated by bringing this value way down on the Trail Renderer components:
    upload_2023-10-18_15-53-22.png

    Note that there is a component on each renderer, this is where you can scale how strongly the effect paints on foam:
    upload_2023-10-18_15-54-31.png
     
  45. gabrielgonzalez89

    gabrielgonzalez89

    Joined:
    Sep 16, 2019
    Posts:
    22
    Actually I feel that whatever porting was happening, it did not update the texture of the dynamic foam. I duplicated the example and copied the values from the previous material and it seems to work correctly. I did update from a extremelly outdate 1.1
     
  46. gabrielgonzalez89

    gabrielgonzalez89

    Joined:
    Sep 16, 2019
    Posts:
    22
    Ok I'm back , seem to be that there's a Editor issue. You cannot Change the dynamic because I think it is grabbing the normal Foam on the editor.

     
  47. Bwacky

    Bwacky

    Joined:
    Nov 2, 2016
    Posts:
    192
    Congrats on the launch!
    Would you be able to offer advice on how to set up or repurpose the falling boxes setup for players?
    I simply want the splash to play once the player initially jumps into the water and can't figure out which way to do it :oops:
     
  48. gabrielgonzalez89

    gabrielgonzalez89

    Joined:
    Sep 16, 2019
    Posts:
    22
    Hey most of this stuff is being done with a particle system or a trail renderer , you want to play the particle as soon as your character touches the water. upload_2023-10-18_17-0-59.png
    You can even place both the splash effect and the ripple together like this and just click play, it should do the effect on your scene view. after that you just need to set this to teleport to the player position and play as soon as he jumps on the water.
     
    StaggartCreations likes this.
  49. gabrielgonzalez89

    gabrielgonzalez89

    Joined:
    Sep 16, 2019
    Posts:
    22
    upload_2023-10-18_17-40-0.png
    Weird issue here, seems like the shader doesn't like if you go over 90° falls
     
  50. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,209
    Ah, that's awkward! Certainly not intended. I see this is due to an oversight in the UI code. You can locally correct this as such:
    upload_2023-10-19_9-57-6.png

    I'll be sure to include this fix in an update soon.

    I believe you have the slope angle falloff set to 0, which will create a sharp border:
    upload_2023-10-19_10-5-10.png
    It'd set it to a minimum of 15-15 to smoothen the transition.

    Thank you so much!

    This is fairly straightforward to achieve:
    • Attach a BoxCollider to your water plane, ensure the "Is Trigger" box is checked.
    • Attach the WaterEntryEffect component to the object with a collider and rigidbody you want to drop in the water.
    • Drag the Water Impact Ripple prefab (or any other) into your scene and drag it into the Entry Effect field.
    What will happen is the particle effect will move to the position where the object with the WaterEntryEffect script touches the water at (specifically anything on the "Water" layer), and plays the effect once.

    You'll notice the script is quite simple, but that's the gist of it! Ways to improve this:
    - Measure and compare the velocity of the colliding object, a splash should only play if it is coming in fast enough. Otherwise you get situations where a big splash plays even when the player touches the water gently.
    - Check the direction in which the colliding object is traveling. Only allow the effect to play when it is coming in nearly vertical.
     
    Bwacky and gabrielgonzalez89 like this.