Demo tested on a OnePlus 3T, runs at 55 - 60 FPS
In the demo scene (Assets/Scenes/Main.unity) you can spawn stones or a rake via the buttons.
- Left click / touch: drag object
- Long left click / touch: pick up object
This effect uses multiple shaders and materials, as multipass shaders are to my understanding currently not available in Unity SRPs. Those multiple materials/shaders need to be controlled by a script. (Done in Assets/Scripts/Sand/DrawDepth.cs)
How it works:
- A depth texture is created from the underside of all movable objects and stored in a render texture.
- From this texture a difference texture is created, with the (stored) depth texture of the previous frame.
- This difference texture gets blured.
- The blured difference texture now gets subtracted from the existing sand depth texture.
- The depth texture from the beginning gets added to the sand depth texture.
This texture is saved as the new sand depth texture.
- The texture gets blured again. This texture is then used by the actual sand shader.
- The actual sand shader uses the depth map to modify the normals of the material. No actual displacement of the geometry happens.