// Defines the noise generator to be used public Generator CreateGenerator() { PinkNoise baseNoise = new PinkNoise(seed); baseNoise.Persistence = .05f; baseNoise.Frequency = .1f; Generator baseNoiseGain = baseNoise.Gain(0f); VoronoiValleys2D voronoiMod = new VoronoiValleys2D(seed); voronoiMod.Frequency = .05f; Generator voronoiModGain = voronoiMod.Gain(.5f); Generator noise = voronoiModGain * baseNoiseGain; //noise.Binarize(threshold); noise = noise.ScaleShift(1f, .5f); noise = noise.ScaleShift(5, 0); return noise; }
private bool m_CameraChangingHeight; // is camera height changing? void Start() { if (!Terrain1 || !Terrain2) { Debug.LogError("Terrains not set!!"); enabled = false; } // desert dune-like ridges are created using RidgeNoise. it is scaled down a bit, and Gain applied to make ridges more pronounced var desert = new Gain( new RidgeNoise(23478568) { OctaveCount = 8 } * 0.6f, 0.4f); // hills use a simple pink noise. var hills = new PinkNoise(3465478) { OctaveCount = 5, // smooth hills (no higher frequencies) Persistence = 0.56f // but steep (changes rapidly in the frequencies we do have) }; // weight decides, whether a given point is hills or desert // cached, as we'd need it to decide texture at every point m_Weight = new Cache(new PinkNoise(346546) { Frequency = 0.5f, OctaveCount = 3 }.ScaleShift(0.5f, 0.5f)); // overall heightmap blends hills and deserts m_Generator = desert.Blend(hills, m_Weight).ScaleShift(0.5f, 0.5f); // as changes to terrains made in playmode get saved in the editor, we need to re-generate terrains // at start. The coroutine will set m_Move in the end, so that camera does not fly intil it's ready #if UNITY_EDITOR StartCoroutine(CreateMapsAtStart()); #else m_NoiseCoord=1; m_Move=true; #endif }
public PinkNoiseOption(int seed) { generator = new PinkNoise(seed); }
// Generates some nice-looking Perlin noise. public float[,] GenerateRawNoise(int width, int height) { float[,] samples = new float[width, height]; //Generator generator = new ValueNoise(Random.Range(1, 65536), SCurve.Cubic); Generator generator = new PinkNoise(Seed); for(int y = 0; y < height; y++) { for(int x = 0; x < width; x++) { float xCoord = (float)x / width; float yCoord = (float)y / height; float sample = generator.GetValue(xCoord, yCoord, 0); // PinkNoise usually returns value in [-1,1] but this is not guaranteed. sample = Mathf.Clamp(sample, -1, 1); // Convert value from [-1,1] to [0,1]. sample = MathUtils.ConvertRange(-1, 1, 0, 1, sample); samples[x, y] = sample; } } return samples; }