Ejemplo n.º 1
0
        public void ShadeHitWithReflectiveTransparency()
        {
            World w     = World.DefaultWorld();
            Shape floor = new Plane();

            floor.Transform                = new Translate(0, -1, 0).GetTransform();
            floor.Material.Reflectivity    = 0.5;
            floor.Material.Transparency    = 0.5;
            floor.Material.RefractiveIndex = 1.5;
            w.AddShape(floor);
            Shape ball = new Sphere();

            ball.Material.Color   = new Color(1, 0, 0);
            ball.Material.Ambient = 0.5;
            ball.Transform        = new Translate(0, -3.5, -0.5).GetTransform();
            w.AddShape(ball);
            Ray r = new Ray(Tuple.Point(0, 0, -3), Tuple.Vector(0, -Math.Sqrt(2) / 2, Math.Sqrt(2) / 2));
            List <Intersection> xs = new List <Intersection>();

            xs.Add(new Intersection(Math.Sqrt(2), floor));
            Computations comps = Computations.PrepareComputations(xs[0], r, xs);
            Color        c     = w.ShadeHit(comps, 5);

            Assert.AreEqual(c, new Color(0.93391, 0.69643, 0.69243));
        }
Ejemplo n.º 2
0
        public void PrecomputeReflectionVector()
        {
            Plane        shape = new Plane();
            Ray          r     = new Ray(Tuple.Point(0, 1, -1), Tuple.Vector(0, -Math.Sqrt(2) / 2, Math.Sqrt(2) / 2));
            Intersection i     = new Intersection(Math.Sqrt(2), shape);
            Computations comps = Computations.PrepareComputations(i, r);

            Assert.AreEqual(comps.reflectv, Tuple.Vector(0, Math.Sqrt(2) / 2, Math.Sqrt(2) / 2));
        }
Ejemplo n.º 3
0
        public void PrepareComputationsOutside()
        {
            Ray          r     = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1));
            Sphere       shape = new Sphere();
            Intersection i     = new Intersection(4, shape);
            Computations comps = Computations.PrepareComputations(i, r);

            Assert.IsFalse(comps.inside);
        }
Ejemplo n.º 4
0
        public void SmoothTrianglePrepComps()
        {
            Intersection        i  = new Intersection(1, tri, 0.45, 0.25);
            Ray                 r  = new Ray(Tuple.Point(-0.2, 0.3, -2), Tuple.Vector(0, 0, 1));
            List <Intersection> xs = new List <Intersection>();

            xs.Add(i);
            Computations comps = Computations.PrepareComputations(i, r, xs);

            Assert.AreEqual(comps.normalv, Tuple.Vector(-0.5547, 0.83205, 0));
        }
Ejemplo n.º 5
0
        public void ShadeIntersectionOutside()
        {
            World        w     = World.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);
            Computations comps = Computations.PrepareComputations(i, r);
            Color        c     = w.ShadeHit(comps, 0);

            Assert.AreEqual(c, new Color(0.38066, 0.47583, 0.2855));
        }
Ejemplo n.º 6
0
        public void SchlickWithN2GreaterN1()
        {
            Shape shape            = Sphere.GlassSphere();
            Ray   r                = new Ray(Tuple.Point(0, 0.99, -2), Tuple.Vector(0, 0, 1));
            List <Intersection> xs = new List <Intersection>();

            xs.Add(new Intersection(1.8589, shape));
            Computations comps       = Computations.PrepareComputations(xs[0], r, xs);
            double       reflectance = Intersection.Schlick(comps);

            Assert.IsTrue(Globals.EqualityOfDouble(reflectance, 0.48873));
        }
Ejemplo n.º 7
0
        public void PrepareComputationsInside()
        {
            Ray          r     = new Ray(Tuple.Point(0, 0, 0), Tuple.Vector(0, 0, 1));
            Sphere       shape = new Sphere();
            Intersection i     = new Intersection(1, shape);
            Computations comps = Computations.PrepareComputations(i, r);

            Assert.AreEqual(comps.point, Tuple.Point(0, 0, 1));
            Assert.AreEqual(comps.eyev, Tuple.Vector(0, 0, -1));
            Assert.IsTrue(comps.inside);
            Assert.AreEqual(comps.normalv, Tuple.Vector(0, 0, -1));
        }
Ejemplo n.º 8
0
        public void HitOffsetsPoint()
        {
            Ray    r     = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1));
            Sphere shape = new Sphere();

            shape.Transform = new Translate(0, 0, 1).GetTransform();
            Intersection i     = new Intersection(5, shape);
            Computations comps = Computations.PrepareComputations(i, r);

            Assert.IsTrue(comps.overPoint.Z < -Globals.EPSILON / 2);
            Assert.IsTrue(comps.point.Z > comps.overPoint.Z);
        }
