private float T1(float x, float y, Interp interp) { var valueNoise = new ValueNoise(); float val = valueNoise.GetNoise(x, y, interp); Console.WriteLine($"My NoiseValue : {val} for X:{x},Y:{y}"); return(val); }
private void GenerateValue() { for (int i = 0; i < vertices.Length; i++) { Vector3 v = vertices[i]; v.y = zOffset; vertices[i].y = height * ValueNoise.Sample3D(v, frequency, octaves, lacunarity, persistence); } }
public void ValueNoise3d_Hermite_test() { var valueNoise = new ValueNoise(); float val = valueNoise.GetNoise(0.0f, 0.0f, 0.0f, Interp.Hermite); Console.WriteLine($"NoiseValue: {val}"); // -0.06701785 Assert.AreEqual(-0.06701785f, val, 0.00000001f); }
public PlanetNoise(PlanetNoiseSettings settings) { if (settings.octaves < 1) { settings.octaves = 1; } this.settings = settings; noiseClass = new ValueNoise(settings.seed); }
public PlanetNoise() { settings.octaves = 1; settings.frequency = 1f; settings.lacunarity = 2f; settings.amplitude = 1f; settings.persistence = 0.5f; settings.seed = 0; noiseClass = new ValueNoise(settings.seed); }
public void changeSeed(int newseed) { seed = newseed; INoise perlin = new PerlinNoise(seed, 2f); //fractal = new FractalNoise(perlin, 3, 1.0f); fractalT = new FractalNoise(perlin, fractalOctavesT, fractalfrequencyT, fractalamplitudeT); voronoiT = new ValueNoise(seed, fractalOctavesT); perlin = new PerlinNoise(seed + HseedOffset, 2f); voronoiH = new ValueNoise(seed + HseedOffset, fractalOctavesT); //print("hi"); fractalH = new FractalNoise(perlin, fractalOctavesH, fractalfrequencyH, fractalamplitudeH); }
public GeneratorValue(int seed, float amplitude = 1, float persistence = 0.5f, float frequency = 1f, float freqMulti = 2f, int octaves = 1) { this.perlin = new ValueNoise(seed); this.Amplitude = amplitude; this.Persistence = persistence; this.Frequency = frequency; this.FreqMulti = freqMulti; this.Octaves = octaves; System.Random rand = new System.Random(seed); offsetX = (float)rand.NextDouble(); offsetY = (float)rand.NextDouble(); offsetZ = (float)rand.NextDouble(); offsetW = (float)rand.NextDouble(); }
public static float[,] ValueNoiseMapGenerator(int width, int height, int seed, float noiseScale) { float[,] noiseMap = new float[width, height]; ValueNoise noise = new ValueNoise(seed); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { float xCoord = (float)i / width; float yCoord = (float)j / height; float valor = noise.GetNoise(xCoord, yCoord, noiseScale); noiseMap[i, j] = valor; } } return(noiseMap); }
void Awake() { pixelAvgs = new float[img.width, img.height]; xSize = img.width; ySize = img.height; //pixelAvgs = new float[xSize, ySize]; Color c = img.GetPixel(0, 0); hi = (c.r + c.g + c.b) / 3f; lo = (c.r + c.g + c.b) / 3f; for (int y = 0; y < ySize; y++) { for (int x = 0; x < xSize; x++) { c = img.GetPixel(x, y); pixelAvgs[x, y] = (c.r + c.g + c.b) / 3f; if (pixelAvgs[x, y] < lo) { lo = pixelAvgs[x, y]; } if (pixelAvgs[x, y] > hi) { hi = pixelAvgs[x, y]; } avgColor += new Color(c.r / (float)(xSize * ySize), c.g / (float)(xSize * ySize), c.b / (float)(xSize * ySize)); //pixelAvgs[y, x] = Mathf.PerlinNoise(((float)x) * perlinMult + perlinOffset, ((float)y) * perlinMult + perlinOffset); } } float centColor = (avgColor.r + avgColor.g + avgColor.b) / 3f; hiColor = avgColor * hi; loColor = (avgColor * lo + avgColor * 2f) / 2f; float xft = 0; for (int y = 0; y < ySize; y++) { float xf = 0; for (int x = 1; x < xSize; x++) { xf += Mathf.Abs(pixelAvgs[x, y] - pixelAvgs[x - 1, y]) * ((xSize / 2.0f) / xSize); } xft += xf * ((ySize / 2.0f) / ySize); } print(xft); float yft = 0; for (int x = 0; x < xSize; x++) { float yf = 0; for (int y = 1; y < ySize; y++) { yf += Mathf.Abs(pixelAvgs[x, y] - pixelAvgs[x, y - 1]) * ((ySize / 2.0f) / ySize); } yft += yf * ((xSize / 2.0f) / xSize); } print(yft); float ft = (xft + yft) / (.2f * xSize * ySize); print(ft); outTexture = new Texture2D(xSize, ySize); Noise sn = new SimplexNoise(1, ft); Noise pn = new PerlinNoise(1, ft); Noise vn = new ValueNoise(1, 1); for (int y = 0; y < ySize; y++) { for (int x = 0; x < xSize; x++) { float p = (sn.Sample2D(((float)x) + perlinOffset, ((float)y) * 2f + perlinOffset) + sn.Sample2D(((float)x) * 2f + perlinOffset, ((float)y) * 4f + perlinOffset) + sn.Sample2D(((float)x) * 4f + perlinOffset, ((float)y) * 8f + perlinOffset)) / 3f; if (p > .5f) { c = Color.Lerp(avgColor, hiColor, (p - .5f) * 2f); } else { c = Color.Lerp(loColor, avgColor, p * 2f); } outTexture.SetPixel(x, y, c); } } outTexture.Apply(); imgmat.mainTexture = outTexture; }
public void GenerateMap() { System.Random random = new System.Random(); int RandomSeed = random.Next(0, 100000); System.Random local_seed = new System.Random(RandomSeed); int int_seed = local_seed.Next(-100000, 100000); float[,] NoiseMap; if (this.noiseSelector == NoiseSelector.Perlin) { NoiseMap = PerlinNoise.PerlinNoiseMapGenerator(this.mapWidth, this.mapHeigth, int_seed, this.noiseScale, octaves, persistance, lacunarity, offset); } else if (this.noiseSelector == NoiseSelector.Simplex) { NoiseMap = SimplexNoise.SimplexNoiseMapGenerator(this.mapWidth, this.mapHeigth, int_seed, octaves, offset); } else if (this.noiseSelector == NoiseSelector.Value) { NoiseMap = ValueNoise.ValueNoiseMapGenerator(this.mapWidth, this.mapHeigth, int_seed, this.noiseScale); } else if (this.noiseSelector == NoiseSelector.Voronoi) { NoiseMap = VoronoiNoise.ValueNoiseMapGenerator(this.mapWidth, this.mapHeigth, int_seed, this.noiseScale, octaves, persistance); } else if (this.noiseSelector == NoiseSelector.PerlinVoronoi) { float[,] perlinMap = PerlinNoise.PerlinNoiseMapGenerator(this.mapWidth, this.mapHeigth, int_seed, this.noiseScale, octaves, persistance, lacunarity, offset); float[,] voronoiMap = VoronoiNoise.ValueNoiseMapGenerator(this.mapWidth, this.mapHeigth, int_seed, this.noiseScale, octaves, persistance); NoiseMap = Convolution.ConvolutionMapGenerator(this.mapWidth, this.mapHeigth, perlinMap, voronoiMap); } else { //default: perlin noise NoiseMap = PerlinNoise.PerlinNoiseMapGenerator(this.mapWidth, this.mapHeigth, int_seed, this.noiseScale, octaves, persistance, lacunarity, offset); } Color[] HeighMap = new Color[mapWidth * mapHeigth]; for (int y = 0; y < mapHeigth; y++) { for (int x = 0; x < mapWidth; x++) { float currentHeigth = NoiseMap[x, y]; for (int i = 0; i < regions.Length; i++) { if (currentHeigth <= regions[i].heigth) { HeighMap[y * mapWidth + x] = regions[i].colour; break; } } } } MapDisplay display = FindObjectOfType <MapDisplay>(); if (drawMode == DrawMode.NoiseMap) { display.DrawTexture(TextureGenerator.TextureFromHeightMap(NoiseMap)); } else if (drawMode == DrawMode.HeighMap) { display.DrawTexture(TextureGenerator.TextureFromHeighMap(HeighMap, mapWidth, mapHeigth)); } }
private static float GetNoise(float x, float y, InterpolationMethod interpolationMethod) { var val = ValueNoise.GetSingleValue((int)x, (int)y, 0.5f, 1336, InterpolationMethod.Linear); return val; }