Example #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);
            }
        }
        public void Given_sphere_Is_GlassSphere_With(Table table)
        {
            var sphere = new GlassSphere();

            table.SetShapePropertiesFromTable(sphere);
            _sphereContext.Sphere = sphere;
        }
Example #3
0
        private static void TestCase02()
        {
            // A helper for producing a sphere with a glassy material
            Shape s = new GlassSphere();

            Assert.Equal(s.Transform, Matrix.Identity());
            Assert.Equal(1, s.Material.Transparency);
            Assert.Equal(1.5f, s.Material.RefractiveIndex);
        }
        public void Given_sphere_Is_GlassSphere_With(int index, Table table)
        {
            var sphere = new GlassSphere
            {
                Name = index.ToString()
            };

            table.SetShapePropertiesFromTable(sphere);
            _sphereContext.Spheres[index] = sphere;
        }
Example #5
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);
        }
Example #6
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);
        }
Example #7
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);
        }
Example #8
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);
        }
Example #9
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>   Main entry-point for this application. </summary>
        ///
        /// <remarks>   Kemp, 1/3/2019. </remarks>
        ///
        /// <param name="args"> An array of command-line argument strings. </param>
        ///-------------------------------------------------------------------------------------------------

        static void Main(string[] args)
        {
            World w = new World();

            w.AddLight(new LightPoint(new Point(10, 10, 10), new Color(1, 1, 1)));

            Plane floor = new Plane();

            floor.Material.Pattern = new CheckedPattern();
            w.AddObject(floor);

            GlassSphere a = new GlassSphere();

            a.Transform           = (Matrix)(MatrixOps.CreateTranslationTransform(0, 15, 0) * MatrixOps.CreateScalingTransform(2, 2, 2));
            a.Material.Ambient    = new Color(0, 0, 0);
            a.Material.Color      = new Color(0, 0, 0);
            a.Material.Reflective = 0.5;
            w.AddObject(a);

            Sphere b = new Sphere();

            b.Transform      = MatrixOps.CreateTranslationTransform(3, 3, 0);
            b.Material.Color = new Color(1, 0, 0);
            w.AddObject(b);

            GlassSphere ainner = new GlassSphere();

            ainner.Transform                = MatrixOps.CreateTranslationTransform(0, 15, 0);
            ainner.Material.Ambient         = new Color(0, 0, 0);
            ainner.Material.Color           = new Color(0, 0, 0);
            ainner.Material.RefractiveIndex = 1;
            ainner.Material.Reflective      = 0.5;
            w.AddObject(ainner);

            Camera camera = new Camera(400, 400, Math.PI / 3);

            camera.Transform = MatrixOps.CreateViewTransform(new Point(0, 20, 0), new Point(0, 0, 0), new RayTracerLib.Vector(0, 0, 1));

            Canvas image = w.Render(camera);

            /*
             * String ppm = image.ToPPM();
             *
             * System.IO.File.WriteAllText(@"ToPPM.ppm", ppm);
             */
            image.WritePNG("ToPNG.png");
            Console.Write("Press Enter to finish ... ");
            Console.Read();
        }