private void GenerateCustomHexMesh(bool raiseBorders) { Texture2D localHeightMap; localMesh.vertices = parentChunk.worldManager.flatHexagonSharedMesh.vertices; localMesh.triangles = parentChunk.worldManager.flatHexagonSharedMesh.triangles; localMesh.uv = parentChunk.worldManager.flatHexagonSharedMesh.uv; //we use tangents as an extra uv channel and to pass in the FOW settings localMesh.tangents = parentChunk.worldManager.flatHexagonSharedMesh.uv.ToVector4(1, 0); if (terrainFeature == Feature.Mountain) { localHeightMap = NoiseGenerator.RandomOverlay(parentChunk.worldManager.mountainHeightMap, Random.Range(-500f, 500f), parentChunk.worldManager.mountainDefines.noiseScale, ///0.005f-0.18f parentChunk.worldManager.mountainDefines.noiseSize, //0.2-0.5f Random.Range(0.3f, 0.6f), //0.3-0.6 parentChunk.worldManager.mountainDefines.maximumHeight, //2 true, false); } else if (terrainFeature == Feature.Hill) { localHeightMap = NoiseGenerator.RandomOverlay(parentChunk.worldManager.mountainHeightMap, Random.Range(-100f, 100f), parentChunk.worldManager.hillDefines.noiseScale, //0.005-0.18 parentChunk.worldManager.hillDefines.noiseSize, //0.75-1 Random.Range(0.4f, 0.7f), parentChunk.worldManager.hillDefines.maximumHeight, //2 true, false); } else { localHeightMap = NoiseGenerator.RandomOverlay(parentChunk.flatHeightMap, Random.Range(-100f, 100f), parentChunk.worldManager.flatDefines.noiseScale, parentChunk.worldManager.flatDefines.noiseSize, Random.Range(0.4f, 0.7f), parentChunk.worldManager.flatDefines.maximumHeight, false, false); } Vector3[] vertices = localMesh.vertices; for (int i = 0; i < vertices.Length; i++) { if (VertexIsEdge(i)) { if (IsLandVertex(i) && raiseBorders == true) { vertices[i].Set(vertices[i].x, 0.06f, vertices[i].z); } else { vertices[i].Set(vertices[i].x, 0f, vertices[i].z); } } else { float pixelHeight = localHeightMap.GetPixelBilinear(localMesh.uv[i].x, localMesh.uv[i].y).grayscale; if (terrainFeature == Feature.Mountain) { pixelHeight *= 1.5f; vertices[i].Set(vertices[i].x, vertices[i].y + (pixelHeight - (parentChunk.worldManager.mountainDefines.yScale / 100)), vertices[i].z); } if (terrainFeature == Feature.Hill) { vertices[i].Set(vertices[i].x, vertices[i].y + (pixelHeight - (parentChunk.worldManager.hillDefines.yScale / 100)), vertices[i].z); } //flat else { pixelHeight = localHeightMap.GetPixelBilinear(localMesh.uv[i].x + (chunkArrayPosition.x * localMesh.uv[i].x), localMesh.uv[i].y + (chunkArrayPosition.y * localMesh.uv[i].y)).grayscale; vertices[i].Set(vertices[i].x, vertices[i].y + pixelHeight / 10, vertices[i].z); } } } localMesh.vertices = vertices; //recalculate normals to play nicely with lighting localMesh.RecalculateNormals(); //assign tile texture AssignUVToDefaultTile(); }