The luminance calculated by following GLSL functions (fragment shaders - tonemap) has different value:
float GetLuminance (vec3 rgb)
{
return (0.2126 * rgb.x) + (0.7152 * rgb.y) + (0.0722 * rgb.z);
}
vec3 RGB2xyY (vec3 rgb)
{
const mat3 RGB2XYZ = mat3(0.4124, 0.3576, 0.1805,
0.2126, 0.7152, 0.0722,
0.0193, 0.1192, 0.9505);
vec3 XYZ = RGB2XYZ * rgb;
return vec3(XYZ.x / (XYZ.x + XYZ.y + XYZ.z),
XYZ.y / (XYZ.x + XYZ.y + XYZ.z),
XYZ.y);
}
I used a glm library to calculate an example result. For glm::vec3(2.0f, 3.0f, 8.0f) GetLuminance returns 3.1484. RGB2xyY returns glm::vec3 which z component is equal 3.8144. What is wrong ?