Ejemplo n.º 1
0
        public static void writePPM(string ppmFileName, Picture yCbCrPicture)
        {
            string outputFilename = "out_" + ppmFileName;
            string inputFilePath  = Assets.GetFilePath(outputFilename);

            PPMWriter.WritePictureToPPM(inputFilePath, yCbCrPicture);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            float bias = (1 / 2000f);

            //Start a new scene
            Scene scene = new Scene(65f, 750, 1500, new Color(25, 25, 80));

            scene.AddLamp(new DirectionalLamp(new Vector3(30, -3, -25), new Color(155, 155, 155), .25f));
            scene.AddLamp(new DirectionalLamp(new Vector3(0, -1, 0), new Color(155, 155, 155), .05f));

            //Plane
            scene.AddObject(new Plane(new Vector3(0, -3, 0), new Vector3(0, -1, 0), new Material(32f, 0f, bias, new Color(155, 155, 155))));
            //Spheres
            scene.AddObject(new Sphere(new Vector3(5, 2.25f, -8), 4.5f, new Material(32f, .75f, bias, new Color(255, 10, 10))));  // Red

            scene.AddObject(new Sphere(new Vector3(-10f, 2.5f, -15), 6f, new Material(32f, .25f, bias, new Color(80, 200, 50)))); // blue

            scene.AddObject(new Sphere(new Vector3(0, 2, -15), 4.5f, new Material(32f, .1f, bias, new Color(100, 100, 200))));    // green

            scene.AddObject(new Sphere(new Vector3(-8, 2, -8), .5f, new Material(32f, 0, bias, new Color(10, 200, 200))));        // Cyan

            scene.AddObject(new Sphere(new Vector3(2, .15f, -2), .5f, new Material(32f, 1, bias, new Color(255, 255, 255))));     // clear

            scene.AddObject(new TriFace(new Vector3(5f, -3f, -5f), new Vector3(-5f, 0f, -5f), new Vector3(-0f, 10f, -30f), new Material(32f, .001f, bias, new Color(255, 255, 255))));

            //Draw the image
            scene.Render();

            //Write the image to file
            PPMWriter.WriteBitmapToPPM("./save.ppm", scene.GetScreenContents());
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            const int width  = 100;
            const int height = 100;
            var       canvas = new Canvas(width, height);

            var sphere = new Sphere();

            var origin = Tuple.Point(0, 0, -5);
            var red    = new Color(255, 0, 0);

            var scale = 0.01;

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    var ray = new Ray(origin,
                                      Tuple.Vector(scale * (x - 0.5 * width),
                                                   scale * (y - 0.5 * height), 1));

                    if (sphere.Intersect(ray).Count > 0)
                    {
                        canvas.SetPixel(x, y, red);
                    }
                }
            }

            PPMWriter.WriteToFile(canvas, "RayCast1.ppm");
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            /*
             * Console.Write("Donner le nombre de point que vous vouler afficher : ");
             * int nbre = int.Parse(Console.ReadLine());
             * Console.WriteLine(nbre);
             */
            //int nbre = 105;

            // Couleurs
            Color pen        = new Color(255, 0, 0);
            Color greenPen   = new Color(0, 255, 0);
            Color bluePen    = new Color(0, 0, 255);
            Color yellowPen  = new Color(255, 255, 0);
            Color background = new Color(255, 255, 255);
            // Couleur du centre du repère
            Color couleurCentreImage = new Color(0, 0, 0);

            // Images
            Bitmap img = new Bitmap(400, 400);

            img.Fill(background);

            // Centre du repere
            img.SetPixel(0 + img.Width / 2, img.Height / 2 - 0, couleurCentreImage);

            /*
             * Debut Affichage des figures
             */
            // Affichages des points
            //Drawer.DrawPoints(nbre, img, pen);

            // Affichages des cercles
            //Drawer.DrawCercles(img, pen);

            // Affichage des segments
            //Drawer.DrawSegments(img, pen);

            // Affichage des Facettes en fil de fer
            //Drawer.DrawFacettesFilDeFer(img, pen);

            // Affichage des Facette
            //Drawer.DrawFacette(img, pen);

            // Affichage d'un cube en fil de fer
            //Drawer.DrawCubeFilDeFer(img, pen);

            // Affichage des cubes en fil de fer
            //Cube c = Drawer.DrawCube();
            //Drawer.DrawCubeFilDeFer(c, img, greenPen, pen);

            // Affichage des cubes en complet
            Drawer.DrawCubeFaces(img);


            PPMWriter.WriteBitmapToPPM("IKheiryPPM.ppm", img);
            Console.WriteLine("Finish");
            Console.ReadLine();
        }
