private TerrainMap PrepareGeometryMap(ChunkMaskBlock[,] blocks, int border) { var result = new Color[blocks.Length]; for (int z = 0; z <= blocks.GetUpperBound(1); z++) for (int x = 0; x <= blocks.GetUpperBound(0); x++) { var normal = blocks[x, z].Normal; result[x + z * blocks.GetLength(1)].r = normal.x / 2 + 0.5f; result[x + z * blocks.GetLength(1)].g = normal.y / 2 + 0.5f; result[x + z * blocks.GetLength(1)].b = normal.z / 2 + 0.5f; result[x + z * blocks.GetLength(1)].a = Vector3.Angle(normal, Vector3.up)/90f; } var resultTexture = new Texture2D(blocks.GetLength(0), blocks.GetLength(1), TextureFormat.RGBA32, false); resultTexture.wrapMode = TextureWrapMode.Clamp; resultTexture.SetPixels(result); resultTexture.Apply(false, true); return new TerrainMap() {Map = resultTexture, Border = border}; }
private Texture2D PrepareBlockTypeMask(ChunkMaskBlock[,] blocks) { var result = new Color[blocks.Length]; for (int z = 0; z <= blocks.GetUpperBound(1); z++) for (int x = 0; x <= blocks.GetUpperBound(0); x++) { var blockType = blocks[x, z].Block; if (blockType == BlockType.Grass) result[x + z * blocks.GetLength(1)] = new Color(0, 1, 0, 0); else if (blockType == BlockType.Sand) result[x + z * blocks.GetLength(1)] = new Color(1, 0, 0, 0); else if (blockType == BlockType.Water) result[x + z * blocks.GetLength(1)] = new Color(0, 0, 1, 0); else if (blockType == BlockType.Snow) result[x + z * blocks.GetLength(1)] = new Color(0, 0, 0, 1); //Stone - no color at all } var resultTexture = new Texture2D(blocks.GetLength(0), blocks.GetLength(1), TextureFormat.RGBA32, false); resultTexture.wrapMode = TextureWrapMode.Clamp; resultTexture.SetPixels(result); resultTexture.Apply(false, true); return resultTexture; }