예제 #1
0
        private void RenderSingleThreaded(IPixelArray pixelArray, Camera camera, Scene scene, bool useKdTree)
        {
            var tracer = CreateRayTracer(camera, _renderData, scene, useKdTree);

            for (var y = 0; y < _renderData.Height; y++)
            {
                try
                {
                    pixelArray.Lock();
                    for (var x = 0; x < _renderData.Width; x++)
                    {
                        var color = tracer.GetPixelColor(x, y);
                        pixelArray.SetPixelColor(x, y, color);
                    }
                }
                finally
                {
                    pixelArray.Unlock();
                }

                Progress?.Invoke(
                    this,
                    new RenderProgressEventArgs((Convert.ToDouble(y) * 100.0) / Convert.ToDouble(_renderData.Height)));
            }
        }
예제 #2
0
        private void ResultFunc(
            IPixelArray pixelArray,
            ConcurrentQueue <RenderLineResult> resultQueue,
            AutoResetEvent queueDataAvailableEvent)
        {
            var incompleteRows = new HashSet <int>();

            for (var y = 0; y < pixelArray.Height; y++)
            {
                incompleteRows.Add(y);
            }

            while (incompleteRows.Count > 0)
            {
                queueDataAvailableEvent.WaitOne();

                try
                {
                    pixelArray.Lock();
                    while (resultQueue.TryDequeue(out var renderLineResult))
                    {
                        // assert pixelArray.Width == renderLineResult.Count
                        pixelArray.SetPixelRowColors(renderLineResult.Y, renderLineResult.RowPixels);
                        incompleteRows.Remove(renderLineResult.Y);

                        var totalRows       = Convert.ToDouble(pixelArray.Height);
                        var completeRows    = Convert.ToDouble(pixelArray.Height - incompleteRows.Count);
                        var percentComplete = completeRows / totalRows * 100.0;
                        Console.WriteLine($"Percent Complete: {percentComplete:F}%");

                        Progress?.Invoke(
                            this,
                            new RenderProgressEventArgs(percentComplete));
                    }
                }
                finally
                {
                    pixelArray.Unlock();
                }
            }
        }