public void Draw(Vector3[] activeChunks, Player player) { Vector3 chunkMax = new Vector3(size, 128, size); Vector3 position; float lightIntensity = time.LightIntensity; bool[] chunkVisible = new bool[activeChunks.Length]; effect.Parameters["World"].SetValue(Matrix.Identity); effect.Parameters["View"].SetValue(player.Camera.View); effect.Parameters["Projection"].SetValue(player.Camera.Projection); effect.Parameters["Texture"].SetValue(atlas); effect.Parameters["LightIntensity"].SetValue(lightIntensity); if (!game.Paused) { time.Update(); } graphics.Clear(Color.Lerp(Color.SkyBlue, Color.Black, 1f - lightIntensity)); //Drawing opaque blocks for (int i = 0; i < activeChunks.Length; i++) { position = activeChunks[i]; currentChunk = region[position]; BoundingBox chunkBounds = new BoundingBox(-position, chunkMax - position); chunkVisible[i] = player.Camera.Frustum.Contains(chunkBounds) != ContainmentType.Disjoint; if (chunkVisible[i] && currentChunk.VertexCount > 0) { effect.Parameters["Alpha"].SetValue(1f); buffer.SetData(currentChunk.Vertices); graphics.SetVertexBuffer(buffer); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); graphics.DrawPrimitives(PrimitiveType.TriangleList, 0, currentChunk.VertexCount / 3); } } } //Drawing transparent blocks for (int i = 0; i < activeChunks.Length; i++) { currentChunk = region[activeChunks[i]]; if (chunkVisible[i] && currentChunk.TransparentVertexCount > 0) { effect.Parameters["Alpha"].SetValue(0.7f); buffer.SetData(currentChunk.TransparentVertices); graphics.SetVertexBuffer(buffer); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); graphics.DrawPrimitives(PrimitiveType.TriangleList, 0, currentChunk.TransparentVertexCount / 3); } } } if (screenshotHandler.TakeScreenshot) { screenshotHandler.Screenshot(DateTime.Now.ToString()); } blockSelector.Draw(); }