31 lines
809 B
GLSL
31 lines
809 B
GLSL
/**
|
|
* Converts an RGB color to CIE Yxy.
|
|
* <p>The conversion is described in
|
|
* {@link http://content.gpwiki.org/index.php/D3DBook:High-Dynamic_Range_Rendering#Luminance_Transform|Luminance Transform}
|
|
* </p>
|
|
*
|
|
* @name czm_RGBToXYZ
|
|
* @glslFunction
|
|
*
|
|
* @param {vec3} rgb The color in RGB.
|
|
*
|
|
* @returns {vec3} The color in CIE Yxy.
|
|
*
|
|
* @example
|
|
* vec3 xyz = czm_RGBToXYZ(rgb);
|
|
* xyz.x = max(xyz.x - luminanceThreshold, 0.0);
|
|
* rgb = czm_XYZToRGB(xyz);
|
|
*/
|
|
vec3 czm_RGBToXYZ(vec3 rgb)
|
|
{
|
|
const mat3 RGB2XYZ = mat3(0.4124, 0.2126, 0.0193,
|
|
0.3576, 0.7152, 0.1192,
|
|
0.1805, 0.0722, 0.9505);
|
|
vec3 xyz = RGB2XYZ * rgb;
|
|
vec3 Yxy;
|
|
Yxy.r = xyz.g;
|
|
float temp = dot(vec3(1.0), xyz);
|
|
Yxy.gb = xyz.rg / temp;
|
|
return Yxy;
|
|
}
|