Пример #1
0
        public void ShadeHitIntersectionFromInside()
        {
            var world            = new DefaultWorld(new PointLight(new Point(0, 0.25f, 0), Color.White));
            var ray              = new Ray(new Point(0, 0, 0), new Vector(0, 0, 1));
            var shape            = world.Shapes[1];
            var intersection     = new Intersection(0.5f, shape);
            var intersectionInfo = new IntersectionInfo(new Intersections(intersection), intersection, ray);

            Assert.Equal(new Color(0.9046617f, 0.9046617f, 0.9046617f), world.ShadeHit(intersectionInfo, 0));
        }
Пример #2
0
        public void ShadeHitIntersectionFromOutside()
        {
            var world            = new DefaultWorld();
            var ray              = new Ray(new Point(0, 0, -5), new Vector(0, 0, 1));
            var shape            = world.Shapes[0];
            var intersection     = new Intersection(4, shape);
            var intersectionInfo = new IntersectionInfo(new Intersections(intersection), intersection, ray);

            Assert.Equal(new Color(0.38066f, 0.47583f, 0.2855f), world.ShadeHit(intersectionInfo, 0));
        }
Пример #3
0
        public void ShadeHitReflectiveMaterial()
        {
            var world = new DefaultWorld();
            var plane = new Plane(
                Matrix4x4.Translation(0, -1, 0),
                new Material(reflective: 0.5f));

            world.Shapes.Add(plane);

            var ray          = new Ray(new Point(0, 0, -3), new Vector(0, -MathF.Sqrt(2) / 2, MathF.Sqrt(2) / 2));
            var intersection = new Intersection(MathF.Sqrt(2), plane);
            var info         = new IntersectionInfo(new Intersections(intersection), intersection, ray);

            var actual = world.ShadeHit(info, 1);

            Assert.Equal(new Color(0.87688595f, 0.9245087f, 0.82926315f), actual);
        }
Пример #4
0
        public void ShadeHitReflectiveAndTransparentMaterial()
        {
            var floor = new Plane(
                Matrix4x4.Translation(0, -1, 0),
                new Material(transparency: 0.5f, refractiveIndex: 1.5f, reflective: 0.5f));
            var ball = new Sphere(
                Matrix4x4.Translation(0, -3.5f, -0.5f),
                new Material(Color.Red, ambient: 0.5f));

            var world = new DefaultWorld();

            world.Add(floor);
            world.Add(ball);

            var ray          = new Ray(new Point(0, 0, -3), new Vector(0, -MathF.Sqrt(2) / 2, MathF.Sqrt(2) / 2));
            var intersection = new Intersection(MathF.Sqrt(2), floor);
            var info         = new IntersectionInfo(new Intersections(intersection), intersection, ray);

            var actual = world.ShadeHit(info, 5);

            Assert.Equal(new Color(0.93391f, 0.69643f, 0.69243f), actual);
        }