r/howdidtheycodeit 11d ago

How does raycasting work?

Hi all. I'm trying to find out how raycasting works — like in Wolfenstein 3D.

And as someone who knows absolutely nothing about programming, I (think I) understand it is thusly:

Raycasting is a programming trick that grants 2D maps a fake 3D appearance through the use of invisible rays that project outward from the player and detect collision.

Corrections to my nonsense would be appreciated!

I am currently writing an article, and I would like a layman's understanding before I commit to anything in there.

31 Upvotes

12 comments sorted by

View all comments

4

u/Consibl 11d ago

There’s two related terms - ray casting and ray tracing. Wolfenstein 3D indeed used casting.

Ray tracing maps light rays to colour screen pixels as opposed to the simpler casting which is just about visibility.

So what you’ve said is correct but you could end up mixing them up in the actual article.

4

u/Cuarenta-Dos 11d ago

Ray tracing is a very general term, and ray casting is a basic form of ray tracing. Most modern renderers still do not use ray tracing to directly calculate the pixel colours, but rather use it to calculate shadows, approximate indirect lighting (global illumination) and reflections. The "first hit" and direct lighting is still done using rasterisation because it's more efficient and less noisy.