Example #1
0
        /// <summary>
        /// For the incident vector I and surface normal N,
        /// and the ratio of indices of refraction eta,
        /// return the refraction vector.
        /// </summary>
        /// <param name="I"></param>
        /// <param name="N"></param>
        /// <returns></returns>
        public static Vec2f Refract(Vec2f I, Vec2f N, float eta)
        {
            //TODO: Use operatores instead of function madness.

            float dotValue = Dot(N, I);
            float k        = 1.0f - eta * eta * (1.0f - dotValue * dotValue);

            if (k < 0.0f)
            {
                return(Vec2f.Zero);
            }
            else
            {
                return(eta * I - (eta * dotValue + MathF.Sqrt(k)) * N);
            }
            //return eta * I - (eta * dotValue + MathFunctions.Sqrt(k)) * N;
            //TODO: Use operatores instead of function madness.
            //return Multiply(Subtract(Multiply(I, eta), (eta * dotValue + MathFunctions.Sqrt(k))), N);

            //return Multiply(Subtract(Multiply(I, eta),sdf), N);
            //return eta * I - (eta * dotValue + MathFunctions.Sqrt(k)) * N;

            // return eta * I - (eta * dotValue + MathFunctions.Sqrt(k)) * N;
        }
 public static float InverseSqrt(float f)
 {
     return((float)1.0f / MathF.Sqrt(f));
 }
Example #3
0
 public static unsafe float InverseSqrt(float x)
 {
     return(1.0f / MathF.Sqrt(x));
 }