IEnumerator GenerateTerrain() { float t = Time.time; yield return(new WaitForEndOfFrame()); SimplexNoiseGenerator sng = new SimplexNoiseGenerator(seed); BinaryImage bi = new BinaryImage(tex.width, tex.height, false); for (int x = 0; x < tex.width; x++) { float height = sng.coherentNoise(x / terrainStretch + (transform.position.x * terrainStretch), 0, 0, 1, 200, 1.75f, 2f, 0.9f); height += sng.coherentNoise(x / terrainStretch + (transform.position.x * terrainStretch), 0, 0, 2, 25, 0.05f, 2f, 0.9f); height += sng.coherentNoise(x / terrainStretch + (transform.position.x * terrainStretch), 0, 0, 1, 25, 0.1f, 2f, 0.9f); for (int y = 0; y < tex.height; y++) { if (y < height * tex.height + 500) { bi.Set(x, y, true); } else { break; } } } binaryImage = bi; binaryImage = tidyBinaryImage(binaryImage); updateCollider(); Debug.Log((Time.time - t) * 1000f); }
//Get a float point noise value given a chunk location and an x/z location within that chunk. Uses Simplex Noise from SimplexNoiseGenerator //Determines y-height of basic terrain heightmap at that x/z location float pointNoiseVal(int chunkX, int chunkZ, int x, int z) { float freq = .1f; return(noiseGenerator.coherentNoise((x + chunkX) * freq, 0, (z + chunkZ) * freq, 3) * 80); //Below is old Perlin noise method. keep for posterity. //return (Mathf.PerlinNoise((x + chunkX) * .05f, (z + chunkZ) * .05f)) * 9 + (Mathf.PerlinNoise((x + chunkX) * .1f, (z + chunkZ) * .1f)); }
public Texture3D GenerateNoise() { SimplexNoiseGenerator noise = new SimplexNoiseGenerator(); Color[] colorArray = new Color[_textureSize * _textureSize * _textureSize]; Texture3D texture = new Texture3D(_textureSize, _textureSize, _textureSize, _format, false); for (int x = 0; x < _textureSize; x++) { for (int y = 0; y < _textureSize; y++) { for (int z = 0; z < _textureSize; z++) { float value = noise.coherentNoise(x, y, z, _octaves, _multiplier, _amplitude, _lacunarity, _persistence); Color c = new Color(value, 0.0f, 0.0f, 1.0f); colorArray[x + (y * _textureSize) + (z * _textureSize * _textureSize)] = c; } } } texture.SetPixels(colorArray); texture.Apply(); return(texture); }