public void CalculateAmbient() { #if WDEBUG if (!ThreadWorker.multithreading) { Profiler.BeginSample("Calculate Ambient"); } #endif //reading data if (ambientWorker.stop || !voxeland.useAmbient || voxeland.channelEncoding != Voxeland.ChannelEncoding.Voxeland) { ambient = null; return; } int topPoint; int bottomPoint; int margin = voxeland.ambientMargin; voxeland.data.GetTopBottomPoints(rect.Expanded(margin), out topPoint, out bottomPoint, ignoreEmptyColumns: true); //empty mesh check if (topPoint == 0) { ambient = null; return; } //create and fill matrix Matrix3 <byte> matrix = new Matrix3 <byte>(rect.offset.x - margin, bottomPoint - 1, rect.offset.z - margin, rect.size.x + margin * 2, topPoint - bottomPoint + 2, rect.size.z + margin * 2); voxeland.data.FillMatrix(matrix); if (ambientWorker.stop) { ambient = null; return; } if (ambient == null || ambient.cube.size != matrix.cube.size) { ambient = new Matrix3 <byte>(matrix.cube); } lock (ambient) { ambient.cube.offset = matrix.cube.offset; voxeland.data.FillMatrix(ambient); Matrix heightmap = new Matrix(ambient.cube.rect); voxeland.data.FillHeightmap(heightmap); if (ambientWorker.stop) { return; } ChunkMesh.HeightmapAmbient(ref ambient, heightmap); if (ambientWorker.stop) { return; } ChunkMesh.SpreadAmbient(ref ambient, voxeland.ambientFade); if (ambientWorker.stop) { return; } ChunkMesh.BlurAmbient(ref ambient); if (ambientWorker.stop) { return; } ChunkMesh.EqualizeBordersAmbient(ref ambient, margin: margin); } #if WDEBUG if (!ThreadWorker.multithreading) { Profiler.EndSample(); } #endif }