Ejemplo n.º 5
0
        public void TestEmptyLineEnd()
        {
            var canvas = new Canvas(5, 3);

            var ppmLines = PPMWriter.ToText(canvas).ToList();

            Assert.AreEqual(7, ppmLines.Count());
            Assert.AreEqual("", ppmLines.Last());
        }
Ejemplo n.º 6
0
        public void TestHeader()
        {
            var canvas = new Canvas(5, 3);

            var ppmLines = PPMWriter.ToText(canvas).ToList();

            Assert.AreEqual("P3", ppmLines[0]);
            Assert.AreEqual("5 3", ppmLines[1]);
            Assert.AreEqual("255", ppmLines[2]);
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            const int width  = 100;
            const int height = 100;
            var       canvas = new Canvas(width, height);

            var sphere = new Sphere();

            sphere.Material.Color = new Color(1, 0.2, 1);

            var light = new PointLight(Tuple.Point(-10, 10, -10), new Color(1, 1, 1));

            var origin = Tuple.Point(0, 0, -5);
            var red    = new Color(255, 0, 0);

            var scale = 0.01;

            for (int x = 0; x < width; x++)
            {
                System.Console.Write(".");
                for (int y = 0; y < height; y++)
                {
                    var ray = new Ray(origin,
                                      Tuple.Vector(scale * (x - 0.5 * width),
                                                   scale * (y - 0.5 * height), 1));
                    ray.Direction.Normalize();

                    var intersections = sphere.Intersect(ray);

                    if (intersections.Count > 0)
                    {
                        var hit       = intersections.Hit();
                        var hitObject = hit.Shape;
                        var point     = ray.Position(hit.Distance);
                        var normal    = hitObject.Normal(point);
                        var eye       = -ray.Direction;

                        var color = LightUtil.Lighting(hitObject.Material, hitObject, light, point, eye, normal, false);

                        canvas.SetPixel(x, y, color);
                    }
                }
            }

            PPMWriter.WriteToFile(canvas, "RayCast2.ppm");
        }
Ejemplo n.º 8
0
        public void TestSomeValues()
        {
            var canvas = new Canvas(5, 3);
            var c1     = new Color(1.5, 0, 0);
            var c2     = new Color(0, 0.5, 0);
            var c3     = new Color(-0.5, 0, 1);

            canvas.SetPixel(0, 0, c1);
            canvas.SetPixel(2, 1, c2);
            canvas.SetPixel(4, 2, c3);

            var ppmLines = PPMWriter.ToText(canvas).ToList();

            Assert.AreEqual("255 0 0 0 0 0 0 0 0 0 0 0 0 0 0", ppmLines[3]);
            Assert.AreEqual("0 0 0 0 0 0 0 127 0 0 0 0 0 0 0", ppmLines[4]);
            Assert.AreEqual("0 0 0 0 0 0 0 0 0 0 0 0 0 0 255", ppmLines[5]);
        }
Ejemplo n.º 9
0
        public void TestSplitLine()
        {
            var canvas = new Canvas(10, 2);
            var c      = new Color(1, 0.8, 0.6);

            for (int y = 0; y < 2; y++)
            {
                for (int x = 0; x < 10; x++)
                {
                    canvas.SetPixel(x, y, c);
                }
            }
            var ppmLines = PPMWriter.ToText(canvas).ToList();

            Assert.AreEqual("255 204 153 255 204 153 255 204 153 255 204 153 255 204 153 255 204", ppmLines[3]);
            Assert.AreEqual("153 255 204 153 255 204 153 255 204 153 255 204 153", ppmLines[4]);
            Assert.AreEqual("255 204 153 255 204 153 255 204 153 255 204 153 255 204 153 255 204", ppmLines[5]);
            Assert.AreEqual("153 255 204 153 255 204 153 255 204 153 255 204 153", ppmLines[6]);
        }
