Example #1
0
        public static void TestRender(int spp, int height)
        {
            var aspectRatio = 1f;
            var width       = (int)(height * aspectRatio);
            var from        = new Point(278, 278, -800f);
            var to          = new Point(278, 278, 0);

            var fov = MathF.Deg(278f / 400f);

            //var transform = Transform.LookAt2(from, to, Vectors.Up);
            var transform = Transform.Translate(278, 278, -800);
            var dist      = Point.Distance(from, to);

            var filter = new MitchellFilter(new Vector2(2f, 2f), 0.5f, 0.25f);
            var film   = new Film(new PixelVector(width, height), new Bounds2D(0, 0, 1, 1), filter, 20f, 1f);
            var camera = PerspectiveCamera.Create(transform, aspectRatio, 0.8f, dist, fov, film);

            //var integrator = new AmbientOcclusionIntegrator(true, 64, camera,
            //                                                new HaltonSampler(spp, film.GetSampleBounds()),
            //                                                film.CroppedBounds);

            //var integrator = new DepthIntegrator(700f, 1000f, camera, new HaltonSampler(spp, film.GetSampleBounds()),
            //                                                film.CroppedBounds);

            //var integrator = new NormalIntegrator(camera, new HaltonSampler(spp, film.GetSampleBounds()),
            //                                                film.CroppedBounds);

            //var integrator = new WhittedIntegrator(5, camera, new HaltonSampler(spp, film.GetSampleBounds()),
            //                                       film.CroppedBounds);

            var integrator = new PathIntegrator(5, camera, new HaltonSampler(spp, film.GetSampleBounds()),
                                                film.CroppedBounds, 1f, LightSampleStrategy.Uniform);

            film.SetSink(new Sink(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "tri"));

            var scene = Build();

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

            stopwatch.Start();
            integrator.Render(scene);
            stopwatch.Stop();
            Console.WriteLine("Done ({0})", stopwatch.Elapsed);
        }
Example #2
0
        public static void RowTestByDelegate(int spp, string fileSuffix, Func <float, int, IMaterial> materialFunc)
        {
            var dx    = 3.65f;
            var nX    = 11;
            var delta = 1f / (nX - 1);
            var prims = new List <IPrimitive>();

            for (var x = 0; x < nX; x++)
            {
                var s1t = Transform.Translate(x * dx, 0, 0);
                var s1  = new Sphere(s1t, Transform.Invert(s1t), false, 1.5f, -1.5f, 1.5f, 360);
                var s1g = new GeometricPrimitive(s1, materialFunc(delta * x, x + 1), null);
                prims.Add(s1g);
            }

            var slt = Transform.Translate(5, 2, -4);
            var slg = new Sphere(slt, Transform.Invert(slt), false, 0.5f, -0.5f, 0.5f, 360);
            var ls  = Spectrum.FromBlackbodyT(7500);
            var dl  = new DiffuseAreaLight(slt, null, ls * 100, 20, slg);
            var sg  = new GeometricPrimitive(slg, new MatteMaterial(new ConstantTexture <Spectrum>(ls), new ConstantTexture <float>(0f), null), dl);

            prims.Add(sg);

            var bvh = new BVH(prims.ToArray(), SplitMethod.HLBVH);

            var mid = bvh.WorldBounds.Centroid;

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

            var fov         = 5.6f;
            var aspectRatio = (float)width / height;

            var transform = Transform.Translate(mid.X, 0f, -50f);
            var dist      = Point.Distance(from, to);
            var filter    = new MitchellFilter(new Vector2(2.5f, 2.5f), 0.7f, 0.15f);
            var film      = new Film(new PixelVector(width, height), new Bounds2D(0, 0, 1, 1), filter, 20f, 1f);
            var camera    = PerspectiveCamera.Create(transform, aspectRatio, 0.0f, dist, fov, film);

            //var integrator = new WhittedIntegrator(4, camera, new HaltonSampler(spp, film.GetSampleBounds()),
            //                                       film.CroppedBounds);

            var integrator = new PathIntegrator(3, camera, new HaltonSampler(spp, film.GetSampleBounds()),
                                                film.CroppedBounds, 6f, LightSampleStrategy.Spatial);

            film.SetSink(new Sink(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "row_" + fileSuffix));

            var lt  = Transform.Translate(mid.X - 60, 200, -80);
            var s   = Spectrum.FromBlackbodyT(4500) * 100000f;
            var pl1 = new PointLight(lt, null, s);

            lt = Transform.Translate(mid.X + 100, 100, -200);
            s  = Spectrum.FromBlackbodyT(2200) * 50000f;
            var pl2 = new PointLight(lt, null, s);

            lt = Transform.Translate(mid.X, 1000f, 0);
            s  = Spectrum.FromBlackbodyT(7000) * 5f;
            var pl3 = new DistantLight(lt, s, new Vector(0, -0.5f, 1));

            lt = Transform.Translate(mid.X, 10, -300);
            s  = Spectrum.FromBlackbodyT(5500) * 100000f;
            var pl4 = new PointLight(lt, null, s);

            var splt = Transform.RotateX(MathF.Rad(18f)).RotateY(MathF.Rad(75)).Translate(0, 10, -8);

            s = Spectrum.FromBlackbodyT(5500) * 100000f;
            var sl = new SpotLight(splt, null, s, 5f, 2f);

            var scene = new Scene(bvh, new ILight[] { pl1, pl2, pl3, pl4, dl, sl });

            //var scene = new Scene(bvh, new ILight[] { dl });

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

            stopwatch.Start();
            integrator.Render(scene);
            stopwatch.Stop();
            Console.WriteLine("Done ({0})", stopwatch.Elapsed);
        }