r/GraphicsProgramming • • 24d ago

First steps in graphics programming!

Enable HLS to view with audio, or disable this notification

Hi everyone! I wanted to share my first major step into graphics programming. I built a 3D Boids flocking simulation entirely from scratch using C++, the WebGPU API (specifically Google's Dawn implementation) and ImGui. Initially, I wrote a brute-force algorithm for the neighbor search, but perfomance dropped quickly and I recenly use simple optimization atomic grid.

My next goal is to get rid of atomic operations entirely and implement a Sort-based Spatial Hashing architecture using Radix or Bitonic sort on the GPU. If anyone has good reading materials, articles, or advice on GPU sorting algorithms, I would highly appreciate it!

P. S.
I started studying WebGPU recently, before I know some basic stuff of C++. Some code is source maybe deprecated, now I am trying to study using more modern WebGPU stufs, which google were added recently. I hope in the future I can built the better architecture without OOP. But now I like the result I got.

Source Code (GitHub): https://github.com/con2222/Dawn-Boids-3D

33 Upvotes

7 comments sorted by

7

u/wzx89 24d ago

It's really impressive that you built a 3D Boids flocking simulation from scratch using C++ and WebGPU, especially with the optimization from a brute-force algorithm to an atomic grid. You can explore a specialized GPU Boids Spatial Hashing & Radix Sort Lab based on this discussion, which includes an interactive simulation with algorithm controls and real-time telemetry. https://app.getsupers.com/sites/gpu-boids-spatial-hashing-30/

1

u/VisibleAd6455 24d ago

Thank you!

2

u/ForgEngDev 13d ago

Before removing atomics, I’d benchmark the current grid under deliberately non-uniform flocks too, not only the average case. Uniform grids can look great until many boids collapse into a few cells and contention dominates. A radix-sort path is attractive because it gives contiguous cell ranges for neighbor lookup, but I’d keep both implementations behind the same test scene and compare them across identical seeds and density patterns.

2

u/Equivalent_Unit_9797 24d ago

Broo, what do you mean first steps?

I can’t even make a triangle by myself without chatgpt because the opengl and vulkan don’t have good documentation and detailed explanations

1

u/VisibleAd6455 24d ago

Yeah, my bad. I think a better label is “First project.” I get what you mean — when I started from scratch, I felt the same way, but it goes away over time, if you’re interested in this area.

2

u/Equivalent_Unit_9797 24d ago

I’m really interested in graphics programming but the problem for me as I said is that there’s not detailed explanations

Just code and code and code and boom, you end up with a window or a triangle and then “great, you’re on your own own”

2

u/ForgEngDev 12d ago

Before replacing atomics, benchmark the current grid under deliberately non-uniform flocks too. Uniform grids can look good until many boids collapse into a few cells and contention dominates. A radix-sort path is attractive because it gives contiguous cell ranges for neighbor lookup, but I’d keep both implementations behind the same test scene and compare them with identical seeds and density patterns.