[1/2] this is one crazy impressive piece of work: /u/Heinz2001 spent *ten years*...

@vga256@tomodori.net

[1/2] this is one crazy impressive piece of work:

/u/Heinz2001 spent *ten years* researching, disassembling, and rewriting dozens of lines of Ultima Underworld's bytecode (and underlying assembly) in order to correct an extremely goofy flaw in UW's 3d renderer.

the code and binary patch for win/linux:
github.com/SiENcE/uwpatch

the explanation:
Ultima Underworld used an "affine" texture mapper. to draw a brick wall stretching into the distance away from you, it draws each pixel of the texture in linear steps, by adding a textured pixel of brick for each step into the distance. because it relies on addition and subtraction to calculate distances and the number of pixels to use, it's very very fast. (if you've played PS1 games, it used this method for many games to pull off fast textured rendering too.) why addition and subtraction? because they purely rely on 2d space: x and y coordinates, and toss out the z coordinate. in effect: it's 2d rendering!

the problem with affine texture rendering is that it creates hilariously weird warpage in certain situations, especially when it comes to walls close to the camera. the left two screenshots show the warpage you get from affine calculations. when you lose the z (depth) coordinate, you lose visual accuracy.

in comes the patch: with "perspective" texture mapping, the z-coordinate (depth) is used in the calculation. this is computationally *expensive*. every time the renderer needs to determine which pixel to paint to a polygon, it must divide by 'z' three times. division kills rendering speed like you wouldn't believe, and this is why UW never used it. the target recommended machine was a 386 DX-25 mhz. the screenshots on the right show the perspective-corrected texture mapper: they look how we'd expect a wall to look.

this wikipedia entry does a perfectly cromulent job of explaining how affine and perspective texture mappers work, if you want to read some of the underlying math involved:
en.wikipedia.org/wiki/Texture_

#ultima #retrocomputing #programming