G3dNormalCoding.mesa
Copyright Ó 1989, 1992 by Xerox Corporation. All rights reserved.
Glassner, March 10, 1989 11:21:10 am PST
Jules Bloomenthal July 15, 1992 10:43 pm PDT
DIRECTORY G3dBasic, Random;
G3dNormalCoding: CEDAR DEFINITIONS
~ BEGIN
This module contains support routines for converting normalized vectors to or from 8-bit integers. This is useful for interactive tools that perform shading via the colormap; each entry in the colormap corresponds to a particular normal. Once each colormap entry is filled with the shade for its associated normal, the picture in the frame buffer will appear shaded.
Encoding and decoding is pretty easy, as described below. When the implementation is run, the start code will build the normal-to-8-bit-integer and 8-bit-integer-to-normal tables.
See the documentation for an explanation of the implementation.
Basic Types
Triple:     TYPE ~ G3dBasic.Triple;
RandomStream:   TYPE ~ Random.RandomStream;
Procedures
EncodeAllNormals: PROC [context3d: Context3d];
Replace the (presumably just rendered) image in context with
an 8-bit image containing an encoded normal for each pixel.
EncodeNormal: PROC [dx, dy: REAL, dither: BOOL ¬ TRUE, userRS: RandomStream ¬ NIL]
RETURNS [pval: INT];
Convert a single normal into an 8 bit representation, pval, which is a number in [6..254].
dx and dy are the x and y components of the unit-length vector to be encoded.
If dither, low-level noise is added to the normal; otherwise sharp quantization borders result.
The client's own random stream for dithering can be optionally provided.
DecodeNormal: PROC [pval: INT] RETURNS [Triple];
Convert an 8 bit representation into a unit length normal. The normal is a quantized triple;
averaging a small region around the pixel of interest will result in a smoother set of normals.
IsValidNormalIndex: PROC [index: INT] RETURNS [BOOL];
Check that the normal index is within a proper range. [6..254] are reserved pixel values.
This procedures returns TRUE iff the input pixel value can be an encoded normal.
This avoids interrogations of pixels that belong to the background or in use by a tool.
END.