Пример #1
0
        //With thanks to following:
        //http://ogldev.atspace.co.uk/www/tutorial19/tutorial19.html
        private Colour CalculateSpecularColour(ILight lightSource, Vector3 cameraLocation, Vector3 hitLoc, IShape shape)
        {
            Colour specColour = new Colour(0, 0, 0);

            Vector3 i      = Vector3.Normalize(lightSource.GetOrigin() - hitLoc); //LightVector
            Vector3 normal = Vector3.Normalize(shape.GetOrigin() - hitLoc);
            Vector3 v      = Vector3.Normalize(hitLoc - cameraLocation);          //Vector to Eye

            Vector3 r = Vector3.Normalize(Vector3.Reflect(i, normal));

            float specFactor = Vector3.Dot(v, r);

            if (specFactor > 0.0f)
            {
                specFactor = (float)Math.Pow(specFactor, spec_power);
                specColour = lightSource.GetColour() * spec_intensity * specFactor;
            }

            return(specColour);
        }