RasterCore
Ready to execute

Hardware Heritage

The software lens effect was a masterclass in coordinate distortion. It simulates light passing through a curved glass surface by mathematically warping the pixels of a background image.

PC VGA Tables

Software lenses were a PC VGA staple. The math for a sphere's surface was too slow for real-time, so programmers pre-calculated an offset table (LUT). Drawing the lens was simply a matter of copying pixels from the background using these offsets.

Amiga Sprites

Amiga coders often used large hardware sprites or the Copper to create "fake" lenses. By shifting the display window or the palette, they could create the illusion of magnification without the per-pixel cost of a software LUT.

Modern Ray-Cast

The code calculates the hemispherical normal of the lens at every fragment. This normal is then used to refract the UV coordinates, providing a mathematically perfect glass simulation.

Glass Lens

Real-time distortion and magnification.

Legacy C (LUT)

// Precalc sphere offsets
for(y=-R; y < R; y++)
  for(x=-R; x < R; x++)
    offsetTab[x][y] = (x * mag) / sqrt(R*R - x*x - y*y);

Modern GLSL

float z = sqrt(r*r - d*d);
vec2 refr = (p - pos) * (1.0 - z/r);
uv -= refr * 0.5;