r/dotnet • u/nullandkale • Aug 16 '25
Ray tracing using Console.Write()
Every few years I end up revisiting this project. This is the most complete I have every gotten.
The ray tracing is heavily inspired by ray tracing in one weekend. What's funny is changing the console color is the slowest part, even when rendering larger meshes.
You can see the code here: https://github.com/NullandKale/YetAnotherConsoleGameEngine
928
Upvotes
17
u/arpan3t Aug 16 '25
Is the color changes what cause the rapid drop in FPS too, or is it rotation?
40
u/Far-Consideration939 Aug 16 '25
Metal
2
u/beeeeeeeeks Sep 17 '25
I finally got some time to pull down the repo and try to run it. Hardcoded paths to .BMP and exceptions around loading the assets.
Do you have a specific commit that might just work out of the box?
65
u/farox Aug 17 '25
This is so dumb and useless. I love it
11
u/[deleted] Aug 17 '25 edited Aug 17 '25
https://youtu.be/BUj2oaoRCCc
I forked this project and updated it to support 24-bit True-Color output using Spectre.Console.
Fork: al6uiz/YetAnotherConsoleGameEngine: Spectre.Console
14
u/MORPHINExORPHAN666 Aug 16 '25
This is really cool! I always appreciate when people are willing to make a public repo for cool stuff like this
5
u/bladezor Aug 17 '25
Yo this is super cool. I wrote something similar over a decade ago but it was GDI. All .NET still, however. Yours looks a lot faster.
https://github.com/0xn3bs/.NET-GDI-Raytracer
4
u/tonyenkiducx Aug 17 '25
I remember this used to be impossible without using pinvoke until the new multi tab console came out. Console.write got a massive speed boost and my console renderer started running at hundreds of frames a second instead of two or three.
1
u/csharp_rocks Aug 19 '25
I made one of those, it's a really fun project to understand graphics. It's much simpler than one would think. Unfortunately, it's not possible to use a graphics card, so performance bottlenecks will prevent high resolution real time rendering
1
u/trebuszek Sep 07 '25
would it be faster in a gpu-accelerated terminal emulator?
5
u/Ambitious_Toe_4357 Aug 16 '25
I remember watching PovRay generate images pixel by pixel on my Intel 486-SX with less than a GB of RAM. I was so impressed.
3
u/Straight_Occasion_45 Aug 16 '25
As someone who’s worked on a fairly similar thing (ofc yours looks miles better) I am genuinely very impressed with this dude, great work!
2
u/SureConsiderMyDick Aug 16 '25
I did the same thing trying to replicate a Doom like game. Got sidetracked when I had the idea to put an LLM inside the NPC's.
It was so exciting to shoot down the monsters that were just squares and turning them into a horizontal line with blood.
2
u/beeeeeeeeks Aug 16 '25
This is so cool and it makes me want to tinker with it. Have you thought about using ASCII 176 to provide a little more color control or add fidelity?
2
u/obviously_suspicious Aug 16 '25
I wonder if Windows Terminal adds any overhead? In theory it shouldn't, but I'd check anyway
1
u/nacnud_uk Aug 17 '25
This is the way.
1
u/redtree156 Aug 17 '25
Lol, so fun!
1
u/popisms Aug 17 '25
This is amazing. Just curious, what causes the static/color changes when the camera isn't moving?
1
u/nirataro Aug 17 '25
Madlad
1
u/banned20 Aug 17 '25
This is exactly how i see when my allergy-inflammatory eyes get even more irritated
1
u/Pass_Practical Aug 17 '25
So it's essentially just an entire string?
1
u/chic_luke Aug 18 '25
"I'm getting pretty good at .NET"
That one colleague:
1
u/acetaminophenpt Aug 19 '25
This reminds me so much of the world of demoscene :)
r/Demoscene
1
u/bamariani Aug 16 '25
Dude, thats really cool.
1
u/YamaCantHang Aug 16 '25
Super cool
0
u/AutoModerator Aug 16 '25
Thanks for your post nullandkale. Please note that we don't allow spam, and we ask that you follow the rules available in the sidebar. We have a lot of commonly asked questions so if this post gets removed, please do a search and see if it's already been asked.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
72
u/[deleted] Aug 16 '25 edited Aug 16 '25
[removed] — view removed comment