public static XMVector RefractV(XMVector incident, XMVector normal, XMVector refractionIndex) { //// Result = RefractionIndex * Incident - Normal * (RefractionIndex * dot(Incident, Normal) + //// sqrt(1 - RefractionIndex * RefractionIndex * (1 - dot(Incident, Normal) * dot(Incident, Normal)))) XMVector zero = XMVector.Zero; XMVector incidentDotNormal = XMVector4.Dot(incident, normal); // R = 1.0f - RefractionIndex * RefractionIndex * (1.0f - IDotN * IDotN) XMVector r = XMVector.NegativeMultiplySubtract(incidentDotNormal, incidentDotNormal, XMGlobalConstants.One); r = XMVector.Multiply(r, refractionIndex); r = XMVector.NegativeMultiplySubtract(r, refractionIndex, XMGlobalConstants.One); if (XMVector4.LessOrEqual(r, zero)) { // Total internal reflection return(zero); } else { // R = RefractionIndex * IDotN + sqrt(R) r = r.Sqrt(); r = XMVector.MultiplyAdd(refractionIndex, incidentDotNormal, r); // Result = RefractionIndex * Incident - Normal * R XMVector result = XMVector.Multiply(refractionIndex, incident); result = XMVector.NegativeMultiplySubtract(normal, r, result); return(result); } }
public static bool LessOrEqual(XMVector c1, XMVector c2) { return(XMVector4.LessOrEqual(c1, c2)); }