Particle simulation (Vulkan Compute Shaders + C++)
- 4 Devlogs
- 33 Total hours
A particle simulation using Vulkan and C++. For this project specifically, I put massive focus on using compute shaders and learning as many new vk features as possible.
A particle simulation using Vulkan and C++. For this project specifically, I put massive focus on using compute shaders and learning as many new vk features as possible.
Probably not, but it sounds cool and is a Minecraft reference.
Anyway, as you can see, I (sadly along with the help of an LLM, since I’m not the best at physics (i promise I only used it to explain the physics part and fix some insanely weird bugs)) implemented the collision system.
So, to achieve this and not make my computer burn down, I used a spatial grid. The way this one worked is:
I probably won’t finish this during stardance, but I’ll add some mouse interactions so the simulation isn’t so stagnant, and that should probably be it.
In the attachments you’ve got a simulation of 2,000 and 100,000 particles, and a screenshot of the final result.
Just a regular burger now, though.
As you can see, the particles are there. And there’s many of them. Three thousand if I remember correctly. I can’t lie, implementing this took a lot and made me experiment with a lot of new things and especially modern Vulkan.
So, in my last devlog I said that the particles were in memory. They in fact were not, because my compute invocation was broken. But as you might imagine by now, I fixed that. What was wrong is that I was calling vkDispatch(cb, [actual number of dispatches], 0, 0). Since x * 0 * 0 = 0, the total number of calls was, you guessed it - zero. Changed it to vkDispatch(..., 1, 1) and it worked like a charm. Then I had issues with displaying the stuff (passing uninitialized values to the shaders), and also making the particles round. Overall, a nice challenging part of the project.
Yup. Despite working on this devlog for about 9 hours, I’ve made no visible progress. There’s still no window displaying anything (there is one on traditional DEs, but it won’t work on Hyprland for some unknown reason). However, it’s not as simple as it sounds, since I had to be working on something, right? Right. That thing being the base for the particle simulation – The compute pipeline, the compute shader, the compute everything. Additionally, I’ve finished the renderer init. Now the program launches without any issues! Somehow. Lol. The obvious next step is to actually get something rendering, and since the particles, or at least potential particles should be in their SSBO by now, I think I should be able to make a humble hundred-thousand-vertex draw call and be good! In theory, of course. How it will turn out in practice, we will see. And because as I said, I don’t have any visual output yet, you can have another picture of the terminal output as a treat.
This was supposed to be covered a separate devlog, however posting the devlog failed and I simply gave up. Anyhow, I set up the project in quite a simple way, hoping to minimize the amount of bloat in the vendor directory. The project uses C++, Vulkan (my two beloved technologies) and CMake, which is a first for me.
So far, I’ve made use of GLFW to create a window and then used Vulkan to create a window surface and prepare the swapchain. What the swapchain in plain terms is that it makes sure you dont have to wait for the next frame to be rendered with a blank screen.
The next obvious step would be a graphics pipeline, however this time I’m thinking of going straight into rendering particles instead of the regular triangle. That would require a different (possibly instanced) .
graphics pipeline, more sophisticated shaders and of course, a compute pipeline, learning which is the very point of this project.
-# ignore assert failed please