Normal Coding

I tried my hand at some basic normal coding methods, this was my result...



You can download the program here if you want to try it out, just move your mouse around and it should animate.

The program goes through 3 basic steps.

Step 1 - Convert the image into normals

The image is converted into a set of normalized normal vectors (thats fun to say) and stored in a vector structure, one for each pixel in the source image.

Step 2 - Encode the normals

Each normal is encoded down into 8 bits. 4 bits for the x value (xe, and 4 bits for the y value (ye. The two encoded values are then stuck into a single byte using (xe << 4) | ye. These bytes are used as palette indexes in an 8 bit indexed image of the same size as the source image.

Step 3 - Light it Up

The mouse position relative to the center of the window is used as the lighting vector, and this vector is applied to each of the 256 unique normals.

Since the image is indexed, any change to the palette will result in a change in all pixels in the image that use that palette index. This is a powerful concept, as it means that the calculations will be just as fast no matter what size your destination image is. Their will always be 256 values to calculate.