EncodeNormals
Description
Encodes a normal map image, assuming that all tangent-space normal vectors point upwards (i.e. the minimum blue channel value is 0.5
).
The pixels of the given normal map are interpreted as follows:
red :[0..1] => X:[-1 .. +1] green:[0..1] => Y:[-1 .. +1] blue :[0..1] => Z:[-1 .. +1]
The vector (X,Y,Z)
is then normalized to unit-length. The grayscale intensity I
is computed from the pixel in map (if not null
). The pixel P
of the resulting image is then computed like this:
map == null : P.red = X * 0.5 - 0.5 P.green = Y * 0.5 - 0.5 map != null : P.red = X * 0.5 - 0.5 P.green = I P.blue = Y * 0.5 - 0.5