예제 #1
0
        public Tuple ColorAt(World w, Ray r, int remaining)
        {
            List <Intersection> intersections = w.Intersection(r);
            Intersection        intersection  = Intersection.Hit(intersections);

            if (intersection == null)
            {
                return(Tuple.Color(0, 0, 0));
            }
            Computation comps = new Computation(intersection, r, intersections);

            return(ShadeHit(w, comps, remaining));
        }
예제 #2
0
        /// <summary>
        /// Finds color value given a Ray and Scene
        /// Use this method for outside calls to find color value.
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="ray"></param>
        /// <returns></returns>
        public Color ColorAt(Ray ray, int remaining = reflectionBounces)
        {
            Color resultColor = Color.Black;
            Scene scene       = this;

            List <Intersection> intersections = scene.Intersections(ray);

            Intersection hit = Intersection.Hit(intersections);

            if (hit == null)
            {
                return(resultColor);
            }

            Computation comp = new Computation(hit, ray);

            resultColor = ShadeHit(comp, remaining);

            return(resultColor);
        }
예제 #3
0
        /// <summary>
        /// Determines if a point is in shadow
        /// Legacy. Will Remove. Doesn't pass object blocking light.
        /// </summary>
        /// <param name="point"></param>
        /// <param name="light"></param>
        /// <returns></returns>
        public bool IsShadowed(Point point, Light light) // LEGACY
        {
            // this needs to work for every light in the scene
            Scene scene = this;

            Vector3 pointToLight = light.Position - point;
            float   distance     = pointToLight.Magnitude();
            Vector3 direction    = pointToLight.Normalized();

            Ray ray = new Ray(point, direction);

            List <Intersection> intersects = scene.Intersections(ray);
            Intersection        hit        = Intersection.Hit(intersects);

            //Do we have a hit and is it within the distance to the light?
            if (hit != null && hit.t < distance)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }