Using **Graphics.DrawMeshInstancedIndirect** so that I can calculate the fish positions with compute shader.

The moving tails are just vertex displacements in shader. Rotation are also done in the rendering shader.

Below is the look-at matrix that takes the normalized velocity to be the rotation, and to be the forward axis.

```
float4 ApplyRotation (float4 v, float3 rotation)
{
// Create LookAt matrix
float3 up = float3(0,1,0);
float3 zaxis = rotation;
float3 xaxis = normalize(cross(up, zaxis));
float3 yaxis = cross(zaxis, xaxis);
float4x4 lookatMatrix = {
xaxis.x, yaxis.x, zaxis.x, 0,
xaxis.y, yaxis.y, zaxis.y, 0,
xaxis.z, yaxis.z, zaxis.z, 0,
0, 0, 0, 1
};
return mul(lookatMatrix,v);
}
```

Continue reading “Fishes”