Sketch · 2026-10-16
Grid raycaster, one ray per column.
The left view is not 3D. It is 320 vertical lines, one for each ray fired from the player across a flat grid. Each line is drawn taller when its ray hits a wall sooner. The map on the right is the whole world. Click it to add or remove walls, and the corridor in front of you changes on the next frame.
- rays this frame
- 0
- cells visited by DDA
- 0
- samples, fixed 0.02 step
- 0
- centre ray distance
- 0
Click the view, then WASD or arrows. Shaded cells on the map are the ones the centre ray checked.
Note
The trick depends on two restrictions. Every wall fills a whole grid cell, and every wall has the same height on a flat floor. Under those rules a screen column can show at most one wall slice, so one ray per column is enough. Wolfenstein 3D shipped on that idea in 1992 and ran on a 286.
The ray does not creep forward in small steps. It jumps from one grid line to the next, always choosing whichever of the next vertical or horizontal line is closer. This is the DDA traversal Amanatides and Woo described for voxel ray tracing in 1987. Each jump costs an add and a compare, and it can never step over a corner. The stats compare it with a naive march at a step of 0.02 cells. The march takes 50 samples per cell of distance, while the DDA visits at most about 1.4 cells per cell of distance, so it does roughly 30 times less work and still cannot miss a corner.
Switch off the fisheye fix and a straight wall bows outward. The rays at the edge of the screen travel further to reach the same flat wall, so they draw it shorter. The fix is to use the distance measured along the view direction instead of along the ray, which is the true distance times the cosine of the ray's angle. Here the rays are built from a direction vector plus an offset along a camera plane, and that perpendicular distance falls out of the DDA for free.
Side shading darkens walls that a ray hits on a horizontal grid line. It is the only lighting here, and without it corners vanish into flat colour. Push the field of view past 120 degrees to see why games settle near 60 to 90: the projection is a flat plane, and a flat plane stretches everything near its edges.
Sources
- Amanatides, J. and Woo, A. (1987). A Fast Voxel Traversal Algorithm for Ray Tracing. Eurographics '87, pages 3-10.
- Vandevenne, L. Lode's Computer Graphics Tutorial: Raycasting. lodev.org/cgtutor/raycasting.html
- Sanglard, F. (2017). Game Engine Black Book: Wolfenstein 3D. Self-published.