New demo uploaded: Wolfenstein 3D - raycasting demo with textures
Posted: Fri Mar 26, 2021 8:32 am
I wanted to illustrate what this shortcut does, so I took the starting screen from Jeffrey's demo and marked it up a bit in Paint. First, there would be four rays cast a using the normal method, marked here in red in the first file below. A is column 0, B is column 256, C is column 288, and D is column 304. Note that the display is only columns 0 to 303 so 304 is not actually displayed, just used for interpolation if possible.
The second image shows where the interpolation happens. Ray E is column 128. First, we check the high byte of the distance value array corresponding to this column; these will all be set to FF at the start of a screen and only changed if a ray is calculated. So in this case column E has not already been calculated. We look to the left and right, rays A and B, and see if they point to the same wall. They do not, so we cast the ray for E and move on to the next one, ray F in column 64.
Once again we check if this ray is already calculated, nope, and then check to the left and right, A and E. These two are not on the same wall, so we cast ray F and move on to ray G. Ray G, in column 192, has not been calculated yet (its distance high byte is still FF) so it checks to the left and right, rays E and B. These are not pointing to the same wall, so we cast ray G and move on to ray H.
Ray H is in column 32. We see that it has not been calculated yet, so we check to the left and right, columns A and F. These two rays are indeed pointing to the same wall, so we can interpolate all the rays in between A and F. Now if we go further down the list and find ourselves at a column that has already been interpolated, such as column 16, the high byte of its distance will no longer be FF, and that entry in the list is skipped.
These interpolated pixel columns are marked in yellow in the second image. Eventually ray Y (column 272) will be encountered, and comparing B and C shows that they are on the same wall so columns 257-287 are all interpolated. And when Z comes up on the list, all columns from 289-303 would be interpolated.
The third image shows all 39 columns that would have to be raycast as red vertical lines, and the 266 interpolated columns are shown in yellow across the bottom - an 87% reduction in the number of rays cast.
Edited to add: this is probably pretty representative of an average. 305/(log(305)/log(2)) ~ 37
startscreensmall2.bmp startscreensmall3.bmp startscreensmall4.bmp