Esempio n. 1
0
        public static void MappingTestRender()
        {
            Cube Cube(float rotY, float rotX, float tx, float ty)
            {
                var cube1 = new Cube
                {
                    Material = { Texture = CreateTestCubeMap(), Roughness = 1f, SpecularColor = new Color(0.3f, 0.3f, 0.3f) }
                };

                cube1.SetTransform(Transform.RotateY(rotY).RotateX(rotX).Translate(tx, ty, 0));
                return(cube1);
            }

            var g = new Group();

            g.AddChild(Cube(0.7854f, 0.7854f, -6, 2));
            g.AddChild(Cube(2.3562f, 0.7854f, -2, 2));
            g.AddChild(Cube(3.927f, 0.7854f, 2, 2));
            g.AddChild(Cube(5.4978f, 0.7854f, 6, 2));
            g.AddChild(Cube(0.7854f, -0.7854f, -6, -2));
            g.AddChild(Cube(2.3562f, -0.7854f, -2, -2));
            g.AddChild(Cube(3.927f, -0.7854f, 2, -2));
            g.AddChild(Cube(5.4978f, -0.7854f, 6, -2));

            g.Divide(1);

            var w = new World();

            w.SetLights(new PointLight(new Point(0, 2, -100), Colors.White));
            w.SetObjects(g);

            var width  = 800;
            var height = 400;
            var from   = new Point(0, 0, -20f);
            var to     = new Point(0, 0, 0);

            var canvas      = new Canvas(width, height);
            var pps         = new PerPixelSampler(16);
            var fov         = 0.8f;
            var aspectRatio = (float)width / height;
            var transform   = Transform.LookAt(from, to, new Vector(0, 1, 0));
            var camera      = new PinholeCamera(transform, fov, aspectRatio);
            var cws         = new PhongWorldShading(1, w);
            var ctx         = new RenderContext(canvas, new RenderPipeline(cws, camera, pps));

            Console.WriteLine("Rendering at {0}x{1}...", width, height);
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            ctx.Render();
            PPM.ToFile(canvas, Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "mapping");
            stopwatch.Stop();
            Console.WriteLine("Done ({0})", stopwatch.Elapsed);
        }
Esempio n. 2
0
        public static void LowPolyTeapotTest()
        {
            var path         = Path.Combine(GetExecutionPath(), "teapot-low.obj");
            var data         = ObjFile.ParseFile(path);
            var triangulated = data.Groups[0];

            triangulated.SetTransform(Transform.Scale(0.1f).RotateX(-MathF.PI / 2f));

            var material = new Material
            {
                Texture    = new SolidColor(new Color(0.3f, 0.3f, 1f)),
                Reflective = 0.4f,
                Ambient    = 0.2f,
                Diffuse    = 0.3f
            };

            var floor = new Cube();

            floor.SetMaterial(material);
            var fg = new Group();

            fg.AddChild(floor);
            fg.SetTransform(Transform.TranslateY(-1).Scale(1f));

            var g = new Group(fg, triangulated);

            g.Divide(1);

            var w = new World();

            w.SetLights(new PointLight(new Point(-10, 10, -10), Colors.White));
            w.SetObjects(g);

            //var width = 300;
            //var height = 200;
            //var transform = Transforms.View(new Point(0, 1.5f, -5f), new Point(0, 1, 0), new Vector(0, 1, 0));
            //var c = new PinholeCamera(transform, MathF.PI / 3f, width, height);
            //var scene = new Scene(c, new PhongWorldShading(1, w));
            //var canvas = new Canvas(width, height);

            var width  = 300;
            var height = 200;
            var from   = new Point(0, 1.5f, -5f);
            var to     = new Point(0, 1, 0);

            var canvas      = new Canvas(width, height);
            var pps         = new PerPixelSampler(3);
            var fov         = MathF.PI / 3f;
            var aspectRatio = (float)width / height;
            var transform   = Transform.LookAt(from, to, new Vector(0, 1, 0));
            var camera      = new PinholeCamera(transform, fov, aspectRatio);
            var cws         = new PhongWorldShading(1, w);
            var ctx         = new RenderContext(canvas, new RenderPipeline(cws, camera, pps));

            Console.WriteLine("Rendering at {0}x{1}...", width, height);
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            //RenderContext.Render(canvas, scene);
            ctx.Render();
            PPM.ToFile(canvas, Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "teapot");
            stopwatch.Stop();
            Console.WriteLine("Done ({0})", stopwatch.Elapsed);
        }
Esempio n. 3
0
        public static void SphereMappingTestRender()
        {
            Console.WriteLine("Loading file...");
            var filePath = Path.Combine(GetExecutionPath(), "winter_river_1k.ppm");

            Console.WriteLine("Parsing file...");
            var textureCanvas = PPM.ParseFile(filePath);
            var image         = new UVImage(textureCanvas);
            var map           = new TextureMap(image, UVMapping.Spherical);


            Sphere Sphere(float rotY, float rotX, float tx, float ty)
            {
                var s = new Sphere()
                {
                    Material = { Texture = map }
                };

                s.SetTransform(Transform.RotateY(rotY).RotateX(rotX).Translate(tx, ty, 0));
                return(s);
            }

            var g = new Group();

            g.AddChild(Sphere(0.7854f, 0.7854f, -6, 2));
            g.AddChild(Sphere(2.3562f, 0.7854f, -2, 2));
            g.AddChild(Sphere(3.927f, 0.7854f, 2, 2));
            g.AddChild(Sphere(5.4978f, 0.7854f, 6, 2));
            g.AddChild(Sphere(0.7854f, -0.7854f, -6, -2));
            g.AddChild(Sphere(2.3562f, -0.7854f, -2, -2));
            g.AddChild(Sphere(3.927f, -0.7854f, 2, -2));
            g.AddChild(Sphere(5.4978f, -0.7854f, 6, -2));

            g.Divide(1);

            var w = new World();

            w.SetLights(new PointLight(new Point(0, 2, -100), Colors.White));
            w.SetObjects(g);

            var width  = 800;
            var height = 400;
            var from   = new Point(0, 0, -20f);
            var to     = new Point(0, 0, 0);

            var canvas      = new Canvas(width, height);
            var pps         = new PerPixelSampler(16);
            var fov         = 0.8f;
            var aspectRatio = (float)width / height;
            var transform   = Transform.LookAt(from, to, new Vector(0, 1, 0));
            var camera      = new PinholeCamera(transform, fov, aspectRatio);
            var cws         = new PhongWorldShading(1, w);
            var ctx         = new RenderContext(canvas, new RenderPipeline(cws, camera, pps));

            Console.WriteLine("Rendering at {0}x{1}...", width, height);
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            ctx.Render();
            PPM.ToFile(canvas, Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "mapping_spheres");
            stopwatch.Stop();
            Console.WriteLine("Done ({0})", stopwatch.Elapsed);
        }