protected override void OnUpdateRenderLightmap(out bool finished) { finished = false; //render bucket { //DoLogEvent( string.Format( "Render bucket {0},{1}", lightmapBucketIndex.X, // lightmapBucketIndex.Y ) ); RectI bucketRectangle = new RectI(lightmapBucketIndex * bucketSize, (lightmapBucketIndex + new Vec2I(1, 1)) * bucketSize); if (bucketRectangle.Right > lightmapRenderingImage.Size.X) { bucketRectangle.Right = lightmapRenderingImage.Size.X; } if (bucketRectangle.Bottom > lightmapRenderingImage.Size.Y) { bucketRectangle.Bottom = lightmapRenderingImage.Size.Y; } lightmapRenderingImage.Fill(bucketRectangle, new ColorValue(1, 1, 0)); ColorValue[] colors = new ColorValue[bucketRectangle.Size.X * bucketRectangle.Size.Y]; for (int y = bucketRectangle.Minimum.Y; y < bucketRectangle.Maximum.Y; y++) { for (int x = bucketRectangle.Minimum.X; x < bucketRectangle.Maximum.X; x++) { Vec2I pixelIndex = new Vec2I(x, y); ColorValue color = RenderPixel(pixelIndex); Vec2I colorIndex = pixelIndex - bucketRectangle.Minimum; colors[colorIndex.Y * bucketRectangle.Size.X + colorIndex.X] = color; } } lightmapRenderingImage.Fill(bucketRectangle, colors); } //change bucket { Vec2I bucketCount = lightmapRenderingImage.Size / bucketSize; if (lightmapRenderingImage.Size.X % bucketSize != 0) { bucketCount.X++; } if (lightmapRenderingImage.Size.Y % bucketSize != 0) { bucketCount.Y++; } lightmapBucketIndex.X++; if (lightmapBucketIndex.X >= bucketCount.X) { lightmapBucketIndex.X = 0; lightmapBucketIndex.Y++; if (lightmapBucketIndex.Y >= bucketCount.Y) { finished = true; } } } //image finished. do final operations. if (finished) { lightmapRenderingImage.FillHoles(5); lightmapRenderingImage.Finish(); } }