Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
 public void SaveAsFile(string outputFilePath)
 {
     _pixelBuffer.SaveAsFile(outputFilePath);
 }