Exemple #1
0
        public void NoShadow()
        {
            var world = WorldBuilder.DefaultWorld();
            var point = Tuple.Point(0, 10, 0);

            Assert.IsFalse(ShadowUtil.IsShadowed(world, point));
        }
Exemple #2
0
        public void ObjectBehindPoint()
        {
            var world = WorldBuilder.DefaultWorld();
            var point = Tuple.Point(-2, 2, -2);

            Assert.IsFalse(ShadowUtil.IsShadowed(world, point));
        }
Exemple #3
0
        public void TestColorAtMiss()
        {
            var world = WorldBuilder.DefaultWorld();
            var ray   = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 1, 0));

            Assert.AreEqual(new Color(0, 0, 0), world.ColorAt(ray));
        }
Exemple #4
0
        public void BehindLight()
        {
            var world = WorldBuilder.DefaultWorld();
            var point = Tuple.Point(-20, 20, -20);

            Assert.IsFalse(ShadowUtil.IsShadowed(world, point));
        }
Exemple #5
0
        public void InShadow()
        {
            var world = WorldBuilder.DefaultWorld();
            var point = Tuple.Point(10, -10, 10);

            Assert.IsTrue(ShadowUtil.IsShadowed(world, point));
        }
Exemple #6
0
        public void TestColorAtBehindRay()
        {
            var world = WorldBuilder.DefaultWorld();

            world.Shapes[0].Material.Ambient = 1;
            world.Shapes[1].Material.Ambient = 1;

            var ray = new Ray(Tuple.Point(0, 0, 0.75), Tuple.Vector(0, 0, -1));

            Assert.AreEqual(world.Shapes[1].Material.Color, world.ColorAt(ray));
        }
Exemple #7
0
        public void TestShadeIntersection()
        {
            var world  = WorldBuilder.DefaultWorld();
            var ray    = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1));
            var sphere = world.Shapes[0];
            var i      = new Intersection(4, sphere);

            var comp  = Computation.Prepare(i, ray);
            var color = LightUtil.ShadeHit(world, comp);

            Assert.AreEqual(new Color(0.38066, 0.47583, 0.2855), color);
        }
Exemple #8
0
        public void TestDefaultWorldIntersect()
        {
            var world = WorldBuilder.DefaultWorld();
            var ray   = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1));

            var xs = world.Intersect(ray);

            Assert.AreEqual(4, xs.Count);
            Assert.AreEqual(xs[0].Distance, 4.0, Epsilon);
            Assert.AreEqual(xs[1].Distance, 4.5, Epsilon);
            Assert.AreEqual(xs[2].Distance, 5.5, Epsilon);
            Assert.AreEqual(xs[3].Distance, 6.0, Epsilon);
        }
Exemple #9
0
        public void TestShadeIntersectionInside()
        {
            var world = WorldBuilder.DefaultWorld();

            world.Light = new PointLight(Tuple.Point(0, 0.25, 0), new Color(1, 1, 1));
            var ray    = new Ray(Tuple.Point(0, 0, 0), Tuple.Vector(0, 0, 1));
            var sphere = world.Shapes[1];
            var i      = new Intersection(0.5, sphere);

            var comp  = Computation.Prepare(i, ray);
            var color = LightUtil.ShadeHit(world, comp);

            Assert.AreEqual(new Color(0.90498, 0.90498, 0.90498), color);
        }
Exemple #10
0
        public void TestReflectOnNonReflectiveShape()
        {
            var world = WorldBuilder.DefaultWorld();

            world.Shapes[1].Material.Ambient = 1.0;

            var ray = new Ray(Tuple.Point(0, 0, 0), Tuple.Vector(0, 0, 1));
            var i   = new Intersection(1, world.Shapes[1]);

            var comp = Computation.Prepare(i, ray);

            var col = world.ReflectedColor(comp);

            Assert.AreEqual(new Color(0, 0, 0), col);
        }
Exemple #11
0
        public void TestRenderWorldWithCamera()
        {
            var world = WorldBuilder.DefaultWorld();
            var cam   = new Camera(11, 11, PI / 2)
            {
                Transform = Matrix4.ViewTransform(
                    Tuple.Point(0, 0, -5),
                    Tuple.Point(0, 0, 0),
                    Tuple.Vector(0, 1, 0))
            };

            Canvas image = Renderer.Render(cam, world);

            Assert.AreEqual(new Color(0.38066, 0.47583, 0.2855), image.PixelAt(5, 5));
        }
Exemple #12
0
        public void TestRefractColor()
        {
            var world = WorldBuilder.DefaultWorld();
            var ray   = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1));

            var xs = new Intersections
            {
                new Intersection(4, world.Shapes[0]),
                new Intersection(6, world.Shapes[0])
            };

            var comps = Computation.Prepare(xs[0], ray, xs);
            var col   = world.RefractColor(comps, 5);

            Assert.AreEqual(new Color(0, 0, 0), col);
        }
Exemple #13
0
        public void TestDefaultWorld()
        {
            var world = WorldBuilder.DefaultWorld();

            Assert.AreEqual(new PointLight(Tuple.Point(-10, 10, -10), new Color(1, 1, 1)), world.Light);
            Assert.IsTrue(world.Shapes.Contains(new Sphere
            {
                Material = new Material
                {
                    Color    = new Color(0.8, 1.0, 0.6),
                    Diffuse  = 0.7,
                    Specular = 0.2
                }
            }));
            Assert.IsTrue(world.Shapes.Contains(new Sphere
            {
                Transform = Matrix4.Scaling(0.5, 0.5, 0.5)
            }));
        }