Ejemplo n.º 9
0
        public void PrepareComputations()
        {
            Ray          r     = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1));
            Sphere       shape = new Sphere();
            Intersection i     = new Intersection(4, shape);
            Computations comps = Computations.PrepareComputations(i, r);

            Assert.AreEqual(comps.t, i.T);
            Assert.AreEqual(comps.shape, i.S);
            Assert.AreEqual(comps.point, Tuple.Point(0, 0, -1));
            Assert.AreEqual(comps.eyev, Tuple.Vector(0, 0, -1));
            Assert.AreEqual(comps.normalv, Tuple.Vector(0, 0, -1));
        }
Ejemplo n.º 10
0
        public void SchlickWithPerpendicularRay()
        {
            Shape shape            = Sphere.GlassSphere();
            Ray   r                = new Ray(Tuple.Point(0, 0, 0), Tuple.Vector(0, 1, 0));
            List <Intersection> xs = new List <Intersection>();

            xs.Add(new Intersection(-1, shape));
            xs.Add(new Intersection(1, shape));
            Computations comps       = Computations.PrepareComputations(xs[1], r, xs);
            double       reflectance = Intersection.Schlick(comps);

            Assert.IsTrue(Globals.EqualityOfDouble(reflectance, 0.04));
        }
Ejemplo n.º 11
0
        public void SchlickUnderTotalInternalReflection()
        {
            Shape shape            = Sphere.GlassSphere();
            Ray   r                = new Ray(Tuple.Point(0, 0, Math.Sqrt(2) / 2), Tuple.Vector(0, 1, 0));
            List <Intersection> xs = new List <Intersection>();

            xs.Add(new Intersection(-Math.Sqrt(2) / 2, shape));
            xs.Add(new Intersection(Math.Sqrt(2) / 2, shape));
            Computations comps       = Computations.PrepareComputations(xs[1], r, xs);
            double       reflectance = Intersection.Schlick(comps);

            Assert.IsTrue(Globals.EqualityOfDouble(reflectance, 1.0));
        }
Ejemplo n.º 12
0
        public void ReflectedColorOfNonreflectiveMaterial()
        {
            World w  = World.DefaultWorld();
            Ray   r  = new Ray(Tuple.Point(0, 0, 0), Tuple.Vector(0, 0, 1));
            Shape s2 = w.Shapes[1];

            s2.Material.Ambient = 1;
            Intersection i     = new Intersection(1, s2);
            Computations comps = Computations.PrepareComputations(i, r);
            Color        c     = w.ReflectedColor(comps, 5);

            Assert.AreEqual(c, new Color(0.0, 0.0, 0.0));
        }
Ejemplo n.º 13
0
        public void ShadeIntersectionInside()
        {
            World w = World.DefaultWorld();

            w.Lights[0] = Light.PointLight(Tuple.Point(0, 0.25, 0), new Color(1, 1, 1));
            Ray          r     = new Ray(Tuple.Point(0, 0, 0), Tuple.Vector(0, 0, 1));
            Shape        shape = w.Shapes[1];
            Intersection i     = new Intersection(0.5, shape);
            Computations comps = Computations.PrepareComputations(i, r);
            Color        c     = w.ShadeHit(comps, 0);

            Assert.AreEqual(c, new Color(0.90498, 0.90498, 0.90498));
        }
Ejemplo n.º 14
0
        public void RefractedColorWithOpaqueSurface()
        {
            World w                = World.DefaultWorld();
            Shape shape            = w.Shapes[0];
            Ray   r                = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1));
            List <Intersection> xs = new List <Intersection>();

            xs.Add(new Intersection(4, shape));
            xs.Add(new Intersection(6, shape));
            Computations comps = Computations.PrepareComputations(xs[0], r, xs);
            Color        c     = w.RefractedColor(comps, 5);

            Assert.AreEqual(c, new Color(0, 0, 0));
        }
Ejemplo n.º 15
0
        public void UnderPoint()
        {
            Ray    r     = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1));
            Sphere shape = Sphere.GlassSphere();

            shape.Transform = new Translate(0, 0, 1).GetTransform();
            Intersection        i  = new Intersection(5, shape);
            List <Intersection> xs = new List <Intersection>();

            xs.Add(i);
            Computations comps = Computations.PrepareComputations(i, r, xs);

            Assert.IsTrue(comps.underPoint.Z > Globals.EPSILON / 2);
            Assert.IsTrue(comps.point.Z < comps.underPoint.Z);
        }
Ejemplo n.º 16
0
        public void LimitRecursion()
        {
            World w     = World.DefaultWorld();
            Shape shape = new Plane();

            shape.Material.Reflectivity = 0.5;
            shape.Transform             = new Translate(0, -1, 0).GetTransform();
            w.AddShape(shape);
            Ray          r     = new Ray(Tuple.Point(0, 0, -3), Tuple.Vector(0, -Math.Sqrt(2) / 2, Math.Sqrt(2) / 2));
            Intersection i     = new Intersection(Math.Sqrt(2), shape);
            Computations comps = Computations.PrepareComputations(i, r);
            Color        c     = w.ReflectedColor(comps, 0);

            Assert.AreEqual(c, new Color(0, 0, 0));
        }
