This is a Unity Project with assets for a ripple shader. It contains the shader itself (HLSL) and a script (C#) for using on the object to create ripples on.
The default scene contains a dynamically generated mesh with configurable LOD and a particle system. Because the shader modifies individual vertices, the higher LOD the mesh has the better the ripple will look.
The CollisionScript is responsible for receiving the collisions and passing those points to the shader. The shader then manipulates the verticies based on their distance from the collision adjusting the normals accordingly and taking (basic) lighting into account.
unity-ripple-shader-short.mov
- The ripples are based on collisions so a collider is necessary on the object being rippled.
- Attach the CollisionScript to the object being rippled.
- Create a material specifying the ripple shader as the shader.
- The following settings can be configured (default values are recommended):
Setting | Description | Location | Default Value |
Initial Ripple Size | The initial size or amplitude of the ripple. | Script | 0.7 |
Scale | The overall size or scale of the ripple. | Shader | 0.5 |
Speed | The effective animation speed of the ripple. Use to emulate density of the fluid. | Shader | 0.3 |
Frequency | The number of times the ripple rebounds. | Shader | 8 |
RippleDiameter | The max diameter of the ripple and number of ripples per collision. | Shader | 3 |
- Supports the Universal Render Pipeline (URP).
- Configurable size, speed, frequency, magnitude, falloff.
- Supprots a single texture and diffuse color.
- Supports lighting.
- Includes a dynamic plane generator with configurable LOD.
- Because the shader acts on mesh verticies, the quality of the ripple will depend largely on the detail of the mesh - the more verticies, the better the ripple.
- Only works with global directional light at the moment.
- Ripples are always perpendicular to the surface.
- Due to limitations of HLSL the number of ripples has to be defined at compile-time. It's currently limited to 100 simulataneous ripples.
- The mesh generator script is purely to aid prototyping this shader. I will build a seperate project for it that will be comprehensive and complete.
- Upgrade project to latest version of Unity.
- Handle multiple lights including point lights.
- Handle direction better.
- Make intial ripple size dynamic based on force of collision and size of coliding object.
- Tests and more debug features.
- Better comments.
- Caustics maybe?
- Animated textues.
- Work out some way to make the number of ripples truly dynamic. It's partly there but needs more work.