private static float GetHeightAt(Config cfg, Cubemap heightMap, Vector3 radiusVector) { Color pixel = CubemapProjections.ReadPixel(heightMap, radiusVector); // Altitude above water level float heightDelta = pixel.r * (cfg.oceanDepth + cfg.mountainHeight) - cfg.oceanDepth; return(cfg.radius + heightDelta); }
private static Cubemap GenerateHeightmap(Config cfg) { Random.State savedState = Random.state; int size = cfg.heightCubemapSize; Cubemap heightMap = new Cubemap(size, TextureFormat.RGB24, false); // Pixels are laid out right to left, top to bottom Color[] pixels = new Color[size * size]; Color pixel = new Color(); var generator = new LibNoise.Generator.Perlin(); generator.Frequency = cfg.noiseScale; generator.OctaveCount = cfg.octaves; generator.Seed = cfg.seed; foreach (CubemapFace face in System.Enum.GetValues(typeof(CubemapFace))) { if (face == CubemapFace.Unknown) { continue; } for (int y = 0; y < size; ++y) { for (int x = 0; x < size; ++x) { Vector2 uv = new Vector2((float)x / (size - 1), (float)y / (size - 1)); Vector3 radiusVec = CubemapProjections.GetRadiusVectorFromFace(face, uv); /*pixel.r = (radius.x + 1) * 0.5f; * pixel.g = (radius.y + 1) * 0.5f; * pixel.b = (radius.z + 1) * 0.5f;*/ float height = (float)generator.GetValue(radiusVec * cfg.radius); height = (height + 1) * 0.5f; pixel.r = pixel.g = pixel.b = height; pixels[x + y * size] = pixel; } } heightMap.SetPixels(pixels, face); heightMap.Apply(); } Random.state = savedState; return(heightMap); }