Ejemplo n.º 1
0
        public static void RowTestByDelegate(int spp, string fileSuffix, Func <int, Material> materialFunc)
        {
            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);

            var skySphere = new Sphere
            {
                Material = { Texture = map, Ambient = 1.5f, CastsShadows = false, Transparency = 1f }
            };

            skySphere.SetTransform(Transform.RotateY(3.4f).Scale(1000f));

            var g  = new Group();
            var dx = 2.75f;
            var dz = 3.5f;
            var y  = 1f;
            var nX = 10;
            var nZ = 1;
            int n  = 0;

            for (var z = 0; z < nZ; z++)
            {
                for (var x = 0; x < nX; x++)
                {
                    var s = new Sphere();
                    s.SetTransform(Transform.TranslateY(1f).Scale(1.2f).Translate(x * dx, 0, z * dz));
                    s.SetMaterial(materialFunc(x + 1));
                    g.AddChild(s);
                    n++;
                }
            }

            var lightGray = new Color(0.9f, 0.9f, 0.9f);
            var darkGray  = new Color(0.1f, 0.9f, 0.1f);
            var s1        = new StripeTexture(lightGray, darkGray);
            var s2        = new StripeTexture(lightGray, darkGray);

            s2.SetTransform(Transform.RotateY(MathF.PI / 2));
            var pattern = new BlendedCompositeTexture(s1, s2);

            pattern.SetTransform(Transform.Scale(1f / 30f));

            var text = new CheckerTexture(new Color(0.3f, 0.7f, 0.3f), new Color(0.13f, 0.13f, 0.13f));

            text.SetTransform(Transform.Scale(1f / 16f));

            var floor = new Cube
            {
                Material =
                {
                    Texture       = text,
                    SpecularColor = new Color(0.3f, 0.3f, 0.3f),
                    Metallic      =             0f,
                    Roughness     =          0.45f,
                    Ambient       = 0.15f
                }
            };

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

            var min = g.LocalBounds().Min;
            var max = g.LocalBounds().Max;
            var dir = max - min;
            var mid = min + (dir * 0.5f);

            var g2 = new Group(g, floor, skySphere);

            g2.Divide(1);

            var w = new World();

            w.SetLights(new PointLight(new Point(mid.X, 500, -500), new Color(1.7f, 1.7f, 1.7f)));
            w.SetObjects(g2);

            var width  = 1200;
            var height = 140;
            var from   = new Point(mid.X, 6f, -32f);
            var to     = mid;

            var canvas      = new Canvas(width, height);
            var pps         = new PerPixelSampler(spp);
            var fov         = MathF.PI / 4f;
            var aspectRatio = (float)width / height;
            var camera      = new ApertureCamera(fov, aspectRatio, 0.2F, from, to, Vectors.Up);
            var cws         = new ComposableWorldSampler(2,
                                                         16,
                                                         GGXNormalDistribution.Instance,
                                                         GGXSmithGeometricShadow.Instance,
                                                         SchlickFresnelFunction.Instance,
                                                         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), "col_row_" + fileSuffix);
            stopwatch.Stop();
            Console.WriteLine("Done ({0})", stopwatch.Elapsed);
        }
