Example #1
0
        private ColorVector GetLightingColor(PosVector point, PosVector normal)
        {
            var lightColor = new ColorVector();

            foreach (var light in Scene.Lights)
            {
                // if not shaded
                if (IsViewable(light.Position, point))
                {
                    var lightVector = light.Position - point;
                    lightColor = lightColor + (light.Color * Math.Abs(PosVector.CosVectors(normal, lightVector)));
                }
            }

            return(lightColor);
        }
Example #2
0
        private ColorVector GetSpecularColor(Ray ray, double p)
        {
            var lightColor = new ColorVector();

            foreach (var light in Scene.Lights)
            {
                // if not shaded
                if (IsViewable(light.Position, ray.Position))
                {
                    var lightSourceVector = light.Position - ray.Position;
                    var cosLightSource    = PosVector.CosVectors(ray.Direction, lightSourceVector);
                    if (cosLightSource > double.Epsilon)
                    {
                        lightColor = lightColor * p; // + (light.Color * Math.Pow(cosLightSource, p));
                    }
                }
            }

            return(lightColor);
        }