Exemple #14
0
        public void TestShadeHitOnReflectiveShape()
        {
            var world = WorldBuilder.DefaultWorld();

            var plane = new Plane
            {
                Transform = Matrix4.Translation(0, -1, 0)
            };

            plane.Material.Reflective = 0.5;
            world.Shapes.Add(plane);

            var ray = new Ray(Tuple.Point(0, 0, -3), Tuple.Vector(0, -0.5 * System.Math.Sqrt(2), 0.5 * System.Math.Sqrt(2)));
            var i   = new Intersection(System.Math.Sqrt(2), plane);

            var comp = Computation.Prepare(i, ray);
            var col  = LightUtil.ShadeHit(world, comp);

            Assert.AreEqual(new Color(0.876757, 0.924340, 0.829174), col);
        }
Exemple #15
0
        public void TestRefractColorUnderTotalInternalReflection()
        {
            var world = WorldBuilder.DefaultWorld();

            world.Shapes[0].Material.Transparency    = 1.0;
            world.Shapes[0].Material.RefractiveIndex = 1.5;

            var ray = new Ray(Tuple.Point(0, 0, 0.5 * System.Math.Sqrt(2)), Tuple.Vector(0, 1, 0));

            var xs = new Intersections
            {
                new Intersection(-0.5 * System.Math.Sqrt(2), world.Shapes[0]),
                new Intersection(0.5 * System.Math.Sqrt(2), world.Shapes[0])
            };

            var comps = Computation.Prepare(xs[1], ray, xs);
            var col   = world.RefractColor(comps, 5);

            Assert.AreEqual(new Color(0, 0, 0), col);
        }
Exemple #16
0
        public void TestRefractMaxDepth()
        {
            var world = WorldBuilder.DefaultWorld();

            world.Shapes[0].Material.Transparency    = 1.0;
            world.Shapes[0].Material.RefractiveIndex = 1.5;

            var ray = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1));

            var xs = new Intersections
            {
                new Intersection(4, world.Shapes[0]),
                new Intersection(6, world.Shapes[0])
            };

            var comps = Computation.Prepare(xs[0], ray, xs);
            var col   = world.RefractColor(comps, 0);

            Assert.AreEqual(new Color(0, 0, 0), col);
        }
Exemple #17
0
        public void TestReflectMaxDepth()
        {
            var world = WorldBuilder.DefaultWorld();

            var plane = new Plane
            {
                Transform = Matrix4.Translation(0, -1, 0)
            };

            plane.Material.Reflective = 0.5;
            world.Shapes.Add(plane);

            var ray = new Ray(Tuple.Point(0, 0, -3), Tuple.Vector(0, -0.5 * System.Math.Sqrt(2), 0.5 * System.Math.Sqrt(2)));
            var i   = new Intersection(System.Math.Sqrt(2), plane);

            var comp = Computation.Prepare(i, ray);

            var col = world.ReflectedColor(comp, 0);

            Assert.AreEqual(new Color(0, 0, 0), col);
        }
Exemple #18
0
        public void TestRefractShadeHit()
        {
            var world = WorldBuilder.DefaultWorld();
            var floor = new Plane
            {
                Transform = Matrix4.Translation(0, -1, 0),
                Material  = new Material
                {
                    Reflective      = 0.5,
                    Transparency    = 0.5,
                    RefractiveIndex = 1.5
                }
            };
            var ball = new Sphere
            {
                Transform = Matrix4.Translation(0, -3.5, -0.5),
                Material  = new Material
                {
                    Color   = new Color(1, 0, 0),
                    Ambient = 0.5
                }
            };

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

            var ray = new Ray(Tuple.Point(0, 0, -3), Tuple.Vector(0, -0.5 * System.Math.Sqrt(2), 0.5 * System.Math.Sqrt(2)));

            var xs = new Intersections
            {
                new Intersection(System.Math.Sqrt(2), floor),
            };

            var comps = Computation.Prepare(xs[0], ray, xs);
            var color = LightUtil.ShadeHit(world, comps, 5);

            Assert.AreEqual(new Color(0.93391, 0.69643, 0.69243), color);
            //Assert.AreEqual(new Color(0.93642, 0.68642, 0.68642), color);
        }
Exemple #19
0
        public void TestRefractRayColor()
        {
            var world = WorldBuilder.DefaultWorld();

            world.Shapes[0].Material.Ambient         = 1.0;
            world.Shapes[0].Material.Pattern         = new Test_Pattern();
            world.Shapes[1].Material.Transparency    = 1.0;
            world.Shapes[1].Material.RefractiveIndex = 1.5;

            var ray = new Ray(Tuple.Point(0, 0, 0.1), Tuple.Vector(0, 1, 0));

            var xs = new Intersections
            {
                new Intersection(-0.9899, world.Shapes[0]),
                new Intersection(-0.4899, world.Shapes[1]),
                new Intersection(0.4899, world.Shapes[1]),
                new Intersection(0.9899, world.Shapes[0])
            };

            var comps = Computation.Prepare(xs[2], ray, xs);
            var col   = world.RefractColor(comps, 5);

            Assert.AreEqual(new Color(0, 0.998884, 0.047219), col);
        }