Ejemplo n.º 10
0
        public static IPNMWriter GetIPNMWriter(PNMType ptype)
        {
            IPNMWriter imWriter = null;

            switch (ptype)
            {
            case PNMType.PBM:
                imWriter = new PBMWriter();
                break;

            case PNMType.PGM:
                imWriter = new PGMWriter();
                break;

            case PNMType.PPM:
                imWriter = new PPMWriter();
                break;
            }

            return(imWriter);
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            const int width  = 1000;
            const int height = 500;

            var floor = new Plane()
            {
                Material = new Material()
                {
                    Color    = new Color(1, 0.9, 0.9),
                    Specular = 0
                }
            };


            var middle = new Sphere()
            {
                Transform = Matrix4.Translation(-0.5, 1, 0.5),
                Material  = new Material
                {
                    Color    = new Color(0.1, 1, 0.5),
                    Diffuse  = 0.7,
                    Specular = 0.3
                }
            };

            var right = new Sphere()
            {
                Transform = Matrix4.Translation(1.5, 0.5, -0.5) * Matrix4.Scaling(0.5, 0.5, 0.5),
                Material  = new Material
                {
                    Color    = new Color(0.5, 1, 0.1),
                    Diffuse  = 0.7,
                    Specular = 0.3
                }
            };

            var left = new Sphere()
            {
                Transform = Matrix4.Translation(-1.5, 0.33, -0.75) * Matrix4.Scaling(0.33, 0.33, 0.33),
                Material  = new Material
                {
                    Color    = new Color(1, 0.8, 0.1),
                    Diffuse  = 0.7,
                    Specular = 0.3
                }
            };

            var world = new World
            {
                Light  = new PointLight(Tuple.Point(-10, 10, -10), new Color(1, 1, 1)),
                Shapes = { floor, middle, left, right }
            };

            var cam = new Camera(width, height, System.Math.PI / 3)
            {
                Transform = Matrix4.ViewTransform(
                    Tuple.Point(0, 1.5, -5),
                    Tuple.Point(0, 1, 0),
                    Tuple.Vector(0, 1, 0))
            };

            var image = Renderer.Render(cam, world, p => System.Console.Write($"\rRendering {100 * p:N2}"));

            PPMWriter.WriteToFile(image, "RayCast4.ppm");
        }
