Exemplo n.º 1
0
        private static void TestCase03()
        {
            // Finding n1 and n2 at various intersections
            Shape A = new GlassSphere();

            A.Transform = Transformation.Scaling(2, 2, 2);
            A.Material.RefractiveIndex = 1.5f;
            Shape B = new GlassSphere();

            B.Transform = Transformation.Translation(0, 0, -0.25f);
            B.Material.RefractiveIndex = 2;
            Shape C = new GlassSphere();

            C.Transform = Transformation.Translation(0, 0, 0.25f);
            C.Material.RefractiveIndex = 2.5f;
            Ray r = new Ray(Tuple.Point(0, 0, -4), Tuple.Vector(0, 0, 1));
            List <Intersection> xs = Intersection.Aggregate(new Intersection(2, A),
                                                            new Intersection(2.75f, B),
                                                            new Intersection(3.25f, C),
                                                            new Intersection(4.75f, B),
                                                            new Intersection(5.25f, C),
                                                            new Intersection(6, A));

            var expectedN1 = new[] { 1, 1.5f, 2, 2.5f, 2.5f, 1.5f };
            var expectedN2 = new[] { 1.5f, 2, 2.5f, 2.5f, 1.5f, 1 };

            for (int i = 0; i < 6; ++i)
            {
                Computation comps = new Computation(xs[i], r, xs);

                Assert.Equal(expectedN1[i], comps.N1);
                Assert.Equal(expectedN2[i], comps.N2);
            }
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        private static void TestCase11()
        {
            Sphere              s  = new Sphere();
            Intersection        i1 = new Intersection(1, s);
            Intersection        i2 = new Intersection(2, s);
            List <Intersection> xs = Intersection.Aggregate(i2, i1);
            Intersection        i  = Intersection.Hit(xs);

            Assert.Equal(i1, i);

            i1 = new Intersection(-1, s);
            i2 = new Intersection(1, s);
            xs = Intersection.Aggregate(i2, i1);
            i  = Intersection.Hit(xs);

            Assert.Equal(i2, i);

            i1 = new Intersection(-2, s);
            i2 = new Intersection(-1, s);
            xs = Intersection.Aggregate(i2, i1);
            i  = Intersection.Hit(xs);

            Assert.Null(i);

            i1 = new Intersection(5, s);
            i2 = new Intersection(7, s);
            Intersection i3 = new Intersection(-3, s);
            Intersection i4 = new Intersection(2, s);

            xs = Intersection.Aggregate(i1, i2, i3, i4);
            i  = Intersection.Hit(xs);

            Assert.Equal(i4, i);
        }
Exemplo n.º 4
0
        private static void TestCase03()
        {
            // The Schlick approximation with small angle and n2 > n1
            Shape shape               = new GlassSphere();
            Ray   r                   = new Ray(Tuple.Point(0, 0.99f, -2), Tuple.Vector(0, 0, 1));
            List <Intersection> xs    = Intersection.Aggregate(new Intersection(1.8589f, shape));
            Computation         comps = new Computation(xs[0], r, xs);
            float reflectance         = Fresnel.Schlick(comps);

            Assert.Equal(0.48873f, reflectance, 5);
        }
Exemplo n.º 5
0
        private static void TestCase02()
        {
            // The Schlick approximation with a perpendicular viewing angle
            Shape shape               = new GlassSphere();
            Ray   r                   = new Ray(Tuple.Point(0, 0, 0), Tuple.Vector(0, 1, 0));
            List <Intersection> xs    = Intersection.Aggregate(new Intersection(-1, shape), new Intersection(1, shape));
            Computation         comps = new Computation(xs[1], r, xs);
            float reflectance         = Fresnel.Schlick(comps);

            Assert.Equal(0.04f, reflectance, 5);
        }
Exemplo n.º 6
0
        private static void TestCase01()
        {
            // The Schlick approximation under total internal reflection
            Shape shape               = new GlassSphere();
            Ray   r                   = new Ray(Tuple.Point(0, 0, Sqrt(2) / 2), Tuple.Vector(0, 1, 0));
            List <Intersection> xs    = Intersection.Aggregate(new Intersection(-Sqrt(2) / 2, shape), new Intersection(Sqrt(2) / 2, shape));
            Computation         comps = new Computation(xs[1], r, xs);
            float reflectance         = Fresnel.Schlick(comps);

            Assert.Equal(1, reflectance);
        }
Exemplo n.º 7
0
        private static void TestCase09()
        {
            Sphere              s  = new Sphere();
            Intersection        i1 = new Intersection(1, s);
            Intersection        i2 = new Intersection(2, s);
            List <Intersection> xs = Intersection.Aggregate(i1, i2);

            Assert.Equal(2, xs.Count);
            Assert.Equal(1, xs[0].T);
            Assert.Equal(2, xs[1].T);
        }
Exemplo n.º 8
0
        private static void TestCase05()
        {
            // The refracted color with an opaque surface
            World w                   = new DefaultWorld();
            Shape shape               = w.Shapes[0];
            Ray   r                   = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1));
            List <Intersection> xs    = Intersection.Aggregate(new Intersection(4, shape), new Intersection(6, shape));
            Computation         comps = new Computation(xs[0], r, xs);
            LightingModel       l     = new PhongReflection();
            Tuple c                   = l.RefractedColor(w, comps, 5);

            Assert.Equal(Tuple.Color(0, 0, 0), c);
        }
