コード例 #1
0
 public void AdvancePaths(FilmFrame fframe)
 {
     for (int i = 0; i < populationSize; i++)
     {
         var pathRadiance = EvaluatePath(paths[i].Vertices);
         var offset = (int)(Width * paths[i].Sample.ImageY + paths[i].Sample.ImageX);
         fframe.Data[offset] += pathRadiance;
         fframe.Weight[offset] += 1f;
     }
 }
コード例 #2
0
        public override void StartRendering(Action<IFilmFrame, int> taskCallback, Action<IFilmFrame> endTaskCallback)
        {
            var filmFrame = new FilmFrame(Width, Height);

            Console.Write("Rendering :[");
#if PL
            Parallel.For(0, Height, new ParallelOptions() { CancellationToken = this.cancelToken.Token, MaxDegreeOfParallelism = CpuThreadsUsed }, ( y) =>
#else
            for (int y = 0; y < height; y++)
#endif
            {
                for (int x = 0; x < Width; x++)
                {
                    for (int n = 0; n < this.samplesPerPixel; n++)
                    {
                        int ny = y;
                        IRay ray;
                        camera.GetRay(x + (1f - rnd.Value.NextFloat()), (ny) + (1f - rnd.Value.NextFloat()), out ray);
                        var pixelColor = Trace((RayInfo) ray, 1.0f, Air, 0);
                        if (!pixelColor.IsBlack())
                        {
                            //unchecked
                            {
                                filmFrame.Data[unchecked(x + y * Width)] = pixelColor;
                                filmFrame.Weight[unchecked(x + y * Width)] += 1f;
                            }
                        }
                    }
                }
                //for( int x=0; x<width;x++ )
                //    output.SetPixel(pixels[x + y * width].X, pixels[x + y * width].Y, (pixels[x + y * width].Data / pixels[x + y * width].Weight).ToColor());
                taskCallback(filmFrame, y);
            }
#if PL
);
#endif
            if (endTaskCallback != null)
                endTaskCallback(filmFrame);
        }
コード例 #3
0
ファイル: MCPathIntegrator.cs プロジェクト: HungryBear/rayden
        public override void StartRendering(Action<IFilmFrame, int> taskCallback, Action<IFilmFrame> endTaskCallback)
        {
            var frame = new FilmFrame(Width, Height);
            var start = DateTime.UtcNow;
            Console.Write("Rendering :[");

            ProcessSamples(frame, taskCallback);

            stats.elapsed = DateTime.UtcNow - start;
            if (endTaskCallback != null)
                endTaskCallback(frame);
            Console.WriteLine("{0:F9} MRays /sec", (stats.TotalRays / (double)stats.elapsed.Seconds) * 0.000001);
            Console.WriteLine("{0} Shadows samples per path", shadowRayCount);
            Console.WriteLine("{0} Triangles", scene.Geometry.Select(item => item.IndexData.Count / 3).Sum());
        }
コード例 #4
0
ファイル: MCPathIntegrator.cs プロジェクト: HungryBear/rayden
        private void ProcessSamples(FilmFrame fframe, Action<IFilmFrame, int> taskCallback)
        {
            bool done = false;
            int iteration = 0;
            var sw = new Stopwatch();
            sw.Start();
            while (!done)
            {

                for (int i = 0; i < SamplesPerIteration; i++)
                {
                    samples[i] = sampler.GetNextSample(rnd.Value);
                }
                Parallel.ForEach(samples, new ParallelOptions() { MaxDegreeOfParallelism = CpuThreadsUsed }, sample =>
                    {
#if VERBOSE
                    try {
#endif
                        IRay ray;

                        camera.GetRay(sample.ImageX, sample.ImageY, out ray);
                        var eyePathradiance = this.EvaluatePath(PropagatePath((RayInfo)ray, MaxRecursionLevel));
                        var offset = (int)(Width * sample.ImageY + sample.ImageX);
                        fframe.Data[offset] += eyePathradiance;
                        fframe.Weight[offset] += 1f;
                        stats.totalSamples = Interlocked.Increment(ref stats.totalSamples);
                        stats.elapsed = sw.Elapsed;

#if VERBOSE
                        }
                        catch(Exception ex) {
                            Console.WriteLine(ex.Message);
                            Console.WriteLine(ex.StackTrace);

                        }
#endif

                    });
                
                taskCallback(fframe, iteration);
                iteration++;
                done = sampler.SamplesPerPixel < sampler.CurrentPass;
            }
            sw.Stop();
        }