Пример #1
0
        private static void TestCase04()
        {
            // ShadeHit() with a reflective, transparent material
            World w     = new DefaultWorld();
            Ray   r     = new Ray(Tuple.Point(0, 0, -3), Tuple.Vector(0, -Sqrt(2) / 2, Sqrt(2) / 2));
            Shape floor = new Plane();

            floor.Transform                = Transformation.Translation(0, -1, 0);
            floor.Material.Reflective      = 0.5f;
            floor.Material.Transparency    = 0.5f;
            floor.Material.RefractiveIndex = 1.5f;
            w.Shapes.Add(floor);
            Shape ball = new Sphere();

            ball.Material.Color   = Tuple.Color(1, 0, 0);
            ball.Material.Ambient = 0.5f;
            ball.Transform        = Transformation.Translation(0, -3.5f, -0.5f);
            w.Shapes.Add(ball);
            List <Intersection> xs    = Intersection.Aggregate(new Intersection(Sqrt(2), floor));
            Computation         comps = new Computation(xs[0], r, xs);
            LightingModel       l     = new PhongReflection();
            Tuple color = l.ShadeHit(w, comps, 5);

            Assert.Equal(Tuple.Color(0.93391f, 0.69643f, 0.69243f), color);
        }
Пример #2
0
        private static void TestCase04()
        {
            World         w     = new DefaultWorld();
            Ray           r     = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1));
            Shape         shape = w.Shapes[0];
            Intersection  i     = new Intersection(4, shape);
            Computation   comps = new Computation(i, r);
            LightingModel phong = new PhongReflection();
            Tuple         c     = phong.ShadeHit(w, comps);

            Assert.Equal(Tuple.Color(0.38066f, 0.47583f, 0.2855f), c);
        }
Пример #3
0
        private static void TestCase05()
        {
            // ShadeHit() with a reflective material
            World w     = new DefaultWorld();
            Shape shape = new Plane();

            shape.Material.Reflective = 0.5f;
            shape.Transform           = Transformation.Translation(0, -1, 0);
            w.Shapes.Add(shape);
            Ray           r     = new Ray(Tuple.Point(0, 0, -3), Tuple.Vector(0, -Sqrt(2) / 2, Sqrt(2) / 2));
            Intersection  i     = new Intersection(Sqrt(2), shape);
            Computation   comps = new Computation(i, r);
            LightingModel l     = new PhongReflection();
            Tuple         color = l.ShadeHit(w, comps);

            Assert.Equal(Tuple.Color(0.87677f, 0.92436f, 0.82918f), color);
        }
Пример #4
0
        private static void TestCase06()
        {
            World w = new World();

            w.Lights.Add(new PointLight(Tuple.Point(0, 0, -10), Tuple.Color(1, 1, 1)));

            Shape s1 = new Sphere();

            w.Shapes.Add(s1);

            Shape s2 = new Sphere();

            s2.Transform = Transformation.Translation(0, 0, 10);
            w.Shapes.Add(s2);

            Ray          r = new Ray(Tuple.Point(0, 0, 5), Tuple.Vector(0, 0, 1));
            Intersection i = new Intersection(4, s2);

            Computation     comps = new Computation(i, r);
            PhongReflection phong = new PhongReflection();
            Tuple           c     = phong.ShadeHit(w, comps);

            Assert.Equal(Tuple.Color(0.1f, 0.1f, 0.1f), c);
        }