예제 #1
0
        private MyColor traceRay(Ray ray, int rayDepth, bool isInShape)
        {
            //Determine if we hit anything
            RayIntersectionResult intersectResult = scene.IntersectRay(ray);

            if (intersectResult == null)
            {
                return(scene.backgroundColor);
            }

            //Get the primary color (using the illumination model) of what we hit
            bool    isInShadow   = isPointInShadow(intersectResult.intersectionPoint);
            MyColor primaryColor = getColorAtPoint(intersectResult.intersectedShape, intersectResult.intersectionPoint, isInShadow);

            //If we've hit the max ray depth, stop.
            if (rayDepth >= MAX_RAY_DEPTH)
            {
                return(primaryColor);
            }

            MyColor reflectionColor = new MyColor();
            MyColor refractionColor = new MyColor();

            //Trace reflection ray
            if (intersectResult.intersectedShape.reflectionAmount > 0)
            {
                Ray reflectionRay = getReflectionRay(intersectResult.intersectedShape, intersectResult.intersectionPoint, ray);
                reflectionColor = traceRay(reflectionRay, rayDepth + 1, isInShape);
            }

            //Trace refraction ray
            if (intersectResult.intersectedShape.refractionAmount > 0)
            {
                Ray refractionRay = getRefractionRay(intersectResult.intersectedShape, intersectResult.intersectionPoint, ray, isInShape);
                refractionColor = traceRay(refractionRay, rayDepth + 1, !isInShape);
            }

            return(primaryColor * intersectResult.intersectedShape.ownColorAmount +
                   reflectionColor * intersectResult.intersectedShape.reflectionAmount +
                   refractionColor * intersectResult.intersectedShape.refractionAmount);
        }
예제 #2
0
 public Scene()
 {
     shapes          = new List <Shape>();
     backgroundColor = new MyColor();             //Constructor defaults to black
 }
예제 #3
0
 public static System.Drawing.Color ToSystemColor(MyColor c)
 {
     return(System.Drawing.Color.FromArgb(Convert.ToByte(c.red * 255), Convert.ToByte(c.green * 255), Convert.ToByte(c.blue * 255)));
 }