Ejemplo n.º 1
0
        public override Illuminance Spotlight(World World, Shape Shape, Vector3 Spot, Ray Ray, Vector3 Normal)
        {
            Vector3 Incident = Point.Sub(Spot);
            double  Dl       = Incident.Norm() - MathHelper.Epsilon;

            Incident.Normalize();
            Ray shadow = new Ray(Spot.Add(Incident.Mul(MathHelper.Epsilon)), Incident);

            foreach (var s in World.Shapes)
            {
                var t = s.Intersection(shadow);
                if (t < Dl)
                {
                    return(Illuminance.Black);
                }
            }
            double      d  = Normal.Dot(Incident).ToRate();
            Illuminance ld = Shape.Material.DRC.Mul(Illuminance.Mul(d));

            if (d > 0.0 && (!Shape.Material.SRC.IsDark()) && Shape.Material.Shininess > 0.0)
            {
                Vector3 r = Normal.Mul(d * 2).Sub(Incident).Normalized();
                Vector3 v = Ray.Direction.Reversed();
                ld = ld.Add(Illuminance.Mul(Shape.Material.SRC.Mul(Math.Pow(r.Dot(v).ToRate(), Shape.Material.Shininess))));
            }

            return(ld);
        }
Ejemplo n.º 2
0
 public override Illuminance Spotlight(World World, Shape Shape, Vector3 Spot, Ray Ray, Vector3 Normal)
 {
     if (Shape.Material.ARC.IsDark())
     {
         return(Illuminance.Black);
     }
     return(l.Mul(Shape.Material.ARC));
 }