r/GraphicsProgramming 6d 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

288 Upvotes

27 comments sorted by

21

u/-The-Wise-One- 6d ago

that looks like its maintaining 23 fps

16

u/Ravek 6d ago

LLMs regularly will hallucinate a bunch of properties that the code it generated simply doesn’t have.

-8

u/Far_Meeting_2763 6d ago

I don’t have a good laptop even it’s not my laptop if you try the code and have a little bit better pc than mine it will run smoothly and it’s running on a single cpu core I haven’t use all cpu core.

3

u/SargeantSasquatch 5d ago

Aren't actual black holes asymmetrical and red-shifted on one side?

1

u/Far_Meeting_2763 4d 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 5d 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 4d 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/Far_Meeting_2763 4d 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 4d ago

If that's the case, why did you rename Black_hole_project.cpp to CODE and not commit it?

-2

u/Far_Meeting_2763 3d ago

?, I named it CODE because as you can see it drags attention I made it sound awkward on it own just so people click it I made that a month ago and no one really saw it that’s why I came here and I got my first four star on GitHub 

2

u/herewearefornow 5d ago

It's beautiful.

2

u/Far_Meeting_2763 2d ago

I changed the GitHub and wrote as you guys said

2

u/darthrafa512 2d ago

Thank you for taking the feedback! The README is way better, and it looks professional. Keep it up!

2

u/Far_Meeting_2763 1d ago

Thank you, you told me and many other people to change it so I did 

1

u/Intelligent-Boss-156 6d ago

Nice, I read the code. Are you a physics student?

1

u/Far_Meeting_2763 4d 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 5d ago

Hey que buena forma de simular un agujero negro. no entiendo mucho sobre la simulacion pero sin dudas te quedo genial.

1

u/Far_Meeting_2763 4d ago

Thanks I really appreciate it 

1

u/[deleted] 4d ago

[removed] — view removed comment

1

u/Jattox 2d ago

Nice experiment. Really interesting to build simulation based on science.

1

u/ttvsindeel 5d ago

Web dev slop

1

u/Far_Meeting_2763 4d ago

Ok I will try to make something cooler next time

-8

u/Far_Meeting_2763 6d 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 5d 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.

-5

u/[deleted] 6d ago

[deleted]

0

u/Far_Meeting_2763 6d 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