private static VertexColorInfo CalculateVertexLight(VoxelHandle Vox, VoxelVertex Vertex, ChunkManager chunks) { var neighborsEmpty = 0; var neighborsChecked = 0; var color = new VertexColorInfo(); color.DynamicColor = 0; color.SunColor = 0; foreach (var c in VoxelHelpers.EnumerateVertexNeighbors(Vox.Coordinate, Vertex)) { var v = chunks.CreateVoxelHandle(c); if (!v.IsValid) { continue; } color.SunColor += v.Sunlight ? 255 : 0; if (!v.IsEmpty || !v.IsExplored) { if (v.Type.EmitsLight) { color.DynamicColor = 255; } neighborsEmpty += 1; neighborsChecked += 1; } else { neighborsChecked += 1; } } var boost = GetAmbienceBoost(Vertex); var proportionHit = (float)neighborsEmpty / (float)neighborsChecked; color.AmbientColor = (int)Math.Min((1.0f - proportionHit) * 255.0f, 255); color.SunColor = (int)Math.Min((float)color.SunColor / (float)neighborsChecked + boost * 255.0f, 255); return(color); }