27. Dezember 2024

Studio Game 2 | Mattia | Week 4

Compute Shaders

This week i wanted to figure out a way to patch those cracks on the mesh. But after a lot of thinking and talking about it with different people, I noticed that the cracks are only a visual problem, but it will never effect the player in any way, if there isn’t a real mesh or collider. And also, when the resolution is high enough, the cracks might be so small, that they aren’t even visible anymore.
So i decided to implement the marching cubes in Compute Shaders, to speed up the process of generating the mesh for each chunk significly.
This took a lot of trial and error since i’ve never used compute shaders before. But after a lot of weird artefacts and a few gpu-crashes it finally worked.

I had to rewrite a lot of the marching cubes algorithm to run on he GPU and in parallel. Especially the parallel running and calculation of the triangles of the mesh led to a few funny-looking results.

 This should be a normal sphere.

But now it’s all up and running as it should.

Performance gains

When I made the switch to the compute shaders, I wanted to test how much faster the algorithm could now run. It probably could be optimised even more, but since I don’t yet have to knowledge to do so, I will just leave it at that for now.

When comparing the times it takes on the single threaded CUP in C# vs multi-threaded GPU in compute shaders, I got those improvements:
125’000 verts 90 times faster
1’000’000 verts 160 times faster

Bottleneck

The only bottleneck I still have is the creation and calculation of the vertex position and wheter it’s on the mesh or not. This is still happening in C#. So the task for next week will be to overhaul the entire system on how the vertices are created. I will probably make this also run on the GPU. Here I’m thinking about creating textures that then can just be sampled, but I will have to see what I can come up with.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert