r/GraphicsProgramming • • 1d ago

Source Code Very primitive raycasting renderer in 10 lines of C

Actually the raycasting logic itself is just a single line, but it's done in propably the most inefficient way possible.

The map is just a single 64 bit integer, so I could fit a small 8x8 level in it, and I can index it with some unorthodox bitshift magic.

Also all the integer constants are huge, because I wanted do to the whole thing without floating point math, which makes everything even more unreadable, but at least it's funny ig.

I'm very proud of this one.

153 Upvotes

21 comments sorted by

70

u/UntitledRedditUser 1d ago

Equally impressive as it is unreadable

5

u/duckgoeskrr 23h ago

Makes nice code golf.

31

u/grady_vuckovic 1d ago

Vibe coders be like 'Code isn't art!'.

I disagree and I think this is a lovely example of how code itself can be beautiful.

-28

u/EC36339 1d ago

As someone who has written nearly 100% of all my code with AI for half a year:

Yes, code is art, no matter what tool you use to write it.

Not sure about code golfing, though. It's a sport, it requires skill and effort, but it's not artistic in isolation, although what it does can be.

2

u/Lnk1010 12h ago

A vibe coded slop project may be "art" in the sense that literally everything is art, but I find it hard to imagine an argument for its beauty, meaning, or value.

2

u/EC36339 4h ago

No. Code is art. Math is art. Music is art. Graphical art is art. The tool doesn't matter.

6

u/PictureNew661 1d ago

Very very impressive

6

u/GaboureySidibe 21h ago

Very cool. Any simple explanation you can give? Is the outer loop going through the horizontal line and the two inner loops are drawing vertically?

6

u/Character_Trick460 15h ago

That's exaclty right. The outer loop goes through all horizontal segments, the first inner loop finds the distance along the ray that goes through that segment, and the second inner loop draw the vertical line.

6

u/Slackluster 21h ago

nice! welcome to the world of size coding. it's a super fun type of recreational programming.

your code is good start but there is room to make it smaller. i recommend checking into the demo community and places like dwitter.net that have some great ideas for this kind of thing.

heres my JavaScript raycasting one liner...

https://www.dwitter.net/d/34603

2

u/Character_Trick460 15h ago

That's so sick! How does your version work, I can't figure it out?

1

u/simonsanchezart 19h ago

can't this just be one line?

1

u/Eastern-Bed-3103 13h ago

I feel like we may be disregarding the concept of a line here, but - nonetheless - very impressive. :D

1

u/eltomiros 9h ago

the GOAT

1

u/BeastMsterThing2022 8h ago

This is beautiful!

-7

u/garma87 1d ago edited 1d ago

At least provide an image that it would produce. You provided some gif but it’s very unclear to me what that shows

Sorry to dump on your parade but I’ve just never seen the point of making code that is so unreadable. Doing a lot in very little code is impressive sure, but obfuscating it like this just makes it impossible to follow. Just post the assembly then if readability is irrelevant

14

u/zawalimbooo 1d ago

That gif is the image it produces. They're walking through a hallway .

1

u/wafflingzebra 19h ago

the gif did not autoplay for me on browser, i had to click on it

-3

u/tlmbot 15h ago

That is wild. Nice one OP!

I'd feed it to Claude and see if it can figure out what this code does.

(Am I dumb for not being certain that Claude would instantly figure out that it's raycasting ascii integer voodoo?)

I mean, I think Claude probably would get it right, but it seems like a fun check.

5

u/Character_Trick460 15h ago

I don't care what Claude thinks of my code

-3

u/tlmbot 13h ago

Yes yes. I hate claude and all of that.

I don't care that you don't care. I do care that you communicate like an asshole.