JavaScript EditorFree JavaScript Editor     Ajax Editor 



Main Page
Previous Page
Next Page

19.2. Mathematical Mappings

A common imaging operation supported by OpenGL fixed functionality is scale-and-bias. In this operation, each incoming color component is multiplied by a scale factor, and a bias value is added. You can use the result to map color values from one linear range to another. This is straightforward in the OpenGL Shading Language with the use of the standard math operators. You can do more complex mathematical mappings on pixel values with built-in functions such as pow, exp2, and log2.

The built-in dot product function (dot) can produce a single intensity value from a color value. The following code computes a CIE luminance value from linear RGB values defined according to ITU-R Recommendation BT.709 (the HDTV color standard):

float luminance = dot(vec3(0.2125, 0.7154, 0.0721), rgbColor);

This luminance mapping function is the standard used in manufacturing contemporary monitors, and it defines a linear RGB color space. The coefficients 0.299, 0.587, and 0.114 are often used to convert an RGB value to a luminance value. However, these values were established with the inception of the NTSC standard in 1953 to compute luminance for the monitors of that time, and they are used to convert nonlinear RGB values to luminance values. They do not accurately calculate luminance for today's CRT monitors, but they are still appropriate for computing nonlinear video luma from nonlinear RGB input values as follows:

float luma = dot(vec3(0.299, 0.587, 0.114), rgbColor);


Previous Page
Next Page




JavaScript EditorAjax Editor     JavaScript Editor