Ejemplo n.º 1
0
        public void Run()
        {
            ints = new Intersection[Objects.Length];
            for (var i = 0; i < ints.Length; i++)
            {
                ints [i] = new Intersection();
            }

            var bmp = new PixelBuffer(1920, 1080);

            var ss = 10 / (Prec)bmp.Width;

            var startT = DateTime.Now;

            var ray = new Ray();

            var ns = 32;

            var rand = new Random();

            for (var y = 0; y < bmp.Height; y++)
            {
                for (var x = 0; x < bmp.Width; x++)
                {
                    var col = new Vec(0, 0, 0);

                    for (var samp = 0; samp < ns; samp++)
                    {
                        var r0 = CameraCenter;
                        var r1 = new Vec(
                            (Prec)(x + (ns > 1 ? rand.NextDouble() : 0.0) - bmp.Width / 2) * ss,
                            (Prec)(y + (ns > 1 ? rand.NextDouble() : 0.0) - bmp.Height / 2) * ss,
                            6);

                        var v = r1 - r0;
                        v.Normalize();

                        ray.Origin    = r0;
                        ray.Direction = v;

                        col += Trace(ray, 1);
                    }

                    col *= ((Prec)1) / ns;

                    bmp.PutPixel(x, y, col);
                }
            }

            var endT = DateTime.Now;
            var time = (endT - startT).TotalSeconds;

            System.Console.WriteLine("Rays/sec = {0}, T = {1}", bmp.Width * bmp.Height / time, time);

            bmp.SavePng();
        }
Ejemplo n.º 2
0
        public void Run()
        {
            ints = new Intersection[Objects.Length];
            for (var i = 0; i < ints.Length; i++) {
                ints [i] = new Intersection ();
            }

            var bmp = new PixelBuffer (1920, 1080);

            var ss = 10 / (Prec)bmp.Width;

            var startT = DateTime.Now;

            var ray = new Ray ();

            var ns = 32;

            var rand = new Random ();

            for (var y = 0; y < bmp.Height; y++) {
                for (var x = 0; x < bmp.Width; x++) {

                    var col = new Vec (0,0,0);

                    for (var samp = 0; samp < ns; samp++) {
                        var r0 = CameraCenter;
                        var r1 = new Vec (
                            (Prec)(x + (ns > 1 ? rand.NextDouble () : 0.0) - bmp.Width / 2) * ss,
                            (Prec)(y + (ns > 1 ? rand.NextDouble () : 0.0) - bmp.Height / 2) * ss,
                            6);

                        var v = r1 - r0;
                        v.Normalize ();

                        ray.Origin = r0;
                        ray.Direction = v;

                        col += Trace (ray, 1);
                    }

                    col *= ((Prec)1)/ns;

                    bmp.PutPixel (x, y, col);
                }
            }

            var endT = DateTime.Now;
            var time = (endT - startT).TotalSeconds;

            System.Console.WriteLine ("Rays/sec = {0}, T = {1}", bmp.Width * bmp.Height / time, time);

            bmp.SavePng ();
        }