Unity Shader to achieve an effect of a water surface swirl - bosssu/shader_Funny GitHub Wiki

This time I mainly use the shader to generate a funnel-shaped water whirlpool. The final effect is as follows:

v2-6fb7b9f21b063609b809eb6db131a916_b

video link: https://youtu.be/d6nWrG0Osx0

The main principle is to use the shader to offset the vertices of the mesh downwards according to the distance between the vertex and the center of the vortex. By twisting the vertices around the center of the vortex in the y-axis direction, we achieve our vortex effect this time. Of course, to achieve the effect of the above picture, some operations such as grabpass need to be added.

I actually wrote three. One basic and two more complex.

See the schematic diagram below:

image

d: distance from mesh vertex of P to vortex center O, r: vortex radius

image

It can be seen that the arc surface of the vortex can be formed by using s^2

image

dep: the distance that the vertex is offset downward (the vortex sinks), s^2 forms an arc surface

As can be seen from the above three schematic diagrams, we mainly require the dep (vertex downward offset) corresponding to each vertex. For the specific process, see the following core code:

image

vertex offset

image

The real vortex will be distorted along the y-axis

image

final effect

Shader source code, key parts are commented, have fun!: https://github.com/bosssu/shader_Funny/tree/main/Assets/Samples/Voxtex