public static void ApplyBiomeTerrainModifiers(BlendedBiomeTerrain b) { if (b.terrain == null) { return; } if (b.terrain.type == SamplerType.Sampler2D) { PWUtils.ResizeSamplerIfNeeded(b.terrain, ref b.biomeTerrain); Sampler2D terrain = b.terrain as Sampler2D; Sampler2D biomeTerrain = b.biomeTerrain as Sampler2D; //Fill biomeTerrain instead of terrain to keep an original version of the terrain biomeTerrain.Foreach((x, y) => { float val = terrain[x, y]; int biomeId = b.biomeMap.GetBiomeBlendInfo(x, y).firstBiomeId; if (biomeId == -1) { return(val); } //TODO: biome blending return(b.biomeTree.GetBiome(biomeId).biomeTerrain.ComputeValue(x, y, val)); }); } //else: TODO //TODO: apply biome terrain modifiers to terrain //TODO: apply biome terrain detail (caves / oth) }
bool ValidateBlendedTerrainIntegrity() { BlendedBiomeTerrain terrain = node.inputBlendedTerrain; if (terrain.biomeData == null || terrain.biomeData.biomeMap == null) { return(false); } foreach (var biome in terrain.biomes) { if (biome == null) { return(false); } } return(true); }
static IEnumerable <Texture2D> GenerateBiomeBlendMaps(BlendedBiomeTerrain b) { List <Texture2D> texs = new List <Texture2D>(); #if UNITY_EDITOR Stopwatch sw = new Stopwatch(); sw.Start(); #endif int chunkSize = b.terrain.size; BiomeMap2D biomeMap = b.biomeMap; int textureCount = 0; foreach (var kp in b.biomeTree.GetBiomes()) { if (kp.Value.biomeSurfaces != null) { foreach (var layer in kp.Value.biomeSurfaces.biomeLayers) { textureCount += layer.slopeMaps.Count; } } } if (blackTexture == null || blackTexture.Length != chunkSize * chunkSize) { blackTexture = new Color[chunkSize * chunkSize]; } for (int i = 0; i <= textureCount / 4; i++) { Texture2D tex = new Texture2D(chunkSize, chunkSize, TextureFormat.RGBA32, true, false); tex.SetPixels(blackTexture); tex.filterMode = FilterMode.Point; tex.Apply(); texs.Add(tex); } for (int x = 0; x < chunkSize; x++) { for (int y = 0; y < chunkSize; y++) { var bInfo = biomeMap.GetBiomeBlendInfo(x, y); if (bInfo.firstBiomeId == -1 || bInfo.secondBiomeId == -1) { continue; } //TODO: biome blening int texIndex = bInfo.firstBiomeId / 4; int texChan = bInfo.firstBiomeId % 4; Color c = texs[texIndex].GetPixel(x, y); c[texChan] = bInfo.firstBiomeBlendPercent; texs[texIndex].SetPixel(x, y, c); } } foreach (var tex in texs) { tex.Apply(); } #if UNITY_EDITOR sw.Stop(); // Debug.Log(sw.ElapsedMilliseconds + "ms taken to generate blend maps"); #endif return(texs); }