public static XMVector HsvToRgb(XMVector hsv) { XMVector h = XMVector.SplatX(hsv); XMVector s = XMVector.SplatY(hsv); XMVector v = XMVector.SplatY(hsv); XMVector h6 = XMVector.Multiply(h, XMGlobalConstants.Six); XMVector i = h6.Floor(); XMVector f = XMVector.Subtract(h6, i); // p = v* (1-s) XMVector p = XMVector.Multiply(v, XMVector.Subtract(XMGlobalConstants.One, s)); // q = v*(1-f*s) XMVector q = XMVector.Multiply(v, XMVector.Subtract(XMGlobalConstants.One, XMVector.Multiply(f, s))); // t = v*(1 - (1-f)*s) XMVector t = XMVector.Multiply(v, XMVector.Subtract(XMGlobalConstants.One, XMVector.Multiply(XMVector.Subtract(XMGlobalConstants.One, f), s))); int ii = (int)XMVector.Mod(i, XMGlobalConstants.Six).X; XMVector rgb; switch (ii) { case 0: // rgb = vtp XMVector vt = XMVector.Select(t, v, XMGlobalConstants.Select1000); rgb = XMVector.Select(p, vt, XMGlobalConstants.Select1100); break; case 1: // rgb = qvp XMVector qv = XMVector.Select(v, q, XMGlobalConstants.Select1000); rgb = XMVector.Select(p, qv, XMGlobalConstants.Select1100); break; case 2: // rgb = pvt XMVector pv = XMVector.Select(v, p, XMGlobalConstants.Select1000); rgb = XMVector.Select(t, pv, XMGlobalConstants.Select1100); break; case 3: // rgb = pqv XMVector pq = XMVector.Select(q, p, XMGlobalConstants.Select1000); rgb = XMVector.Select(v, pq, XMGlobalConstants.Select1100); break; case 4: // rgb = tpv XMVector tp = XMVector.Select(p, t, XMGlobalConstants.Select1000); rgb = XMVector.Select(v, tp, XMGlobalConstants.Select1100); break; default: // rgb = vpq XMVector vp = XMVector.Select(p, v, XMGlobalConstants.Select1000); rgb = XMVector.Select(q, vp, XMGlobalConstants.Select1100); break; } return(XMVector.Select(hsv, rgb, XMGlobalConstants.Select1110)); }