Ejemplo n.º 2
0
        public static void SolidTestRender(int spp)
        {
            Console.WriteLine("Loading file...");
            var filePath = Path.Combine(GetExecutionPath(), "neon_env.ppm");

            //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);

            var skySphere = new Sphere
            {
                Material =
                {
                    Texture       = map,            Ambient = 1.0f, CastsShadows = false, Transparency = 0f, Roughness = 1f,
                    SpecularColor = new Color(0.0f, 0.0f, 0.0f)
                }
            };

            skySphere.SetTransform(Transform.RotateY(3.3f).Scale(1000f));

            var radius = 0.25f;
            var red    = new Material {
                Texture = new SolidColor(new Color(1, 0, 0)), Reflective = 0.3f, Roughness = 0.3f, Ambient = 0.0f, Metallic = 0.3f, SpecularColor = new Color(0.3f, 0.3f, 0.3f)
            };
            var blue = new Material {
                Texture = new SolidColor(new Color(0, 0, 1)), Reflective = 0.3f, Roughness = 0.3f, Ambient = 0.0f, Metallic = 0.3f, SpecularColor = new Color(0.3f, 0.3f, 0.3f)
            };
            var yellow = new Material {
                Texture = new SolidColor(new Color(1, 1, 0)), Reflective = 0.3f, Roughness = 0.3f, Ambient = 0.0f, Metallic = 0.3f, SpecularColor = new Color(0.3f, 0.3f, 0.3f)
            };
            var white = new Material {
                Texture = new SolidColor(new Color(1, 1, 1)), Reflective = 0.3f, Roughness = 0.3f, Ambient = 0.0f, Metallic = 0.3f, SpecularColor = new Color(0.3f, 0.3f, 0.3f)
            };
            var blackPip = new Material {
                Texture = new SolidColor(new Color(0.1f, 0.1f, 0.1f)), Ambient = 0.0f, Roughness = 0.8f, Metallic = 0f, SpecularColor = new Color(0.2f, 0.2f, 0.2f)
            };
            var whitePip = new Material {
                Texture = new SolidColor(new Color(0.95f, 0.95f, 0.95f)), Ambient = 0.0f, Roughness = 0.8f, Metallic = 0f, SpecularColor = new Color(0.2f, 0.2f, 0.2f)
            };

            var d1 = CutPips(RoundedCube(radius, blue), whitePip);
            var d2 = CutPips(RoundedCube(radius, red), whitePip);
            var d3 = CutPips(RoundedCube(radius, white), blackPip);
            var d4 = CutPips(RoundedCube(radius, yellow), blackPip);

            d1.SetTransform(Transform.RotateY(-2.2f).TranslateY(1f).Scale(0.5f));
            d2.SetTransform(Transform.RotateZ(MathF.PI / 2f).TranslateY(1f).TranslateX(2f).TranslateZ(1f).Scale(0.5f));
            d3.SetTransform(Transform.RotateY(0.5f).TranslateY(1f).TranslateX(-4f).TranslateZ(1f).Scale(0.5f));
            d4.SetTransform(Transform.RotateY(-0.2f).TranslateY(3f).TranslateX(0.2f).TranslateZ(1.25f).Scale(0.5f));

            var lightGray = new Color(0.48f, 0.48f, 0.48f);
            var darkGray  = new Color(0.15f, 0.15f, 0.15f);
            //var s1 = new StripeTexture(lightGray, darkGray);
            //var s2 = new StripeTexture(lightGray, darkGray);
            //s2.SetTransform(Transforms.RotateY(MathF.PI / 2));
            //var pattern = new BlendedCompositeTexture(s1, s2);
            //pattern.SetTransform(Transforms.Scale(1f / 20f));

            var pattern = new CheckerTexture(lightGray, darkGray);

            pattern.SetTransform(Transform.Scale(1f / 20f));

            var floor = new Cube
            {
                Material =
                {
                    Texture       = pattern,
                    Roughness     =           0.5f,
                    Specular      =           0.1f,
                    Diffuse       =           0.3f,
                    Reflective    =          0.15f,
                    SpecularColor = new Color(0.3f, 0.3f, 0.3f),
                    Ambient       = 0f
                }
            };

            floor.SetTransform(Transform.TranslateY(-1f).Scale(20f));
            var g = new Group(d1, d2, d3, d4, floor, skySphere);

            g.Divide(1);

            var w = new World();

            w.SetLights(new AreaLight(new Point(-8, 10, -10), new Vector(12f, 0, 0), 6, new Vector(0, 0f, -10f), 3,
                                      new Color(1.1f, 1.1f, 1.1f), new Sequence(0.7f, 0.3f, 0.9f, 0.1f, 0.5f)));
            //w.SetLights(new PointLight(new Point(-8, 10, -10), new Color(0.9f, 0.9f, 0.9f)));
            //w.SetLights(new AreaLight(new Point(-3, 6, -4), new Vector(1f, 0, 0), 3, new Vector(0, 1f, 0), 3,
            //                          new Color(1.4f, 1.4f, 1.4f), new Sequence(0.7f, 0.3f, 0.9f, 0.1f, 0.5f)));
            //w.SetLights(new AreaLight(new Point(-10, 10, -10), new Vector(1,0,0), 4, new Vector(0,1,0), 3, Colors.White));
            w.SetObjects(g);

            //var width = 600;
            //var height = 400;
            //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 ws = new ComposableWorldShading(2, GGXNormalDistribution.Instance, SchlickBeckmanGeometricShadow.Instance, SchlickFresnelFunction.Instance, w);
            ////var ws = new PhongWorldShading(2, w);
            //var scene = new Scene(c, ws);
            ////var aaa = new AdaptiveRenderer(2, 0.01f, scene);
            //var aaa = new SamplesPerPixelRenderer(24, scene);
            //var canvas = new Canvas(width, height);

            var width  = 600;
            var height = 400;
            var from   = new Point(0, 1.5f, -5f);
            var to     = new Point(0, 1, -0.5f);

            var canvas = new Canvas(width, height);

            var pps         = new PerPixelSampler(spp);
            var fov         = MathF.PI / 3f;
            var aspectRatio = (float)width / height;
            var camera      = new ApertureCamera(fov, aspectRatio, 0.15f, from, to, Vectors.Up);
            //var transform = Transforms.View(from, to, new Vector(0, 1, 0));
            //var camera = new PinholeCamera2(transform, fov, aspectRatio);
            //var cws = new PhongWorldShading2(4, w);
            var cws = new ComposableWorldSampler(2,
                                                 4,
                                                 GGXNormalDistribution.Instance,
                                                 SchlickBeckmanGeometricShadow.Instance,
                                                 SchlickFresnelFunction.Instance,
                                                 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();
            // RenderContext.Render(canvas, aaa);
            PPM.ToFile(canvas, Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "solid");
            stopwatch.Stop();
            Console.WriteLine("Done ({0})", stopwatch.Elapsed);
        }
Ejemplo n.º 3
0
        public static void ColRowTestRender()
        {
            Console.WriteLine("Loading file...");
            //var filePath = Path.Combine(GetExecutionPath(), "indoor_env.ppm");
            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);

            var skySphere = new Sphere()
            {
                Material = { Texture = map, Ambient = 1.5f, CastsShadows = false, Transparency = 1f }
            };

            skySphere.SetTransform(Transform.RotateY(3.4f).Scale(1000f));

            var  g        = new Group();
            var  dx       = 2.75f;
            var  dz       = 3.5f;
            var  y        = 1f;
            var  nX       = 10;
            var  nZ       = 1;
            var  delta    = 1f / (nX * nZ - 1);
            int  n        = 0;
            bool metallic = false;

            for (var z = 0; z < nZ; z++)
            {
                for (var x = 0; x < nX; x++)
                {
                    var s = new Sphere();
                    s.SetTransform(Transform.TranslateY(1f).Scale(1.2f).Translate(x * dx, 0, z * dz));
                    // var color = x % 2 == 0 ? new Color(1f, 1f, 1f) : new Color(1f, 0.3f, 0.3f);
                    var color = new Color(1f, 0.3f, 0.3f);
                    s.Material.Texture       = SolidColor.Create(color);
                    s.Material.SpecularColor = metallic ? color : new Color(0.2f, 0.2f, 0.2f);
                    s.Material.Roughness     = MathFunction.Saturate(n * delta + 0.01f);
                    s.Material.Metallic      = metallic ? 1f : 0f;
                    s.Material.Ambient       = 0f;
                    s.Material.Reflective    = 0.9f;
                    g.AddChild(s);
                    n++;
                }
            }

            var lightGray = new Color(0.9f, 0.9f, 0.9f);
            var darkGray  = new Color(0.1f, 0.9f, 0.1f);
            var s1        = new StripeTexture(lightGray, darkGray);
            var s2        = new StripeTexture(lightGray, darkGray);

            s2.SetTransform(Transform.RotateY(MathF.PI / 2));
            var pattern = new BlendedCompositeTexture(s1, s2);

            pattern.SetTransform(Transform.Scale(1f / 30f));

            var text = new CheckerTexture(new Color(0.3f, 0.7f, 0.3f), new Color(0.13f, 0.13f, 0.13f));

            text.SetTransform(Transform.Scale(1f / 16f));

            var floor = new Cube
            {
                Material =
                {
                    Texture       = text,
                    SpecularColor = new Color(0.3f, 0.3f, 0.3f),
                    Metallic      =             0f,
                    Roughness     =          0.45f,
                    Ambient       = 0.15f
                }
            };

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

            var min = g.LocalBounds().Min;
            var max = g.LocalBounds().Max;
            var dir = max - min;
            var mid = min + (dir * 0.5f);

            var g2 = new Group(g, floor, skySphere);

            //var g2 = new Group(g);
            g2.Divide(1);

            var w = new World();

            w.SetLights(new PointLight(new Point(mid.X, 500, -500), new Color(1.7f, 1.7f, 1.7f)));
            w.SetObjects(g2);

            //var width = 1200;
            //var height = 140;
            //var transform = Transforms.View(new Point(mid.X, 6f, -32f), mid, new Vector(0, 1, 0));
            //var c = new PinholeCamera(transform, MathF.PI / 4f, width, height);
            ////var c = new ApertureCamera(MathF.PI / 4f, width, height, 0.04f, new Point(mid.X, 6f, -32f), mid);
            //var ws = new ComposableWorldShading(3, GGXNormalDistribution.Instance, GGXSmithGeometricShadow.Instance, SchlickFresnelFunction.Instance, w);
            ////var ws = new PhongWorldShading(3, w);
            //var scene = new Scene(c, ws);
            //var aaa = new AdaptiveRenderer(4, 0.00001f, scene);
            //var canvas = new Canvas(width, height);


            var width  = 1200;
            var height = 140;
            var from   = new Point(mid.X, 6f, -32f);
            var to     = mid;

            var canvas      = new Canvas(width, height);
            var pps         = new PerPixelSampler(400);
            var fov         = MathF.PI / 4f;
            var aspectRatio = (float)width / height;
            var camera      = new ApertureCamera(fov, aspectRatio, 0.2F, from, to, Vectors.Up);
            var cws         = new ComposableWorldSampler(2,
                                                         16,
                                                         GGXNormalDistribution.Instance,
                                                         GGXSmithGeometricShadow.Instance,
                                                         SchlickFresnelFunction.Instance,
                                                         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();
            //RenderContext.Render(canvas, aaa);
            PPM.ToFile(canvas, Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "col_row");
            stopwatch.Stop();
            Console.WriteLine("Done ({0})", stopwatch.Elapsed);
        }