Exemple #1
0
        private static Tuple<LightStrength, double> CalculateLighting(IGeometry[] spheres, Vector3D directionToEye, Vector3D surfaceNormal, Material sphere, Vector3D intersectionPoint, Light light)
        {
            var directionToLight = light.CenterPoint - intersectionPoint;
            directionToLight.Normalize();
            var lightT = (light.CenterPoint.X - intersectionPoint.X)/directionToLight.X;
            var blocked = spheres.Any(s => ObscuresLight(s, intersectionPoint, directionToLight, lightT));
            if (blocked)
            {
                return Tuple.Create(LightStrength.Zero,0.0);
            }

            var ldotn = Math.Max(0.0,Vector3D.DotProduct(surfaceNormal, directionToLight));
            var diffuse = light.Brightness*ldotn;
            var H = directionToLight + directionToEye;
            H.Normalize();
            var ndoth = Math.Max(0.0,Vector3D.DotProduct(surfaceNormal, H));
            var specular = Math.Pow(ndoth, sphere.Shinyness);
            return Tuple.Create(diffuse, specular);
        }