Пример #1
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);
        }
Пример #2
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);
            }
        }