예제 #1
0
        public static void Main(string[] args)
        {
            int       numThreads    = Environment.ProcessorCount / 2;
            const int RayTraceDepth = 50;
            const int NumSamples    = 1000;
            var       renderConfig  = new RenderConfig(numThreads, RayTraceDepth, NumSamples);

            string globeImagePath = Path.Combine(OutputDirectory, "globetex.jpg");
            // var scene = new ManySpheresScene();
            // var scene = new NoiseSpheresScene();
            // var scene = new ImageTextureScene(globeImagePath);
            // var scene = new LightsScene(globeImagePath);
            var scene = new CornellBoxScene();
            // var scene = new CornellBoxWithSmokeScene();
            IRenderer renderer    = new PerPixelRenderer();
            var       pixelBuffer = new PixelBuffer(Width, Height);

            string name = scene.GetType().Name.ToLowerInvariant();

            Console.WriteLine($"Executing {name} at resolution ({pixelBuffer.Width},{pixelBuffer.Height})");
            Console.WriteLine($"  Num Threads   = {numThreads}");
            Console.WriteLine($"  RayTraceDepth = {RayTraceDepth}");
            Console.WriteLine($"  Num Samples   = {NumSamples}");

            var sw           = Stopwatch.StartNew();
            var rendererData = renderer.Render(pixelBuffer, scene, renderConfig);

            sw.Stop();
            Console.WriteLine();
            Console.WriteLine($"Render complete: {sw.ElapsedMilliseconds}ms");
            Console.WriteLine($"Total Pixel Color Time: {rendererData.GetTotalPixelColorMilliseconds()}ms");
            Console.WriteLine($"Per Pixel Avg Time:     {rendererData.GetAveragePixelColorMilliseconds()}ms");

            string outputPath = Path.Combine(OutputDirectory, $"{name}.png");

            Console.WriteLine($"Saving image to {outputPath}");
            pixelBuffer.SaveAsFile(outputPath);


            // RunExecutors();
        }
예제 #2
0
        private void RenderButton_OnClick(object sender, RoutedEventArgs e)
        {
            int       numThreads    = Environment.ProcessorCount;
            const int ImageWidth    = 1000;
            const int ImageHeight   = 1000;
            const int RayTraceDepth = 50;
            const int NumSamples    = 10;
            var       renderConfig  = new RenderConfig(numThreads, RayTraceDepth, NumSamples)
            {
                TwoPhase = false
            };

            var scene = new CornellBoxScene();
            // var scene = NffParser.ParseFile(Path.Combine(NffDirectory, "balls5.nff"), ImageWidth, ImageHeight);

            // var pixelBuffer = new PixelBuffer(ImageWidth, ImageHeight);
            var pixelBuffer = new WpfPixelBuffer(Dispatcher, ImageWidth, ImageHeight);

            RenderImage.Source = pixelBuffer.WriteableBitmap;
            IRenderer renderer = new PerLineRenderer();

            string name       = scene.GetType().Name.ToLowerInvariant();
            string outputPath = Path.Combine(OutputDirectory, $"{name}.png");

            renderer.Progress += (_, args) => { Dispatcher.Invoke(() => { RenderProgress.Value = args.PercentComplete; }); };
            Task.Run(() =>
            {
                Dispatcher.Invoke(() => RenderButton.IsEnabled = false);
                var sw           = Stopwatch.StartNew();
                var rendererData = renderer.Render(pixelBuffer, scene, renderConfig);
                sw.Stop();
                Dispatcher.Invoke(() =>
                {
                    RenderTime.Text        = $"{sw.ElapsedMilliseconds}ms";
                    AvgGetColorMs.Text     = $"{rendererData.GetAveragePixelColorMilliseconds()}ms";
                    RenderButton.IsEnabled = true;
                });
                pixelBuffer.SaveAsFile(outputPath);
            });
        }