/// <summary> /// Generates a map of constructed from connected biome nodes. Instead of /// returning a biome map of size [resolution, resolution], it returns one /// of size [resolution + kernel size, resolution + kernel size] where /// kernel size is defined in <code>BlurUtils.GetGaussianKernelSize()</code> /// </summary> /// <param name="config"></param> /// <param name="position"></param> /// <param name="resolution"></param> /// <param name="deviation"></param> /// <returns></returns> public int[,] GetGaussianBlurrableBiomeMap(TerraConfig config, GridPosition position, int resolution, int deviation) { int[,] biomeMap = GetBiomeMap(config, position, resolution); int kernelSize = BlurUtils.GetGaussianKernelSize(deviation); int newRes = resolution + kernelSize; int[,] blurrableBiomeMap = new int[newRes, newRes]; // Fill in area surrounding the center biome map }
private void SetBlurredBiomePreviewTexture() { Tile tile = (Tile)target; int res = tile.MeshManager.HeightmapResolution; BiomeNode[] biomes = TerraConfig.Instance.Graph.GetEndNode().GetBiomes(); BiomeSampler sampler = new BiomeSampler(biomes); Texture2D tex; if (biomes.Length == 1) { tex = new Texture2D(res, res); MathUtil.LoopXY(res, (x, y) => { // Set colors based on how much biome is showing tex.SetPixel(x, y, biomes[0].PreviewColor); }); tex.Apply(); _previewTexture = tex; return; } int[,] map = sampler.GetBiomeMap(TerraConfig.Instance, tile.GridPosition, res); float[,] blurredMap = BlurUtils.GaussianConvolution(map, _tile.PreviewDeviation); _tile.PreviewGradient = new Gradient(); GradientColorKey[] colorKeys = new GradientColorKey[biomes.Length]; float stepSize = 1f / (biomes.Length - 1); float offset = 0f; for (int i = 0; i < biomes.Length; i++) { GradientColorKey colorKey = new GradientColorKey { color = biomes[i].PreviewColor, time = offset }; colorKeys[i] = colorKey; offset += stepSize; } _tile.PreviewGradient.colorKeys = colorKeys; //Set texture tex = new Texture2D(res, res); MathUtil.LoopXY(res, (x, y) => { // Set colors based on how much biome is showing float normalized = blurredMap[x, y] / biomes.Length; tex.SetPixel(x, y, _tile.PreviewGradient.Evaluate(normalized)); }); tex.Apply(); _previewTexture = tex; }
private void ExportBlurredBiomeMap() { Tile tile = (Tile)target; int res = tile.MeshManager.HeightmapResolution; int[,] map = GetBiomeMap(); // float[,] blurred = BlurUtils.BoxBlur(map, 20); float[,] blurred = BlurUtils.GaussianConvolution(map, 4); string tileName = tile.name.Replace(" ", "_"); WriteMap(blurred, res, $"{tileName}_blurred_biome_map.txt"); }
public void SetBlur() { Camera[] cameras = new Camera[] { Camera.main }; BlurUtils.BlurCameras(cameras); Texture2D texture2D = ScreenshotUtils.Screenshot(cameras, TextureFormat.RGB24); mask.color = Color.white; mask.texture = texture2D; BlurUtils.UnBlurCameras(cameras); }