Optimized real-time refraction and reflection effects
Dynamic waves with 4 different types of ripples:
On-Collision Ripples:
Created when a rigidbody falls into the water
Created when a rigidbody gets out of water
Created when a rigidbody moves in water
Constant Ripples: Created at regular time intervals
Script-Generated Ripples: Created in code
Waterfall Ripples: Created by a waterfall object that overlaps the water object
Sine waves
Waves Can Affect Rigidbodies: Rigidbodies floating on water follow the undulations of water waves
Customizable sound and particle effects for each type of ripple (excluding the waterfall ripples), with an efficient object pooling system
Easily create very large (limited to a specific region) or endless water areas with great performance
Fake perspective effect: Add a sense of depth to your scene by rendering certain objects as partially submerged into water
Set a solid or gradient color, a texture, or even a texture sheet animation and apply distortion effects, across the water body and/or surface
Animate the water size either in code, or using Unity animation system
8 optimized water shaders:
4 shaders for the Builtin Render Pipeline: 1 unlit, and 3 lit shaders (pixel-lit, vertex-lit, and vertex-lit-only-directional-lights)
2 shaders for the Lightweight Render Pipeline: 1 unlit and 1 lit shader (supports the 2D Renderer)
2 shaders for the Universal Render Pipeline: 1 unlit and 1 lit shader (supports the 2D Renderer)
Waterfall System:
Optimized real-time refraction effect
Can interact with water systems it overlaps, disturbing their surfaces and creating ripples
Set a solid or gradient color, a texture, or even a texture sheet animation and apply distortion effects, across the waterfall body, left-right edges, and top-bottom edges
8 optimized waterfall shaders:
4 shaders for the Builtin Render Pipeline: 1 unlit, and 3 lit shaders (pixel-lit, vertex-lit, and vertex-lit-only-directional-lights)
2 shaders for the Lightweight Render Pipeline: 1 unlit and 1 lit shader (supports the 2D Renderer)
2 shaders for the Universal Render Pipeline: 1 unlit and 1 lit shader (supports the 2D Renderer)
Looks great! I’m thinking of grabbing this but I have a few questions…
What’s the purpose of the Prefab Utility you mention in the documentation? Does this plugin support Unity’s standard prefab workflow as default too, or do you have to use the Prefab Utility?
How does this plugin play with Unity’s own Pixel Perfect package? I could imagine that depending which one takes precedence, reflections and refraction might look a bit weird and distort low-res pixel artwork quite heavily. Any observations there?
1- The plugin uses Unity’s standard prefab workflow. Prefab Utility just makes sure that the prefab is saved properly.
When you first create the water object in your scene, the water script will create a new material to be used by the water’s MeshRenderer and a noise texture to be used by the newly created material. This material and the noise texture are not saved as assets in your project yet, they belong to the scene and get serialized with that scene.
So, if you simply drag and drop the water object from the hierarchy to the project view, Unity will create a prefab but it will not save the material with it, and the prefab will end up with a missing material!
To get around this issue, Prefab Utility will take care of saving the material and its noise texture in your project first, then it will create the prefab. You just need to specify where you want to save the prefab, press the “Create Prefab” button and done!
2- The plugin was tested with Unity’s own Pixel Perfect package, and it works just fine!
Hi there, first of all thanks for the assets! The water effects look great and I’m having great fun with all features. I’m fairly new to Unity and am looking to do a couple of things with C# scripts:
how do you change the color of the Game2d water material? The attached script works when attached to sprites but I can’t figure out how to adapt it to the water material.
how would you change the liquid depth? E.g. push a button and liquid depth goes up, push another it goes down
Hello!
Thank you so much! I’m so glad you’re having fun with the asset ^^
[EDIT] As of version 1.3, it’s now much easier to change the water colour at runtime. I have attached an updated version of the script.
1- I adapted the script so it should work now with the water material too, and it sets a random colour each time you press the R key! If anything still unclear, please let me know
(Sorry for the bad gif quality)
[EDIT] 2- As of version 1.3, you can use the method .AnimationModule.AnimateWaterSize(targetSize,duration,constraint,wrapMode)
targetSize: [Vector2]: sets the water target size.
duration: [float]: sets the animation duration in seconds.
constraint: [enum WaterAnimationConstraint]: constraints the position of one/multiple water edge(s).
Once: Stops playing the animation once the target size is reached.
Loop: The water size is reset to the initial size and the animation is restarted once the target size is reached.
PingPong: When the target size is reached, the initial size will be the new target size. So the water size will ping-pong back and forth between the initial and the target size.
For more information please check https://game2dwaterkit.haydeludos.com/water-system/water-size-animation/ [ORIGINAL REPLY]
2- A straightforward solution would be to use Unity Animation system. So you could create two animation clips to animate the water size (here you just need to change the water height (y value)): one animation clip for increasing the water depth(height) and one for decreasing it. Then, you control which of the two animations to play inside your script depending on the pressed key. The water script will then detect the change to the water size and will update accordingly.
But, there’s a better and more flexible solution to the problem IMO that will avoid the hassle of creating the animation clips and managing the controller(animation controller) animations states. We could implement a new public method inside the water script that gets the target depth (and maybe another parameter to set the animation speed (how fast we reach the target depth)), and then we update the water size inside the water script’s update method each frame until the target depth is reached. Then inside your script, you just need to reference the water object and then call the new method with the proper target depth depending on the pressed button. Please feel free to contact me (please check the contact page on my website) so I could provide you with the steps to set up the first solution, or the necessary changes to the water script if you’de like to implement the second solution.
Hi, thanks for your help! Your attached script runs perfectly and is laid out in a way that I can easily adapt. I’ve sent you a message with regards to my second question, I think what you’ve described is bang on
Hello. Love your asset, super versatile and neat looking.
I’m having a problem with sprite layering.
I noticed the options for sorting layers and order in layer is in the rendering options, but they don’t seem to do anything when I use them, do I need to enable something for it to work? So far I have to move gameobjects in front or behind the water with their transforms, and while it works fine, it would be super neat if I could manage it with sprite layers instead.
[OLD REPLY] Opaque objects (Geometry render queue) are rendered before transparent objects (Transparent render queue). And when rendering each queue, objects belonging to that queue are first sorted by various criteria (the sorting layer is just one of these criteria), then get rendered. Hence, if the water’s rendering mode (in the water material editor) is set to Opaque, the water’s sorting order will be relative to other opaque objects and if it is set to Transparent, the water’s sorting order will be relative to other transparent objects (eg: Sprites). So to control the rendering order of the water object relative to the sprites using sorting layers, the water rendering mode should be set to Transparent. Unfortunately, the water refraction and reflection effects are not available in that mode. Therefore, the best way to order the water object relative to the sprites is to keep the water rendering mode to opaque and move the sprites slightly behind and in front of the water, just like you did
v1.3 Update should be available next week, and it will bring many improvements and exciting new features. Any suggestions are greatly appreciated! [Edit] Version 1.3 is now live!
For what it’s worth, I always thought the water in Rainworld looked phenomenal:
I wonder if you could achieve a similar effect by offsetting the upper vertices on the surface strip? I don’t know enough about how it all works to provide much help here unfortunately, but just an idea.
Great idea!
I’m definitely going to work on a similar effect. This would take some time to implement and test, so probably will be part of v1.4 update.
For now, though, I’m focusing on getting the update ready for release: improving the inspector, cleaning up and profiling the code.
-New waterfall system
-Added support for the Lightweight Render Pipeline (LWRP) / Universal Render Pipeline (URP) [Upgrade Guide: https://game2dwaterkit.haydeludos.com/upgrade-render-pipeline/]
-Simulation Mode: Quickly tweak and test water/waterfall simulation properties in edit-mode
-Added support for perspective and isometric camera projections
-Gradient Color for the water surface -Texture Stretch tiling mode
-Texture Scrolling
-Reflection Fade
-Change Tint-Colors/Textures apply order
-Scale the reflection viewing frustum height
-Full support for sorting layers: You can now easily sort the water/waterfall object relative to sprites using sorting layers
-Sprite Mask Interaction: You can now hide/reveal parts of the water/waterfall object using Sprite Masks
-You can now define a fixed size for the refraction/reflection render-textures.
-Greatly improved the inspectors.
Note:
This version adopts a new folder structure, mainly a Runtime folder (scripts and shaders) and an Editor folder (custom editor scripts). So in case you already have prior versions of the asset in your project and want to adopt this new folder structure, please follow these upgrade instructions:
1- Open a new empty scene
2- Delete Game2DWaterKit folder
3- Import the new package
Hello HaydeLudos,
I have an issue with generating shaders when building a project on Windows10. I am using unity 2019.2.6f1 and it takes ages = 8 hours and I am still in the middle of shaders generation. I have around 4 millions small files created in Library/ShaderCache before I cancel this build process and it was still in the middle of shaders generation. Do you have any advice, how to optimize that? Before adding game-2d-water-kit it was a matter of a few seconds to create a build.
I’ve recently came across this issue, and it turned out that adding any of the “Game2D Water Kit” shaders to the “Always Included Shaders”, in the Graphics settings, causes very very long build process.
I’m still investigating to see what’s exactly causing it. But for the time being, you can get rid of this issue by removing any “Game2D Water kit” shaders entries in the “Always Included Shaders” list. Then, please move the shaders to the “Resources” folder.