Ejemplo n.º 12
0
        // 00:02:27.2397869 first run debug
        // 00:01:16.8428786 release
        // 00:01:13.2049173 debug parallel
        // 00:00:47.4624021 release parallel
        // 00:00:51.2508922 debug inner loop parallel
        // 00:00:42.3488772 debug parallel some inversion buffered
        // 00:00:09.0653539 debug parallel inversion buffered
        // 00:00:06.4252125 release parallel inversion buffered
        // 00:00:04.8961149 release parallel inversion buffered standalone

        static void Main(string[] args)
        {
            const int width  = 1000;
            const int height = 500;

            var floor = new Plane()
            {
                Material = new Material()
                {
                    Pattern = new NoisePattern(
                        new SpiralPattern(new Color(1, 0.9, 0.9), new Color(0.5, 0.3, 0.3))
                    {
                        Transform = Matrix4.Translation(0, 0, 2)
                    }
                        ),
                    Color    = new Color(1, 0.9, 0.9),
                    Specular = 0
                }
            };

            var middle = new Sphere()
            {
                Transform = Matrix4.Translation(-0.5, 1, 0.5),
                Material  = new Material
                {
                    Pattern = new CheckerPattern(new Color(0.1, 1, 0.5), new Color(0.0, 0.5, 0.3))
                    {
                        Transform = Matrix4.Scaling(0.2, 0.2, 0.2)
                    },
                    Color    = new Color(0.1, 1, 0.5),
                    Diffuse  = 0.7,
                    Specular = 0.3
                }
            };

            var right = new Sphere()
            {
                Transform = Matrix4.Translation(1.5, 0.5, -0.5) * Matrix4.Scaling(0.5, 0.5, 0.5),
                Material  = new Material
                {
                    Pattern = new StripedPattern(new Color(0.5, 1, 0.1), new Color(0.25, 0.5, 0.03))
                    {
                        Transform = Matrix4.Scaling(0.1, 0.1, 0.1).RotateY(0.6)
                    },

                    Color    = new Color(0.5, 1, 0.1),
                    Diffuse  = 0.7,
                    Specular = 0.3
                }
            };

            var left = new Sphere()
            {
                Transform = Matrix4.Translation(-1.5, 0.33, -0.75) * Matrix4.Scaling(0.33, 0.33, 0.33),
                Material  = new Material
                {
                    Pattern = new GradientPattern(new Color(0, 0, 1), new Color(1, 0, 0))
                    {
                        Transform = Matrix4.Scaling(0.2, 0.2, 0.2).RotateY(-0.6)
                    },
                    Color    = new Color(1, 0.8, 0.1),
                    Diffuse  = 0.7,
                    Specular = 0.3
                }
            };

            var world = new World
            {
                Light  = new PointLight(Tuple.Point(-10, 10, -10), new Color(1, 1, 1)),
                Shapes = { floor, middle, left, right }
            };

            var cam = new Camera(width, height, System.Math.PI / 3)
            {
                Transform = Matrix4.ViewTransform(
                    Tuple.Point(0, 1.5, -5),
                    Tuple.Point(0, 1, 0),
                    Tuple.Vector(0, 1, 0))
            };

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            var image = Renderer.Render(cam, world, p => System.Console.Write($"\rRendering {100 * p:N2}"));

            PPMWriter.WriteToFile(image, "RayCast6.ppm");

            stopwatch.Stop();
            System.Console.WriteLine($"Elapsed {stopwatch.Elapsed}");
        }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            const int width  = 1000;
            const int height = 500;

            var floor = new Sphere()
            {
                Transform = Matrix4.Scaling(10, 0.01, 10),
                Material  = new Material()
                {
                    Color    = new Color(1, 0.9, 0.9),
                    Specular = 0
                }
            };


            var leftWall = new Sphere()
            {
                Transform = Matrix4.Translation(0, 0, 5)
                            * Matrix4.RotationY(-0.25 * Math.PI)
                            * Matrix4.RotationX(0.5 * Math.PI)
                            * Matrix4.Scaling(10, 0.01, 10),
                Material = floor.Material
            };


            var rightWall = new Sphere()
            {
                Transform = Matrix4.Translation(0, 0, 5)
                            * Matrix4.RotationY(0.25 * Math.PI)
                            * Matrix4.RotationX(0.5 * Math.PI)
                            * Matrix4.Scaling(10, 0.01, 10),
                Material = floor.Material
            };

            var middle = new Sphere()
            {
                Transform = Matrix4.Translation(-0.5, 1, 0.5),
                Material  = new Material
                {
                    Color    = new Color(0.1, 1, 0.5),
                    Diffuse  = 0.7,
                    Specular = 0.3
                }
            };

            var right = new Sphere()
            {
                Transform = Matrix4.Translation(1.5, 0.5, -0.5) * Matrix4.Scaling(0.5, 0.5, 0.5),
                Material  = new Material
                {
                    Color    = new Color(0.5, 1, 0.1),
                    Diffuse  = 0.7,
                    Specular = 0.3
                }
            };

            var left = new Sphere()
            {
                Transform = Matrix4.Translation(-1.5, 0.33, -0.75) * Matrix4.Scaling(0.33, 0.33, 0.33),
                Material  = new Material
                {
                    Color    = new Color(1, 0.8, 0.1),
                    Diffuse  = 0.7,
                    Specular = 0.3
                }
            };

            var world = new World
            {
                Light  = new PointLight(Tuple.Point(-10, 10, -10), new Color(1, 1, 1)),
                Shapes = { floor, leftWall, rightWall, middle, left, right }
            };

            var cam = new Camera(width, height, Math.PI / 3)
            {
                Transform = Matrix4.ViewTransform(
                    Tuple.Point(0, 1.5, -5),
                    Tuple.Point(0, 1, 0),
                    Tuple.Vector(0, 1, 0))
            };

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

            PPMWriter.WriteToFile(image, "RayCast3.ppm");
        }