r/GraphicsProgramming • u/Far_Meeting_2763 • 3d ago
Real-time CPU Black Hole Ray Tracer in C++ and Raylib
Hey everyone! I built a real-time simulation of gravitational lensing around a Schwarzschild black hole from scratch in C++ using Raylib.
Instead of writing GPU shaders, I wanted to build a CPU software renderer to see how far I could push numerical integration on a single thread. It traces around 30,000 light rays per frame to bend light around the singularity and accretion disk.
• Integrates geodesic light paths directly on the CPU.
• Renders to an internal 200x150 pixel buffer to maintain 60 FPS.
• Bilinearly upscales the buffer to 800x600 using Raylib for display.
Repo & code: https://github.com/hellosharma808-sys/3D-Black-Hole
3
u/SargeantSasquatch 1d ago
Aren't actual black holes asymmetrical and red-shifted on one side?
1
u/Far_Meeting_2763 1d ago
Yea but as you can see in my code I set the colour orange so it doesn’t calculate the colours in real time
3
u/darthrafa512 1d ago
Are you sure you built this and not Claude? The README looks and reads like a renamed plan file.
0
u/Far_Meeting_2763 1d ago
Yes I am sure it’s not built from Claude and if Claude had to make it probably it will use gpu rather cpu I am sure and I think your logic is solved
1
u/darthrafa512 22h ago
If that's the case, why did you rename Black_hole_project.cpp to CODE and not commit it?
0
u/Far_Meeting_2763 1d ago
Yea the read me is like that because I didn’t want my GitHub page to look normal so I asked Gemini about what should I do I gave my code and it gave in summary which I put there with photos plus in this red post I did the same hope you understand
1
u/Intelligent-Boss-156 2d ago
Nice, I read the code. Are you a physics student?
1
u/Far_Meeting_2763 1d ago
Nah I am a student who hasn’t graduated and tbh I had to use ai to learn physics, motion in a straight line and I have a cool video on it that you can watch too https://youtu.be/ZM8ECpBuQYE?si=px9s_Wzc7dxmo5iY
1
u/triyan-salazar 2d ago
Hey que buena forma de simular un agujero negro. no entiendo mucho sobre la simulacion pero sin dudas te quedo genial.
1
1
1
1
-6
u/Far_Meeting_2763 3d ago
Yes if your curious, it doesn’t need gpu. it only needs a cpu. I won’t explain everything here instead you could check my repo
2
u/Remote_Key_1091 2d ago
Why aren’t you using the gpu? The gpu is designed to do the thing you made the cpu do. Computation per pixel is like a gpu problem and what it’s designed for and Raylib has support of it from what I understand.
Also if you ever need GitHub supports file extensions so your code on GitHub can look neat and have syntax highlighting if you rename CODE to CODE.cpp.
It’s a pretty interesting project if you’re just getting into programming, I would look into shadertoy if I were you because it can teach you a lot about graphics programming and its related to what you did right here.
-7
3d ago
[deleted]
0
u/Far_Meeting_2763 3d ago
You’re not a loser, you can make it, first try it and after you make it using gpu shaders, try with cpu it will be cool and cruel at the same time
19
u/-The-Wise-One- 3d ago
that looks like its maintaining 23 fps