// --------------- CHUNK CREATION --------------- // --------------- CHUNK CREATION --------------- // --------------- NOISE DEBUGGING --------------- // --------------- NOISE DEBUGGING --------------- #region NOISE DEBUGGING private Texture2D MakeNoiseTexture(Vector2 worldPos, SpawnSettingType spawnType) { BiomeSetting biomeSettings = WorldSettings.GetSettingsByType(_biomeType); SpawnSetting noiseSettings = biomeSettings.GetSpawnSettingsByType(spawnType); Texture2D noiseTex = new Texture2D(noiseSettings.resolution, noiseSettings.resolution, TextureFormat.RGB24, true); noiseTex.wrapMode = TextureWrapMode.Clamp; noiseTex.filterMode = FilterMode.Trilinear; noiseTex.anisoLevel = 9; Color[] pix = new Color[noiseTex.width * noiseTex.height]; float[] noiseSamples = GetNoiseSamples(worldPos, spawnType); for (int x = 0; x < noiseSettings.resolution; x++) { for (int y = 0; y < noiseSettings.resolution; y++) { float sample = noiseSamples[y * noiseSettings.resolution + x]; pix[y * noiseSettings.resolution + x] = new Color(sample, sample, sample); } } noiseTex.SetPixels(pix); noiseTex.Apply(); return(FlipTexture(noiseTex)); }
private IEnumerator AddFoliage(SpawnSettingType spawnType) { BiomeSetting biomeSettings = WorldSettings.GetSettingsByType(parent._biomeType); SpawnSetting spawnSettings = biomeSettings.GetSpawnSettingsByType(spawnType); float[] noiseSamples = parent.GetNoiseSamples(parent._worldPosition, spawnType); for (int x = 0; x < spawnSettings.resolution; x++) { for (int y = 0; y < spawnSettings.resolution; y++) { float sample = noiseSamples[y * spawnSettings.resolution + x]; if (sample > 0.3f) { int randomNumber = Random.Range(0, spawnSettings.spawnDensity + 1); if (randomNumber == 1) { parent.SpawnObject(spawnType, new Vector2(x, y), spawnSettings.resolution); if ((y * spawnSettings.resolution + x) % 20 == 0) { yield return(null); } } } } } }
public float[] GetNoiseSamples(Vector2 worldPosition, SpawnSettingType spawnType) { BiomeSetting biomeSettings = WorldSettings.GetSettingsByType(_biomeType); SpawnSetting spawnSettings = biomeSettings.GetSpawnSettingsByType(spawnType); float[] noiseSamples = new float[spawnSettings.resolution * spawnSettings.resolution]; float frequency = spawnSettings.frequency; float resolution = spawnSettings.resolution; float x = 0.0F; while (x < spawnSettings.resolution) { float y = 0.0F; while (y < spawnSettings.resolution) { float xCoord = (worldPosition.x) * frequency + x / resolution * frequency; float yCoord = (worldPosition.y) * frequency + y / resolution * frequency; noiseSamples[(int)(y * spawnSettings.resolution + x)] = Mathf.PerlinNoise(xCoord, yCoord); // TODO: Significantly faster -> Look at simplex for more performance and Voronoi for other effects y++; } x++; } return(noiseSamples); }