Exemplo n.º 9
0
        private static void TestCase04()
        {
            // The under point is offset below the surface
            Ray   r     = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1));
            Shape shape = new GlassSphere();

            shape.Transform = Transformation.Translation(0, 0, 1);
            Intersection        i     = new Intersection(5, shape);
            List <Intersection> xs    = Intersection.Aggregate(i);
            Computation         comps = new Computation(i, r, xs);

            Assert.True(comps.UnderPoint.Z > Constants.floatEps / 2);
            Assert.True(comps.Point.Z < comps.UnderPoint.Z);
        }
Exemplo n.º 10
0
        private static void TestCase07()
        {
            // The refracted color under total internal reflection
            World w     = new DefaultWorld();
            Shape shape = w.Shapes[0];

            shape.Material.Transparency    = 1;
            shape.Material.RefractiveIndex = 1.5f;
            Ray r = new Ray(Tuple.Point(0, 0, Sqrt(2) / 2), Tuple.Vector(0, 1, 0));
            List <Intersection> xs    = Intersection.Aggregate(new Intersection(-Sqrt(2) / 2, shape), new Intersection(Sqrt(2) / 2, shape));
            Computation         comps = new Computation(xs[1], r, xs);
            LightingModel       l     = new PhongReflection();
            Tuple c = l.RefractedColor(w, comps, 5);

            Assert.Equal(Tuple.Color(0, 0, 0), c);
        }
Exemplo n.º 11
0
        private static void TestCase06()
        {
            // The refracted color at the maximum recursive depth
            World w     = new DefaultWorld();
            Shape shape = w.Shapes[0];

            shape.Material.Transparency    = 1;
            shape.Material.RefractiveIndex = 1.5f;
            Ray r = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1));
            List <Intersection> xs    = Intersection.Aggregate(new Intersection(4, shape), new Intersection(6, shape));
            Computation         comps = new Computation(xs[0], r, xs);
            LightingModel       l     = new PhongReflection();
            Tuple c = l.RefractedColor(w, comps, 0);

            Assert.Equal(Tuple.Color(0, 0, 0), c);
        }
Exemplo n.º 12
0
        private static void TestCase08()
        {
            // The refracted color with a refracted ray
            World w = new DefaultWorld();
            Shape A = w.Shapes[0];

            A.Material.Ambient = 1;
            A.Material.Pattern = new PositionPattern();
            Shape B = w.Shapes[1];

            B.Material.Transparency    = 1;
            B.Material.RefractiveIndex = 1.5f;
            Ray r = new Ray(Tuple.Point(0, 0, 0.1f), Tuple.Vector(0, 1, 0));
            List <Intersection> xs = Intersection.Aggregate(new Intersection(-0.9899f, A),
                                                            new Intersection(-0.4899f, B),
                                                            new Intersection(0.4899f, B),
                                                            new Intersection(0.9899f, A));
            Computation   comps = new Computation(xs[2], r, xs);
            LightingModel l     = new PhongReflection();
            Tuple         c     = l.RefractedColor(w, comps, 5);

            Assert.Equal(Tuple.Color(0, 0.99888f, 0.04725f), c);
        }