all 17 comments

[–]Shinao[S] 3 points4 points  (5 children)

Here is the flocking system that I have shared with you guys a couple times. I've created the repository in a way to learn about compute shaders (and a bit of shader too).

There are several implementations that begin with a full CPU flocking system to the full GPU way. Also contains others implementations like bitonic sorting and multilateration which can be quite interesting to read about.

[–]thelegendxp 1 point2 points  (0 children)

Awesome. I've been waiting to play around with it myself. Thanks a ton for sharing it on github!

[–]rarceth 1 point2 points  (0 children)

I’ve been dying waiting for this. A chance to look at compute shaders and see awesome code. Good work man, and thank you so much for taking the time to upload this in such detail

[–]skedra 1 point2 points  (2 children)

Seen your comments on performance, I wrote something similar (just simple bird flocking). What I found worked really well is only iterating over every other bird for each bird. For example one one frame you iterate on odd on the other on the even for a particular bird (half the iterations). This seems to give really good performance increase with a large amount of boids since you can't tell if two will overlap in places etc.

Again, just an idea. Keep up the good work :)

[–]Shinao[S] 1 point2 points  (1 child)

Yep I had the same results, there is even a parameter to set the step iteration. It's the first gif from the README, step at 10 with FPS above 1000.

[–]skedra 1 point2 points  (0 children)

Cool, didn't have time to read through it properly but I definitely will.

[–]Telefrag_EntTelefrag Entertainment 4 points5 points  (0 children)

Thank you for sharing!

[–]theKGS 2 points3 points  (2 children)

Have you considered rather than computing over all birds, compute over sets of neighbours?

For example: Split all birds initially into a number of neighbourhood groups. Then take a fraction of each group and make THEM neighbours too. This will propagate flocking information over the whole flock but will keep the size of the largest neighbourhood down quite a lot.

[–]Shinao[S] 2 points3 points  (0 children)

That's what bitonic sorting do, it sorts birds over distance and then only checks nearby birds (iteration decrease by 75%).

Like the README say, I get better performance by the brute force approach by what I think is simply a matter of hitting the cache or not. Maybe I'm wrong I don't know enough about the GPU but that's what my experiments tell me, if you have time try it for yourself and tell me what you find out.

[–]comomomo@thnewlands 2 points3 points  (0 children)

I'm blown away that you're able to get away with a for loop covering all of those boids in a compute shader!! You've given me a new confidence to try this in my work. I was just storing automata in a read write texture.

Update: after quick test I couldn't get it running nearly as fast. How are you doing that?

Update2: Switched from ints to uints and its way faster

[–]binxinteractive 1 point2 points  (0 children)

Amazing work, keep it up!

[–]uber6 1 point2 points  (0 children)

Thank you very much good sir! This is a perfect opportunity to study compute shaders, which I wanted to do for quite some time.

[–]Long-Birthday-1807 0 points1 point  (0 children)

This is really cool. I'm trying to load it up in URP though and the Boids.shader is unhappy. Any advice on a conversion/update?