private static Color CalculatePointColor(Ray ray, List <IIntersect> intersectables) { var minIntersect = double.MaxValue; Vector3D normalAtIntersection = new Vector3D(0, 0, 0); bool intersectionExists = false; foreach (var intersectable in intersectables) { var intersections = intersectable.GetIntersection(ray); if (intersections == null) { continue; } foreach (var intersection in intersections) { if (intersection < minIntersect) { intersectionExists = true; minIntersect = intersection; normalAtIntersection = intersectable.GetNormalAtIntersection(ray.GetPosition(minIntersect)); } } } if (intersectionExists) { Vector3D rgb = 255 * 0.5 * (normalAtIntersection + new Vector3D(1, 1, 1)); return(Color.FromArgb(1, (byte)rgb.X, (byte)rgb.Y, (byte)rgb.Z)); } // Interpolated Y Background (1-t)*255 *(Desired RGB 1) + t*255 (Desired RGB 2). Simplified ray.Direction.Normalize(); var t = (ray.Direction.Y + 1) * 0.5; return(Color.FromArgb(1, (byte)(255 * (1 - 0.5 * t)), (byte)(255 * (1 - 0.3 * t)), 255)); }