Show HN: Boids Simulation
anoopelias.github.io
anoopelias.github.io
It also hammered home the problem of device/host memory reigions which you've got to deal with when doing GPU programming. I found that other, simpler, systems didn't manage to get as much speedup as Boids did, as transferring data, not computation, was where they bottlenecked. With Boids, by contrast, I could keep everything (computation, and rendering) on the GPU, and never even have to touch the CPU, aside from calling various CUDA and OpenCL functions.
I had run in to some performance issues, the initial few ticks are quiet slow even now, esp. on a phone.
This one uses a kdtree instead. I'll have to try quadtree and benchmark. Thanks.
If what you actually want to do is to have each boid be affected by each boid in a fixed-size neighbourhood, the best acceleration structure is actually just fixed-size bins.
All of a boid's "close enough" neighbours will be found in the 8-neighbourhood of its block.
Feels a good idea. Have to try it to know for sure.
Also instead of a square shaped range you can get a hexagonal range by dividing corner boxes diagonally to two and then checking which half of square the boid is. :)
I'm a TA for an AI-course at my uni, and this semester my students had to program a boids simulation for the first project. In addition to what's shown here, the boids also had to avoid obstacles and flee from predators. I think the students liked it, it's very rewarding to code and actually see the result.
The students also had to implement sliders, for how much cohesion, separation and alignment is weighted. It's pretty fun to change them and watch the behavior of the boids change.
https://developer.mozilla.org/en-US/docs/Web/API/window/requ...
It uses processing.js when I worked through it I just ended up implementing everything with canvas and making my own versions of the processing specific classes and functions needed.
I haven't looked deep in to these kind of simulations in general. Inspiration came from the Princeton Algortihms course in coursera.org. There is this sample problem, http://www.cs.princeton.edu/courses/archive/spr10/cos226/ass...
ThreeJS GPU boids simulation http://threejs.org/examples/#webgl_gpgpu_birds
The value initializes as 60, so it will show as 60 until it gets updated for the first time. Would that be what you are talking about?
The initial few seconds performance is not at optimum so that is a problem. Are you on a laptop or a mobile/tablet device?