// Algorithm can be found in the following sources // http://en.wikipedia.org/wiki/CIEXYZ #include "ColourSpaceXYZ.cgfx" float3 XYZ_To_xyY(float3 _XYZ) { float XplusYplusZ = _XYZ.x+_XYZ.y+_XYZ.z; XplusYplusZ = max(XplusYplusZ, 0.001f); return float3(_XYZ.x/XplusYplusZ, _XYZ.y/XplusYplusZ, _XYZ.y); } float3 xyY_To_XYZ(float3 _xyY) { return float3((_xyY.z/_xyY.y)*_xyY.x, _xyY.z, _xyY.z/_xyY.y*(1.f-_xyY.x-_xyY.y)); } float3 RGB_To_xyY(float3 _rgb) { return XYZ_To_xyY(RGBToXYZ(_rgb)); } float3 xyY_To_RGB(float3 _xyY) { return XYZToRGB(xyY_To_XYZ(_xyY)); } half3 h_XYZ_To_xyY(half3 _XYZ) { half XplusYplusZ = _XYZ.x+_XYZ.y+_XYZ.z; XplusYplusZ = max(XplusYplusZ, 0.001h); return half3(_XYZ.x/XplusYplusZ, _XYZ.y/XplusYplusZ, _XYZ.y); } half3 h_xyY_To_XYZ(float3 _xyY) { return half3((_xyY.z/_xyY.y)*_xyY.x, _xyY.z, _xyY.z/_xyY.y*(1.h-_xyY.x-_xyY.y)); } half3 h_RGB_To_xyY(half3 _rgb) { return h_XYZ_To_xyY(h_RGBToXYZ(_rgb)); } half3 h_xyY_To_RGB(half3 _xyY) { return h_XYZToRGB(h_xyY_To_XYZ(_xyY)); }