Hi all !
I have adapted the Finite Difference method in Unity to simulate the motion of a liquid material.
Here are my actual results :
By Clicking
By Collision
I have made my own Mesh ( a simple plane ) which is 16 by 16 squares ( cut in triangles ).
I have also made my own class MyMatrix because all the calculation are made with Matrix.
I calculate the matrix of rigidity, the matrix of mass etc … and in the FixedUpdate loop I do all the necessary calculations to ‘move the wave’.
As you can see my Frame Rate is a little bit low and i have some fall sometimes !
The big problem is that, if I increase the size of my mesh, the size of the matrix increases too ! (And the number of operation too …) And my frame rate falls to 3 or 4.
The operation which take the more time is the multiplication of huge matrix .
Have you solution to calculate this faster ?
My loop in the Update() method looks like this :
float[,] term_1 = MyMatrix.MatrixProductCoef (M, Z1, 2f);
float[,] term_2 = MyMatrix.MatrixProductCoef (Q, Z0, -1f);
term_1 = MyMatrix.MatrixSum (term_1, term_2);
term_2 = MyMatrix.MatrixProductCoef (A, Z1, -deltat * deltat * 0.5f);
if (f0 != 0) {
float[,] term_3 = MyMatrix.MatrixTripleSumCoef (F0, F1, F2, deltat * deltat * 0.25f, 2 * deltat * deltat * 0.25f, deltat * deltat * 0.25f);
term_2 = MyMatrix.MatrixSum (term_3, term_2);
}
term_1 = MyMatrix.MatrixSum (term_1, term_2);
Z2 = MyMatrix.MatrixProduct (P, term_1);
Z0 = Z1;
Z1 = Z2;
MoveMesh ();
As you can see, unity has to compute lot of sum and multiplication …
I tried also to update that in a Co-routine ( the performance in the video ) but it is not better than before ( worst sometimes… ).
So … Am I in the right direction to reproduce a liquid behavior ? Maybe it’s easier to do this with Shader.( I don’t know anything about Shaders … )
Thanks !