Saturday, August 18, 2012

Moire Effect (1999)

In 1999, when starting university, I was still operating on somewhat older hardware (a pentium 133 and a 486/66, where most roommates had 400-500 MHz machines).  This being as it was, there were still a number of interesting demoscene effects I hadn't written up for myself, and I was still interested in learning about them.  On a rainy afternoon I tried my hand at writing a moiré effect.

The technique is pretty simple: a giant sprite is precomputed where the value of the color of a pixel is the radius from the center of the sprite, times a scalar constant to control radius, mod 32.  This yields a picture whose colour values consist of concentric rings with values increasing from 0 to 31, then 0 through 31 again, etc.  The palette is configured to consist of a gradient from black to white in colors 0 through 15, then white back to black in 16 to 31, so a single copy of the sprite rendered to the screen essentially looks like a series of concentric blurry circles.

At runtime, two copies of this sprite are offset in a simple moving pattern, and they are XORed into the framebuffer.  The XOR operation always a yields a value between 0 and 31, keeping the resulting colors in the frame buffer within the range of the preconfigured palette.  This yields the pattern which can be seen in the following movie.

No comments:

Post a Comment