Made in Unity 2022.3.27f1
Build folder added.
My project topic is simulating mechanical properties of metals such as plasticity, elasticity and hardness.
I started by testing geometry shaders in Unity. I wrote a shader that created pyramid faces on triangles following a tutorial.
End result was great but i wanted to get back calculated vertex data from the GPU. During my research, i found out that Compute Shaders was the best fit for it.
First, i created a position, color struct, put them in an array then in the GPU, i calculated the color of each position using their x position as an offset.
1-first.gpu.coloring.test.mp4
After that i tried changing their positions at each call.
2-first.gpu.movement.test.mp4
Now that i had figured out the syntax, time to continue. During my research, i stumbled upon this video and paper:
It was a great video and i had the idea to shoot balls onto the mesh to test it. So, i created a script to shoot balls using mouse position. At first ball impact test, i had some issues.
3-first.ball.impact.test.mp4
After some time testing and bug fixing, i found out that i was doing the calculation in reverse and not clamping the result. I created a working CPU version of it using a tutorial video.
4-cpu.ball.impact.test.mp4
After that, i created the algorithm in my compute shader and it worked like a charm.
5-gpu.ball.impact.test.mp4
But having a mesh collider for collision detection had complicated things because after changing the vertices, you have to change the mesh reference in the mesh collider but if you do individual changes, Unity won't recognize the change and the mesh collider won't reload.
That's why i wanted to change my approach on the matter and started working on a separate grabbing feature that allows user to place a sphere on a mesh then use it to play with the mesh. So, i created a tool that is controlled by mouse screen position and scroll wheel for the z displacement.
6-Mesh.Grab.Controls.Done.mp4
After that, i created a new script called grabbable then connected it with a new compute shader called GrabShader. My aim is to use the sphere as a grabbing tool to pull or push vertices to modify the mesh. First test:
7-First.Grab.Test.mp4
I'm doing some of the calculations wrong because as opposed to following the sphere at hand, all of the vertices transform to a single spherical volume. If i reverse it, they originate their direction vector from it then go outwards.
After refactoring the code i got a success on basic pull.
8-First.Sucessful.Grab.mp4
The issue was originating from local-global coordinate differences. I forgot to convert them like i did in the first script. Doing collision check myself, i checked them but my Armadillo was near the origin so the numbers were similar. I found out when i to moved it after i've put another Armadillo into the scene.
Now i can take a chunk of some mesh and move it freely.