Exemple #1
0
        public void TestIntersectionInShade()
        {
            var world = new World();

            world.Light = new PointLight(Tuple.Point(0, 0, -10), new Color(1, 1, 1));

            world.Shapes.Add(new Sphere());
            world.Shapes.Add(new Sphere
            {
                Transform = Matrix4.Translation(0, 0, 10)
            });

            var s2 = new Sphere
            {
                Transform = Matrix4.Translation(0, 0, 10)
            };

            world.Shapes.Add(s2);

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

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

            Assert.AreEqual(new Color(0.1, 0.1, 0.1), color);
        }
Exemple #2
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 #3
0
        public Color ColorAt(Ray ray, int remaining = 5)
        {
            var intersections = Intersect(ray);
            var hit           = intersections.Hit();

            if (hit is null)
            {
                return(new Color(0, 0, 0));
            }

            var comps = Computation.Prepare(hit, ray, intersections);

            return(LightUtil.ShadeHit(this, comps, remaining));
        }
Exemple #4
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 #5
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 #6
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);
        }