WaterRW is 2D interactive water system for Unity.
- Unity 2022.3 or later
- Compute shader compatible platform
- Universal Render Pipeline enabled
- 2D Renderer is also required to enable reflection and refraction.
Add git URL from Package Manager:
https://github.com/ruccho/WaterRW.git?path=/Packages/com.ruccho.water-rw
- Import
Prefabs & Samples
fromSamples
page in Package Manager.
- Place
Prefab/Water-RW (Compute).prefab
to the scene.
-
To enable reflection and refraction, you have to use 2D Renderer.
-
Enable Camera Sorting Layer Texture at the layer you want to reflect and refract.
-
Water-RW has to be rendered after Camera Sorting Layer Texture. Use Mesh Renderer Sorting component to configure the sorting layer of a Water-RW instance.
WaterRW uses the shader Water-RW/With Compute
.
Property | Type | |
---|---|---|
Tint | Color |
Tint color. |
Pixel Snap | Float |
Same as one in Sprites-Default shader. |
Normal A | Texture2D |
Normal map A. Use tiling properties to scale a map. |
Normal A Intensity | Float |
Amount of distortion of normal map A. |
Normal A Speed | Vector |
Scroll speed of normal map A. Only X and Y works. |
Normal B | Texture2D |
Same as normal A. |
Normal B Intensity | Float |
Same as normal A. |
Normal B Speed | Vector |
Same as normal A. |
Background Blend | Float |
Rate of reflection blend. |
Transparency | Float |
Dark reflection areas goes transparent. |
Multiplier | Color |
Color multiplier. |
Addend | Color |
Color addend. |
Wave Size in Viewport Space | Float |
Horizontal size of near-surface distortion. |
Wave Distance in Viewport Space | Float |
Vertical size of near-surface distortion. |
Wave Frequency by Position | Float |
Frequency of sin curve used for near-surface distortion by vertical position. |
Wave Frequency by Time | Float |
Frequency of sin curve used for near-surface distortion by vertical time. |
Surface Color | Color |
Color of surface line. |
Surface Width in Pixel | Color |
Width of surface line in pixels. |
Fade Distance in Viewport Space | Float |
Vertical size of fade to avoid display reflection areas out of Camera Sorting Layer Texture. |
Smooth Buffer Edge in World Space | Float |
Size of smoothing area in world space at the edge of wave buffer. |
Reflection Intensity | Float |
Intensity of reflection. |
WaterRW supports rough interation with rigidbodies. (Colliders with complex shapes may not be handled correctly!)
In inspector of WaterRWCompute
script, select layers to interact with in Layers To Interact With
property.
Property | Type | |
---|---|---|
Mesh segments Per Unit | float |
Numbers of mesh divisions per unit. |
Update Mode | FixedUpdate / Update | Timing to calculate wave. Use FixedUpdate to work interactions correctly. |
Override Fixed Time Step | bool |
Determine whether to use custom timestep. |
Fixed Time Step | float |
Custom time step. |
C | float |
The constant used in wave calculation. Increasing this will increase the speed of the waves. |
Decay | float |
Coefficient for damping waves. |
Enable Interaction | float |
Determine whether to use interaction. |
Layers To Interact With | LayerMask |
Layers to interact with. |
Spatial Scale | float |
Horizontal scale used in wave calculation. |
Max Interaction Items | float |
Max number of rigidbodies to interact with. |
Wave Buffer Pixels Per Unit | float |
Resolution of buffers used to wave calculation. |
Scroll To Main Camera | bool |
Track the range of the wave calculation to the position of the main camera. |
Flow Velocity | float |
Velocity of the flow. |
Max Surface width | float |
Max width of the wave in world scale. |
Values of Fixed Time Step
, C
, Spatial Scale
and Wave Buffer Pixels Per Unit
may cause divergence.
To avoid divergence, keep: 0 ≤ (C * dt / dx) ≤ 1
.
dt
= time step (Fixed Time Step
when Override Fixed Time Step
is true, otherwise Time.deltaTime
or Time.fixedDeltaTime
is used)
dx
= Spatial Scale
/ Wave Buffer Pixels Per Unit
Although the size of the buffer used for wave calculation is finite, interaction with the seemingly infinite surface of the water can be achieved by making the wave calculation range follow the camera position.
If Scroll To Main Camera
is true, it will automatically follow Camera.main
.
To set it manually, set the X coordinate to float WaterRWCompute.WavePosition
.