Пример #1
0
        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);
            }
        }
Пример #2
0
 public static XMVector AngleBetweenNormals(XMVector n1, XMVector n2)
 {
     return(XMVector4
            .Dot(n1, n2)
            .Clamp(XMGlobalConstants.NegativeOne, XMGlobalConstants.One)
            .ACos());
 }
Пример #3
0
        public static XMVector DotCoord(XMVector p, XMVector v)
        {
            //// Result = P[0] * V[0] + P[1] * V[1] + P[2] * V[2] + P[3]

            XMVector v3 = XMVector.Select(XMGlobalConstants.One, v, XMGlobalConstants.Select1110);

            return(XMVector4.Dot(p, v3));
        }
Пример #4
0
        public static XMVector Reflect(XMVector incident, XMVector normal)
        {
            //// Result = Incident - (2 * dot(Incident, Normal)) * Normal

            XMVector result = XMVector4.Dot(incident, normal);

            result = XMVector.Add(result, result);
            result = XMVector.NegativeMultiplySubtract(result, normal, incident);

            return(result);
        }
Пример #5
0
        public static XMVector AngleBetweenVectors(XMVector v1, XMVector v2)
        {
            XMVector l1  = XMVector4.ReciprocalLength(v1);
            XMVector l2  = XMVector4.ReciprocalLength(v2);
            XMVector dot = XMVector4.Dot(v1, v2);

            l1 = XMVector.Multiply(l1, l2);

            return(XMVector
                   .Multiply(dot, l1)
                   .Clamp(XMGlobalConstants.NegativeOne, XMGlobalConstants.One)
                   .ACos());
        }
Пример #6
0
 public static XMVector LengthSquare(XMVector v)
 {
     return(XMVector4.Dot(v, v));
 }
Пример #7
0
 public static XMVector Dot(XMVector p, XMVector v)
 {
     return(XMVector4.Dot(p, v));
 }
Пример #8
0
 public static XMVector Dot(XMVector q1, XMVector q2)
 {
     return(XMVector4.Dot(q1, q2));
 }