Ejemplo n.º 1
0
        public bool hit(Ray r, float t_min, float t_max, ref HitRecord rec)
        {
            HitRecord temp_rec       = new HitRecord();
            bool      hit_something  = false;
            float     closest_so_far = t_max;

            foreach (Hitable h in this.hitableList)
            {
                if (h == null)
                {
                    continue;
                }
                if (h.hit(r, t_min, closest_so_far, ref temp_rec))
                {
                    hit_something  = true;
                    closest_so_far = temp_rec.t;
                    rec            = temp_rec;
                }
            }
            return(hit_something);
        }
Ejemplo n.º 2
0
        Vector3 Color(Ray r, HitableList world, int depth)
        {
            HitRecord rec = new HitRecord();

            if (world.hit(r, 0.001f, float.MaxValue, ref rec))
            {
                Ray     scattered   = null;
                Vector3 attenuation = new Vector3(0, 0, 0);
                if (depth < 50 && rec.mat.scatter(r, rec, ref attenuation, ref scattered))
                {
                    return(attenuation * Color(scattered, world, depth + 1));
                }
                else
                {
                    return(new Vector3(0, 0, 0));
                }
            }
            else
            {
                Vector3 unitDirection = Vector3.Normalize(r.Direction());
                float   t             = 0.5f * (unitDirection.Y + 1.0f);
                return((1.0f - t) * new Vector3(1.0f, 1.0f, 1.0f) + t * new Vector3(0.5f, 0.7f, 1.0f));
            }
        }