stardance has been extended another month! the new deadline is october 31 :)

You are browsing as a guest. Sign up (or log in) to start making projects!

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.

Ship #1 Pending review

Particle Simulation, semi-finished.

At last I’ve done it, this a mini-dream come true.
I’ve finally “mastered” Vulkan compute shaders and got better at using C++ and GLSL.
The program spawns 2000 particles (a very humble number, so I can run it on almost any machine) and simulates their gravity and collisions.
In my very humble opinion, it’s quite impressive.

  • 4 devlogs
  • 33h
Try project → See source code →
Open comments for this post

7h 41m 19s logged

The end?

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.

What it took

So, to achieve this and not make my computer burn down, I used a spatial grid. The way this one worked is:

  • I added 2 buffers, one for cell heads, and other for next particles
  • Created a linked list using those, with the last one pointing to index -1.
  • Then, using some nonsense calculations, for every particle I checked every particle in their own cell and the 8 surrounding ones. That way I didn’t have to make a literal billion if statements per second.
  • Then I fiddled around with making the particles stop moving on their own, and bim bam boom, I’ve got a nice layer of particles at the bottom.

What’s next?

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.

Attachments

In the attachments you’ve got a simulation of 2,000 and 100,000 particles, and a screenshot of the final result.

2
0
33
Open comments for this post

9h 20m 39s logged

Not a nothingburger anymore!

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.

What it took

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.

0
0
24
Open comments for this post

8h 39m 4s logged

A very big nothingburger.

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.

0
0
149
Open comments for this post

7h 20m 26s logged

Devlog #1

Project Setup

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.

Renderer base

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.

Next Steps

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

0
0
29

Delete project?

Are you sure you want to permanently delete this project? This action cannot be undone.

All devlogs, followers, and associated data will be removed.

Followers

Loading…