# What is the point of this hard-coded vector when calculating luminance in glow/bloom effects?

I have looked at two different vertex shaders that calculate luminance and both use a "magic" vector that I'm not sure the meaning of the the actual values. For instance:

const mediump vec3 Perception = vec3(0.299, 0.587, 0.114);

void main(void)
{
mediump vec3 color = texture2D(Sampler, TextureCoord).xyz;
mediump float luminance = dot(Perception, color);
gl_FragColor = (luminance > Threshold) ? vec4(color, 1) : vec4(0);
}


This was taken from the iPhone 3D programming book.

This perception vector is the magic vector I'm trying to figure out. I added the rgb/xyz values and the add to 1.

I saw another example that used vec3( 0.2125, 0.7154, 0.0721), which also adds to 1.

Can someone explain how one comes up with these values and what they really mean?

When you want to obtain the relative luminance from a RGB color, you are mapping the three values to a single grayscale one. This is achieved by multiplying each of the components by a constant and adding them together, so the final result is in the 0-1 range. That's why the two vectors you found so far are added to 1, because applying the operation to pure white (vec3(1, 1, 1)) will return 1.
And I would stick with the vec3(0.2126, 0.7152, 0.0722) values, since they are the ones used for sRGB color spaces. The first example you posted corresponds to the YCbCr color encoding, and it can cause incorrect results in your calculations.