public IntersectionPreComputation(double time,
                                   RayTraceableObject obj,
                                   Point point,
                                   Vector eyeVector,
                                   Vector normalVector,
                                   bool isInside,
                                   Point overPoint)
 {
     Time         = time;
     Object       = obj;
     Point        = point;
     EyeVector    = eyeVector;
     NormalVector = normalVector;
     IsInside     = isInside;
     OverPoint    = overPoint;
 }
Esempio n. 2
0
        public Color CalculateLighting(PointLight light,
                                       Point pointBeingIlluminated,
                                       Vector eyeVector,
                                       Vector normalVector,
                                       bool inShadow,
                                       RayTraceableObject objectBeingDrawn)
        {
            var materialColor       = Pattern?.ColorAt(pointBeingIlluminated, objectBeingDrawn) ?? Color;
            var effectiveColor      = materialColor * light.Intensity;
            var lightVector         = (light.Position - pointBeingIlluminated).Normalize();
            var ambientContribution = effectiveColor * Ambient;

            // Represents the cosine of the angle between the light vector and normal vector
            var lightDotNormal = lightVector.Dot(normalVector);

            Color diffuseContribution;
            Color specularContribution;

            if (inShadow || lightDotNormal < 0)
            {
                // Light is on the other side of the surface
                diffuseContribution  = Color.Black;
                specularContribution = Color.Black;
            }
            else
            {
                // Light is on the same side of the surface as the normal
                diffuseContribution = effectiveColor * Diffuse * lightDotNormal;
                var reflectionVector = (-lightVector).Reflect(normalVector);

                // Represents the cosine of the angle between the reflection vector and the eye vector.
                var reflectDotEye = reflectionVector.Dot(eyeVector);
                if (reflectDotEye < 0)
                {
                    // Light reflects away from the eye
                    specularContribution = Color.Black;
                }
                else
                {
                    var factor = Math.Pow(reflectDotEye, Shininess);
                    specularContribution = light.Intensity * Specular * factor;
                }
            }

            return(ambientContribution + diffuseContribution + specularContribution);
        }
Esempio n. 3
0
 public Intersection(double time, RayTraceableObject o)
 {
     Time   = time;
     Object = o;
 }