private static void ProcessSide(Chunk chunk, Chunk neighborChunk, FaceBuildingContext context) { foreach (var flatIndex in context.PendingVoxels) { var index = chunk.FromFlatIndex(flatIndex); var voxel = chunk.Voxels[flatIndex]; var neighbor = neighborChunk.CurrentHeight <= index.Y ? Voxel.SunBlock : neighborChunk.GetVoxel(context.GetNeighborIndex(index, neighborChunk.CurrentHeight)); var voxelDefinition = voxel.GetDefinition(); if (voxelDefinition.IsBlock) { var neighborDefinition = neighbor.GetDefinition(); if ((neighborDefinition.CoverFlags & context.OppositeDirection) == 0) { chunk.BuildingContext.VisibilityFlags.TryGetValue(flatIndex, out var visibility); chunk.BuildingContext.VisibilityFlags[flatIndex] = visibility | context.Direction; context.VoxelCount++; } } } }
private void BuildHorizontalFace(bool isInChunk, int neighborFlatIndex, Chunk chunk, VoxelDefinition definition, int flatIndex, ref VisibilityFlag visibilityFlag, ref byte voxelLight, FaceBuildingContext context) { if (isInChunk) { var neighbor = chunk.Voxels[neighborFlatIndex]; var neighborDefinition = neighbor.GetDefinition(); if (definition.IsBlock) { if ((neighborDefinition.CoverFlags & context.OppositeDirection) == 0 || (definition.CoverFlags & context.Direction) == 0) { visibilityFlag |= context.Direction; context.VoxelCount++; } } else { var lightDrop = VoxelDefinition.GetBrightnessLoss(neighborDefinition, definition, context.OppositeFace); if (voxelLight < neighbor.CompositeLight - lightDrop) { voxelLight = (byte)(neighbor.CompositeLight - lightDrop); } } } else if (definition.IsBlock) { context.PendingVoxels.Add(flatIndex); } }