Esempio n. 1
0
        static void Main(string[] args)
        {
            //byte[] testData = new byte[] { 0, 255, 0, 0, 255, 0, 0, 255, 0, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
            // 255, 0, 0, 255, 0, 0, 255, 0, 0, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
            // 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
            // 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
            // 255, 0, 0, 255, 0, 0, 255, 0, 0, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
            // 255, 0, 0, 255, 0, 0, 255, 0, 0, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
            // 255, 0, 0, 255, 0, 0, 255, 0, 0, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
            // 255, 0, 0, 255, 0, 0, 255, 0, 0, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
            // 255, 0, 0, 255, 0, 0, 255, 0, 0, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127
            // };
            //Output.createBMP(testData, 16, 9, "test.bmp");
            //return;

            //  int w = 960, h = 540, samplesCount = 2048; time  = 180
            // C# is 24 times slower than c++!
            int w = 320, h = 180, samplesCount = 64;
            Vec position    = new Vec(-22, 5, 25);
            Vec dirObserver = (new Vec(-10, 4, 0)).minus(position).normalize();

            sw.Start();
            Console.WriteLine($"Started path tracing at {DateTime.Now.ToString("HH:mm:ss")} with sampleCount {samplesCount}");
            var pathTracer = new PathTracer();

            pathTracer.run(position, dirObserver, samplesCount, w, h);
            sw.Stop();
            Console.WriteLine($"Finished in {sw.ElapsedMilliseconds/1000.0} s");
            Console.ReadKey();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            //byte[] testData = new byte[] { 0, 255, 0, 0, 255, 0, 0, 255, 0, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
            // 255, 0, 0, 255, 0, 0, 255, 0, 0, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
            // 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
            // 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
            // 255, 0, 0, 255, 0, 0, 255, 0, 0, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
            // 255, 0, 0, 255, 0, 0, 255, 0, 0, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
            // 255, 0, 0, 255, 0, 0, 255, 0, 0, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
            // 255, 0, 0, 255, 0, 0, 255, 0, 0, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
            // 255, 0, 0, 255, 0, 0, 255, 0, 0, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127
            // };
            //Output.createBMP(testData, 16, 9, "test.bmp");
            //return;

            //  int w = 960, h = 540, samplesCount = 16;
            int w = 640, h = 270, samplesCount = 8;
            Vec position    = new Vec(-22, 5, 25);
            Vec dirObserver = (new Vec(-10, 4, 0)).minus(position).normalize();


            sw.Start();
            var pathTracer = new PathTracer();

            pathTracer.run(position, dirObserver, samplesCount, w, h);
            sw.Stop();
            Console.WriteLine($"Finished in {sw.ElapsedMilliseconds} ms");
            Console.ReadKey();
        }
Esempio n. 3
0
        public void Render(Scene s, CancellationToken token)
        {
            var integrator = new PathTracer();

            // Use ParallelOptions instance to store the CancellationToken
            ParallelOptions po = new ParallelOptions()
            {
                MaxDegreeOfParallelism = 3,
                CancellationToken      = token
            };

            try
            {
                while (totalSamples < maxTotalSamples)
                {
                    var samples = SamplePointsOnImagePlane(s, 1);
                    Parallel.ForEach(samples, po, samp =>
                    {
                        // if cancel requested from GUI, cancel
                        token.ThrowIfCancellationRequested();

                        var rayTo = new Vector3(samp.X - s.ImagePlaneWidth / 2, samp.Y - s.ImagePlaneHeight / 2 + s.ImagePlaneVerticalOffset, s.ImagePlaneDistance);
                        // ray through point
                        Ray r = new Ray(s.CameraOrigin, rayTo);

                        Console.WriteLine("evaluating radiance");
                        // evaluate radiance
                        Spectrum L = integrator.Li(r, s);
                        Console.WriteLine("radiance evaluated");

                        // add radiance to image
                        AddToImage(samp, L, s);
                    });
                }
            }
            catch (OperationCanceledException)
            {
            }
        }
Esempio n. 4
0
        public void Render(Scene s, CancellationToken token)
        {
            var integrator = new PathTracer();

            // Use ParallelOptions instance to store the CancellationToken
            ParallelOptions po = new ParallelOptions()
            {
                MaxDegreeOfParallelism = 8,
                CancellationToken      = token
            };

            try
            {
                //DirectoryInfo d = new DirectoryInfo(@"D:\NRG seminarska\");
                //FileInfo[] Files = d.GetFiles("*.binary");

                //foreach (FileInfo file in Files)
                //{
                //Scene.brdfFileName = file.Name;
                //Console.WriteLine(file.Name);
                //while (totalSamples < maxTotalSamples)
                while (true)
                {
                    var samples = SamplePointsOnImagePlane(s, 1);
                    Parallel.ForEach(samples, po, samp =>
                    {
                        // if cancel requested from GUI, cancel
                        token.ThrowIfCancellationRequested();

                        var rayTo = new Vector3(samp.X - s.ImagePlaneWidth / 2, samp.Y - s.ImagePlaneHeight / 2 + s.ImagePlaneVerticalOffset, s.ImagePlaneDistance);
                        // ray through point
                        Ray r = new Ray(s.CameraOrigin, rayTo);

                        // evaluate radiance
                        Spectrum L = integrator.Li(r, s);

                        // add radiance to image
                        AddToImage(samp, L, s);
                    });
                }

                //Neki:
                //    try
                //    {
                //        finalRgbImage.Save(@"D:\NRG seminarska\" + DateTime.Now.ToString().Replace("/", "-").Replace(":", "-").Replace(" ", "_") + "_" + file.Name.Replace(".binary", "") + ".png", ImageFormat.Png);
                //    }
                //    catch (Exception)
                //    {
                //        Thread.Sleep(1);
                //        goto Neki;
                //    }
                //    s = Scene.CornellBox();
                //    finalImageSum = new Spectrum[pixelWidth, pixelHeight];
                //    finalImage = new Spectrum[pixelWidth, pixelHeight];
                //    finalRgbImage = new Bitmap(160, (int)Math.Round(160 / s.AspectRatio), PixelFormat.Format24bppRgb);
                //    pixelWeights = new double[pixelWidth, pixelHeight];
                //    bmp = finalRgbImage;
                //    totalSamples = 0;
                //bmp = b;
                //}
            }
            catch (OperationCanceledException)
            {
            }
            catch (Exception e) {
                Console.WriteLine(e);
            }
        }