Friday, August 10, 2012

Refractive Lens Effect (1998)

In the '90s I really dug the demoscene.  Though I was never able to attend any parties, I would max out my BBS download quotas on all the demos I could lay my hands on.  Demos were always an inspiration to get better at coding, and learn about PC hardware.

In 1998, on a rainy afternoon, I decided to try my hand at writing a refractive lens effect somewhat like the one found in the Future Crew's Second Reality.  By now the demo had been out (and imitated) for many years, but hey, I was still working on the same 486, so better late than never.  (In a great twist of fate, I later wound up working at EA Montreal with a member of the Future Crew.)

The effect is very simple; a table of pointer offsets is precomputed, with one offset per pixel on the lens.  This table of pointer offsets can be thought of as being overlaid on top of the source image, at the lens position.  When rendering a given pixel on the lens, instead of a directly fetching the corresponding value in the source image, the precomputed offset is simply added to the raw address and the color value at that offset address is used instead.  For example, a precomputed offset of 1 will read the next pixel right; -1, the previous pixel, immediately to the left; 320, the next pixel down (since the screen is 320 pixels wide, with no padding/per-line stride); etc.  The offsets are precomputed to distort the source image as though it were being viewed through a refractive medium.


No comments:

Post a Comment