Exemplo n.º 1
0
        public static Vektor refract(Vektor uv, Vektor n, double etai_over_etat)
        {
            var    cos_theta      = Math.Min(Vektor.dot(uv * -1, n), 1);
            Vektor r_out_perp     = etai_over_etat * (uv + cos_theta * n);
            Vektor r_out_parallel = -Math.Sqrt(Math.Abs(1 - r_out_perp.length_squared())) * n;

            return(r_out_perp + r_out_parallel);
        }
Exemplo n.º 2
0
 public static Vektor random_in_unit_disk()
 {
     while (true)
     {
         var p = new Vektor(Mathe.random_1Tom1(), Mathe.random_1Tom1(), 0);
         if (p.length_squared() >= 1)
         {
             continue;
         }
         return(p);
     }
 }
Exemplo n.º 3
0
        public static double hit_sphere(Vektor center, double radius, ray r)
        {
            Vektor oc           = r.Origin - center;
            var    a            = r.Direction.length_squared();
            var    half_b       = Vektor.dot(oc, r.Direction);
            var    c            = oc.length_squared() - radius * radius;
            var    discriminant = half_b * half_b - a * c;

            if (discriminant < 0)
            {
                return(-1);
            }
            else
            {
                return((-half_b - Math.Sqrt(discriminant)) / a);
            }
        }
Exemplo n.º 4
0
        public override zwischenSpeicher Hit(ray r, double t_min, double t_max, hit_record rec)
        {
            zwischenSpeicher zw = new zwischenSpeicher();
            Vektor           oc = r.Origin - center;
            var a      = r.Direction.length_squared();
            var half_b = Vektor.dot(oc, r.Direction);
            var c      = oc.length_squared() - radius * radius;

            var discriminant = half_b * half_b - a * c;

            if (discriminant < 0)
            {
                zw.IsTrue = false;
                return(zw);
            }
            var sqrtd = Math.Sqrt(discriminant);

            var root = (-half_b - sqrtd) / a;

            if (root < t_min || t_max < root)
            {
                root = (-half_b + sqrtd) / a;
                if (root < t_min || t_max < root)
                {
                    zw.IsTrue = false;
                    return(zw);
                }
            }

            rec.t = root;
            rec.p = r.at(rec.t);
            Vektor outward_normal = (rec.p - center) / radius;

            rec.set_face_normal(r, outward_normal);
            rec.mat_ptr = mat_ptr;

            zw.rec    = rec;
            zw.IsTrue = true;

            return(zw);
        }