Home

Awesome

WaterRW

日本語版

WaterRW is 2D interactive water system for Unity.

001

Requirements

Quick Start

  1. Download WaterRW.unitypackage from releases page.
  2. Install Burst package from Package Manager.
  3. Add Ruccho/Water-RW/Prefabs/Water-RW (Compute).prefab to your scene.

Water-RW prefab is composed of WaterRWCompute script, MeshFilter, and MeshRenderer with Water-RW/With Compute material.

Some platforms such as WebGL or old mobile devices don't support Compute Shader. Make sure your target platform does before using WaterRW.

(Legacy implementation with C# Job System is also included in the package but it is no longer supported.)

Material Settings Guide

WaterRW uses the shader Water-RW/With Compute.

image

PropertyType
TintColor Tint color.
Pixel SnapFloat Same as one in Sprites-Default shader.
Normal ATexture2DNormal map A. Use tiling properties to scale a map.
Normal A IntensityFloat Amount of distortion of normal map A.
Normal A SpeedVector Scroll speed of normal map A. Only X and Y works.
Normal BTexture2DSame as normal A.
Normal B IntensityFloat Same as normal A.
Normal B SpeedVector Same as normal A.
Background BlendFloat Rate of reflection blend.
TransparencyFloat Dark reflection areas goes transparent.
MultiplierColor Color multiplier.
AddendColor Color addend.
Wave Size in Viewport SpaceFloat Horizontal size of near-surface distortion.
Wave Distance in ViewportFloat Vertical size of near-surface distortion.
Wave Frequency by PositionFloat Frequency of sin curve used for near-surface distortion by vertical position.
Wave Frequency by TimeFloat Frequency of sin curve used for near-surface distortion by vertical time.
Surface ColorColor Color of surface line.
Surface Width in PixelColor Width of surface line in pixels.
Fade Distance in Viewport SpaceFloat Vertical size of fade to avoid display reflection areas out of GrabPass.

Enable Interactions

image

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.

WaterRWCompute Settings

image

PropertyType
Mesh segments Per Unitfloat Numbers of mesh divisions per unit.
Update ModeFixedUpdate / UpdateTiming to calculate wave. Use FixedUpdate to work interactions correctly.
Override Fixed Time StepboolDetermine whether to use custom timestep.
Fixed Time StepfloatCustom time step.
Cfloat The constant used in wave calculation. Increasing this will increase the speed of the waves.
Decayfloat Coefficient for damping waves.
Enable Interactionfloat Determine whether to use interaction.
Layers To Interact WithLayerMaskLayers to interact with.
Spatial Scalefloat Horizontal scale used in wave calculation.
Max Interaction Itemsfloat Max number of rigidbodies to interact with.
Wave Buffer Pixels Per Unitfloat Resolution of buffers used to wave calculation.
Scroll To Main Camerabool Track the range of the wave calculation to the position of the main camera.
Max Surface widthfloat Max width of the wave in world scale.

Avoid Divergence

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


Buffer Scrolling

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.