Example #1
0
        public override void Render(Scene scene)
        {
            this.scene = scene;

            if (NumLightPaths <= 0)
            {
                NumLightPaths = scene.FrameBuffer.Width * scene.FrameBuffer.Height;
            }

            lightPaths = new LightPathCache {
                MaxDepth = MaxDepth, NumPaths = NumLightPaths, Scene = scene
            };

            for (uint iter = 0; iter < NumIterations; ++iter)
            {
                scene.FrameBuffer.StartIteration();
                lightPaths.TraceAllPaths(iter, null);
                ProcessPathCache();
                TraceAllCameraPaths(iter);
                scene.FrameBuffer.EndIteration();
            }
        }
Example #2
0
 protected virtual void AssemblePhotons(LightPathCache paths)
 {
     if (photons == null || photons.Length < paths.MaxDepth * paths.NumPaths)
     {
         photons = new PhotonReference[paths.MaxDepth * paths.NumPaths];
     }
     photonCount = 0;
     for (int i = 0; i < paths.NumPaths; ++i)
     {
         for (int k = 1; k < paths.PathCache.Length(i); ++k)
         {
             if (Filter(paths.PathCache[i, k]))
             {
                 photons[photonCount++] = new PhotonReference {
                     PathIndex   = i,
                     VertexIndex = k,
                     Position    = paths.PathCache[i, k].Point.Position
                 };
             }
         }
     }
 }
Example #3
0
        public void Build(LightPathCache paths, float averageRadius)
        {
            inverseBinSize = 0.5f / averageRadius;

            AssemblePhotons(paths);

            // Compute the bounding box of all photons
            bounds = BoundingBox.Empty;
            for (int i = 0; i < photonCount; ++i)
            {
                var p = photons[i];
                bounds = bounds.GrowToContain(p.Position);
            }

            // Add an offset for numerical stability
            var extents = bounds.Max - bounds.Min;

            bounds = new BoundingBox(
                max: bounds.Max + extents * 0.001f,
                min: bounds.Min - extents * 0.001f
                );

            // Count the number of photons per grid cell
            cellCounts = new int[NextPowerOfTwo(photonCount)];
            Parallel.For(0, photonCount, i => {
                var p    = photons[i];
                var hash = HashPhoton(p.Position);
                Interlocked.Increment(ref cellCounts[hash]);
            });

            // Compute the insertion position for each cell
            int sum = 0;

            for (int i = 0; i < cellCounts.Length; ++i)
            {
                cellCounts[i] = sum += cellCounts[i];
            }
            Debug.Assert(cellCounts[^ 1] == photonCount);