Ejemplo n.º 17
0
        public void RefractedColorUnderTotalInternalReflection()
        {
            World w     = World.DefaultWorld();
            Shape shape = w.Shapes[0];

            shape.Material.Transparency    = 1.0;
            shape.Material.RefractiveIndex = 1.5;
            Ray r = new Ray(Tuple.Point(0, 0, Math.Sqrt(2) / 2), Tuple.Vector(0, 1, 0));
            List <Intersection> xs = new List <Intersection>();

            xs.Add(new Intersection(-Math.Sqrt(2) / 2, shape));
            xs.Add(new Intersection(Math.Sqrt(2) / 2, shape));
            Computations comps = Computations.PrepareComputations(xs[1], r, xs);
            Color        c     = w.RefractedColor(comps, 5);

            Assert.AreEqual(c, new Color(0, 0, 0));
        }
Ejemplo n.º 18
0
        public void RefractedColorWithOpaqueSurfaceMaxRecursiveDepth()
        {
            World w     = World.DefaultWorld();
            Shape shape = w.Shapes[0];

            shape.Material.Transparency    = 1.0;
            shape.Material.RefractiveIndex = 1.5;
            Ray r = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1));
            List <Intersection> xs = new List <Intersection>();

            xs.Add(new Intersection(4, shape));
            xs.Add(new Intersection(6, shape));
            Computations comps = Computations.PrepareComputations(xs[0], r, xs);
            Color        c     = w.RefractedColor(comps, 0);

            Assert.AreEqual(c, new Color(0, 0, 0));
        }
Ejemplo n.º 19
0
        public void FindN1AndN2AtSeveralIntersections()
        {
            Sphere a = Sphere.GlassSphere();

            a.Transform = new Scale(2, 2, 2).GetTransform();
            a.Material.RefractiveIndex = 1.5;
            Sphere b = Sphere.GlassSphere();

            b.Transform = new Translate(0, 0, -0.25).GetTransform();
            b.Material.RefractiveIndex = 2.0;
            Sphere c = Sphere.GlassSphere();

            c.Transform = new Translate(0, 0, 0.25).GetTransform();
            c.Material.RefractiveIndex = 2.5;
            Ray r = new Ray(Tuple.Point(0, 0, -4), Tuple.Vector(0, 0, 1));
            List <Intersection> xs = new List <Intersection>()
            {
                new Intersection(2, a),
                new Intersection(2.75, b),
                new Intersection(3.25, c),
                new Intersection(4.75, b),
                new Intersection(5.25, c),
                new Intersection(6, a)
            };

            double[,] targets = new double[6, 2] {
                { 1.0, 1.5 },
                { 1.5, 2.0 },
                { 2.0, 2.5 },
                { 2.5, 2.5 },
                { 2.5, 1.5 },
                { 1.5, 1.0 }
            };

            for (int i = 0; i < 6; i++)
            {
                Computations comps = Computations.PrepareComputations(xs[i], r, xs);
                Assert.AreEqual(comps.n1, targets[i, 0]);
                Assert.AreEqual(comps.n2, targets[i, 1]);
            }
        }
Ejemplo n.º 20
0
        public void ShadeHitInShadow()
        {
            World w = new World();

            w.Lights = new List <Light>();
            w.Lights.Add(Light.PointLight(Tuple.Point(0, 0, -10), new Color(1, 1, 1)));
            Sphere s1 = new Sphere();

            w.AddShape(s1);
            Sphere s2 = new Sphere();

            s2.TransformList.Add(new Translate(0, 0, 10));
            s2.InitiateTransformation();
            w.AddShape(s2);
            Ray          r     = new Ray(Tuple.Point(0, 0, 5), Tuple.Vector(0, 0, 1));
            Intersection i     = new Intersection(4, s2);
            Computations comps = Computations.PrepareComputations(i, r);
            Color        c     = w.ShadeHit(comps, 0);

            Assert.AreEqual(c, new Color(0.1, 0.1, 0.1));
        }
Ejemplo n.º 21
0
        public void RefractedColor()
        {
            World w = World.DefaultWorld();
            Shape a = w.Shapes[0];

            a.Material.Ambient = 1.0;
            a.Material.Pattern = new TestPattern();
            Shape b = w.Shapes[1];

            b.Material.Transparency    = 1.0;
            b.Material.RefractiveIndex = 1.5;
            Ray r = new Ray(Tuple.Point(0, 0, 0.1), Tuple.Vector(0, 1, 0));
            List <Intersection> xs = new List <Intersection>();

            xs.Add(new Intersection(-0.9899, a));
            xs.Add(new Intersection(-0.4899, b));
            xs.Add(new Intersection(0.4899, b));
            xs.Add(new Intersection(0.9899, a));
            Computations comps = Computations.PrepareComputations(xs[2], r, xs);
            Color        c     = w.RefractedColor(comps, 5);

            Assert.AreEqual(c, new Color(0, 0.99888, 0.04725));
        }