r/GraphicsProgramming • u/Terrible_Shoulder667 • 11d ago
Source Code Vector field simulation with my own math library and Vulkan!
I made a small vector field visualizer in C# with Vulkan through Silk.NET.
You type some 2D field, for example F(x, y) = [x,sin(y)] and it draws the flow with particles.
How it works:
- Formula is parsed and compiled at runtime into one fast delegate, so evaluting the field for every particle each frame is light
- 1,200 to 6,000 particles depending on window size, integrated with RK4 on the CPU, each with a 24-point trail
- Everything is drawn as colored with one tiny shader and 4x MSAA
All the math comes from Epsilon - my symbolic math library for .NET that I'm working on.
- Simulation: https://github.com/XBambinoX/VectorField
- Library(C#): https://github.com/XBambinoX/Epsilon
AI disclosure: I used AI assistants to help write parts of the simulation code and fix bugs in my library.
4
u/otheyhigh 11d ago
That’s very cool. First thought that came to my mind was “that would be pretty neat to use as a base for an audio visualizer”.
4
u/Terrible_Shoulder667 11d ago
Thanks! Btw that's actually a great idea. The field can already depend on time t, so it'd mostly be a matter of feeding audio features like loudness or bass energy into the formula as extra varibles. That's where the Fourier transform comes in, and an FFT-driven version could be a nice demo. 🙌
2
u/otheyhigh 9d ago
It definitely sounds like a cool undertaking. One way I thought of was to use NAudio in C# to intercept the OS level audio output. The raw stream can be passed to ffmpeg to convert it into frequency data. This, I assume is what you would need to use the transform and get the rendering inputs.
ffmpeg does have features to output waveforms. But I have mostly ever used the bitmap/image outputs. Also does not have FFT filter specifically.
3
2
u/RenderTargetView 11d ago
I guess Lorenz attractor would look very cool
2
u/Terrible_Shoulder667 10d ago
Yeah! It's a 3D system though and the viewer is 2D for now, but a 3D mode is on my list, and Lorenz would definitely be the first test!
•
u/AutoModerator 11d ago
Recently updated rules. Please check that your post is in compliance with Rules 1, 4, 5, and 6 on the sidebar. TL;DR:
No showcases.
Disclose AI usage in post or project.
Present a topic to talk about, e.g. how something works.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.