/// <summary> /// Initializes a new instance of Turbulence. /// </summary> public Turbulence() : base(1) { this.m_xDistort = new Perlin(); this.m_yDistort = new Perlin(); this.m_zDistort = new Perlin(); }
public void GenerateHeightMap() { var perlin = new LibNoise.Unity.Generator.Perlin(Frequency, Lacunarity, Persistence, Octaves, Seed, LibNoise.Unity.QualityMode.High); //var ridged = new LibNoise.Unity.Generator.RidgedMultifractal(Frequency, Lacunarity, Octaves, Seed, LibNoise.Unity.QualityMode.Medium); //var turb = new LibNoise.Unity.Operator.Turbulence(0.25, perlin); //var layered = new LibNoise.Unity.Operator.Multiply(perlin, ridged); //var var scaled = new LibNoise.Unity.Operator.ScaleBias(Scaling, ScaleBias, perlin); var final = new LibNoise.Unity.Operator.Terrace(false, scaled); //for (float i = 0; i < 50; i += 10) final.Add(0f); final.Add(10f); final.Add(100f); var noise = new LibNoise.Unity.Noise2D(TotalSize, final); noise.GeneratePlanar(ClipX, ClipX + (ClipSize * ChunksPerSide), ClipY, ClipY + (ClipSize * ChunksPerSide)); GameObject.Destroy(HeightMap); HeightMap = noise.GetTexture(LibNoise.Unity.Gradient.Grayscale); HeightMap.Apply(); GameObject.Destroy(NormalMap); NormalMap = noise.GetNormalMap(1f); NormalMap.Apply(); floatMap = new float[TotalSize * TotalSize]; for (int y = 0; y < TotalSize; y++) for (int x = 0; x < TotalSize; x++) floatMap[y * TotalSize + x] = noise[x, y]; }
/// <summary> /// Initializes a new instance of Turbulence. /// </summary> /// <param name="input">The input module.</param> public Turbulence(ModuleBase input) : base(1) { this.m_xDistort = new Perlin(); this.m_yDistort = new Perlin(); this.m_zDistort = new Perlin(); this.m_modules[0] = input; }
/// <summary> /// Initializes a new instance of Turbulence. /// </summary> /// <param name="x">The perlin noise to apply on the x-axis.</param> /// <param name="y">The perlin noise to apply on the y-axis.</param> /// <param name="z">The perlin noise to apply on the z-axis.</param> /// <param name="power">The power of the turbulence.</param> /// <param name="input">The input module.</param> public Turbulence(Perlin x, Perlin y, Perlin z, double power, ModuleBase input) : base(1) { this.m_xDistort = x; this.m_yDistort = y; this.m_zDistort = z; this.m_modules[0] = input; this.Power = power; }
public static float[][] GenerateVertexHeightMap(Vector3[][] vertices, int seed, float scale, int octaves, float persistance, float lacunarity, Vector3 offset) { LibNoise.Unity.Generator.Perlin perlin = new LibNoise.Unity.Generator.Perlin(1f, lacunarity, persistance, octaves, seed, QualityMode.Medium); float[][] heightMap = new float[vertices.Length][]; if (scale <= 0) { scale = 0.0001f; } float maxNoiseHeight = float.MinValue; float minNoiseHeight = float.MaxValue; for (int f = 0; f < heightMap.Length; f++) { heightMap[f] = new float[vertices[f].Length]; for (int v = 0; v < heightMap[f].Length; v++) { float amplitude = 1f; float frequency = 1f; float noiseHeight = 0f; for (int i = 0; i < octaves; i++) { float sampleX = vertices[f][v].x / scale + offset.x; float sampleY = vertices[f][v].y / scale + offset.y; float sampleZ = vertices[f][v].z / scale + offset.z; float perlinValue = (float)perlin.GetValue(sampleX, sampleY, sampleZ); noiseHeight += perlinValue * amplitude; amplitude *= persistance; } if (noiseHeight > maxNoiseHeight) { maxNoiseHeight = noiseHeight; } else if (noiseHeight < minNoiseHeight) { minNoiseHeight = noiseHeight; } heightMap[f][v] = noiseHeight; } } for (int f = 0; f < vertices.Length; f++) { for (int v = 0; v < heightMap[f].Length; v++) { heightMap[f][v] = Mathf.InverseLerp(minNoiseHeight, maxNoiseHeight, heightMap[f][v]); } } return(heightMap); }
public void Prepare() { LibNoise.Unity.Generator.Perlin perlin = new LibNoise.Unity.Generator.Perlin(1f, 1f, 1f, 4, parentBody.parentBody.biome.terrainGenData.seed, QualityMode.Medium); actualRadius = Mathf.Lerp(parentBody.parentBody.biome.terrainGenData.lowRadius, parentBody.parentBody.biome.terrainGenData.highRadius, (float)perlin.GetValue(transform.position.x, transform.position.y, transform.position.z)); gameObject.AddComponent <MeshFilter>(); GetComponent <MeshFilter>().mesh = mesh = new Mesh(); mesh.name = "Procedural Sphere Side " + face; Rigidbody body = GetComponent <Rigidbody>(); body.isKinematic = true; body.useGravity = false; biome = parentBody.parentBody.biome; }
private GameObject setFace(float unit) { LibNoise.Unity.Generator.Perlin pl = new LibNoise.Unity.Generator.Perlin(); pl.Lacunarity = 1; pl.OctaveCount = 2; pl.Persistence = 1.96f; pl.Seed = 1; pl.Quality = LibNoise.Unity.QualityMode.High; pl.Frequency = 1 / 80.0f; GameObject obj = new GameObject(); for (uint j = 0; j < size; j++) { for (uint i = 0; i < size; i++) { GameObject tmp = (GameObject)Instantiate(plan, new Vector3(unit * (1 + i) - (unit / 2) * size - (unit / 2), unit * (1 + j) - (unit / 2) * size - (unit / 2), (-unit / 2) * size), Quaternion.identity); tmp.transform.parent = obj.transform; tmp.GetComponent<InfosCase>().Percent = (int)(((pl.GetValue(tmp.transform.position) + 1.7f) / 3.0f ) * 100); cubes.Add(tmp); if (terrainProps.Length > 0) { GameObject go = (GameObject) Instantiate(terrainProps[0], tmp.transform.position, Quaternion.Euler(tmp.transform.right)); go.transform.parent = tmp.transform; if (tmp.GetComponent<InfosCase>().Percent >= 50) { go.GetComponentInChildren<MeshRenderer>().enabled = false; // go.GetComponentInChildren<MeshRenderer>().material = prefabProps[0].material; // go.GetComponentInChildren<MeshFilter>().mesh = prefabProps[0].mesh; } else { go.GetComponentInChildren<MeshRenderer>().enabled = true; } } // if (terrainProps.Length > 0) // { // int yolo = (terrainProps.Length - 1) * Mathf.RoundToInt(tmp.GetComponent<InfosCase>().Percent / 100f); // GameObject go = (GameObject) Instantiate(terrainProps[yolo], tmp.transform.position, Quaternion.Euler(tmp.transform.right)); // go.transform.parent = tmp.transform; // } } } return obj; }
private float[,] GetHardness(int width, int height) { LibNoise.Unity.Generator.Perlin generator = new LibNoise.Unity.Generator.Perlin(); generator.Frequency = 1.0 / 6; generator.OctaveCount = 4; generator.Seed = 123498765; generator.Quality = LibNoise.Unity.QualityMode.Low; float[,] values = new float[width, height]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { values[i, j] = (float)generator.GetValue(i, j, 0) * 0.4f + 0.5f; } } return(values); }
public void Generate() { Biome biome = parentBody.biome; bool shouldGenerateTerrain = !(biome.terrainGenData.lacunarity == 0f || biome.terrainGenData.persistance == 0f || biome.terrainGenData.meshHeightMultiplier == 0f || biome.terrainGenData.octaves == 0); for (int i = 0; i < faces.Length; i++) { faceComponents[i].GenerateSphere(); if (shouldGenerateTerrain) { faceVertices[i] = new Vector3[faceComponents[i].vertices.Length]; for (int v = 0; v < faceVertices[i].Length; v++) { faceVertices[i][v] = faceComponents[i].vertices[v][0]; } } } heightMap = null; if (shouldGenerateTerrain) { TerrainGenData terrainData = biome.terrainGenData; LibNoise.Unity.Generator.Perlin perlin = new LibNoise.Unity.Generator.Perlin(1f, 1f, 1f, 4, terrainData.seed, QualityMode.Medium); float actualRadius = Mathf.Lerp(terrainData.lowRadius, terrainData.highRadius, (float)perlin.GetValue(transform.position.x, transform.position.y, transform.position.z)); heightMap = PerlinNoise3D.GenerateVertexHeightMap(faceVertices, terrainData.seed, terrainData.noiseScale * Mathf.Pow(Mathf.Abs((actualRadius - terrainData.lowRadius) / ((terrainData.highRadius - terrainData.lowRadius))), 0.5f), terrainData.octaves, terrainData.persistance, terrainData.lacunarity, terrainData.offset); } for (int i = 0; i < faceComponents.Length; i++) { if (shouldGenerateTerrain) { faceComponents[i].GenerateTerrain(); } faceComponents[i].GenerateTrianglesAndColors(); } }
/// <summary> /// Returns the output value for the given input coordinates. /// </summary> /// <param name="x">The input coordinate on the x-axis.</param> /// <param name="y">The input coordinate on the y-axis.</param> /// <param name="z">The input coordinate on the z-axis.</param> /// <returns>The resulting output value.</returns> public override double GetValue(double x, double y, double z) { float signal; float value; int curOctave; ModuleBase tmpperl = new Perlin(Frequency,Lacunarity,0.5,OctaveCount,Seed,QualityMode.Medium); x *= this.m_frequency; y *= this.m_frequency; z *= this.m_frequency; // Initialize value : first unscaled octave of function; later octaves are scaled value = (float)m_offset + (float)tmpperl.GetValue(x, y, z); x *= this.m_lacunarity; y *= this.m_lacunarity; z *= this.m_lacunarity; // inner loop of spectral construction, where the fractal is built for(curOctave = 1; curOctave < m_octaveCount; curOctave++) { // obtain displaced noise value. signal = (float)m_offset + (float)Utils.GradientCoherentNoise3D(x, y, z, m_seed, this.m_quality);; //scale amplitude appropriately for this frequency signal *= (float)m_weights[curOctave]; // scale increment by current altitude of function signal *= value; // Add the signal to the output value. value += signal; // Go to the next octave. x *= m_lacunarity; y *= m_lacunarity; z *= m_lacunarity; }//end for //take care of remainder in _octaveCount float remainder = m_octaveCount - (int)m_octaveCount; if(remainder > 0.0f) { signal = (float)m_offset + (float)tmpperl.GetValue(x, y, z); signal *= (float)m_weights[curOctave]; signal *= value; signal *= remainder; value += signal; }//end if return value; }
/// <summary> /// Returns the output value for the given input coordinates. /// </summary> /// <param name="x">The input coordinate on the x-axis.</param> /// <param name="y">The input coordinate on the y-axis.</param> /// <param name="z">The input coordinate on the z-axis.</param> /// <returns>The resulting output value.</returns> public override double GetValue(double x, double y, double z) { float signal; float value; int curOctave; x *= Frequency; y *= Frequency; z *= Frequency; // Initialize value, fBM starts with 0 value = 0; ModuleBase tmpperl = new Perlin(Frequency,Lacunarity,0.5,OctaveCount,Seed,QualityMode.Medium); // Inner loop of spectral construction, where the fractal is built for(curOctave = 0; curOctave < OctaveCount; curOctave++) { // Get the coherent-noise value. signal = (float)tmpperl.GetValue(x, y, z) * (float)m_weights[curOctave]; // Add the signal to the output value. value += signal; // Go to the next octave. x *= Lacunarity; y *= Lacunarity; z *= Lacunarity; }//end for //take care of remainder in _octaveCount float remainder = OctaveCount - (int)OctaveCount; if(remainder > 0.0f) { value += remainder * (float)tmpperl.GetValue(x, y, z) * (float)m_weights[curOctave]; }//end if return value; }
public override double GetValue(double x, double y, double z) { x *= this.Frequency; y *= this.Frequency; z *= this.Frequency; float num = 0f; ModuleBase moduleBase = new Perlin(this.Frequency, this.Lacunarity, 0.5, this.OctaveCount, this.Seed, QualityMode.Medium); int i; for (i = 0; i < this.OctaveCount; i++) { float num2 = (float)moduleBase.GetValue(x, y, z) * (float)this.m_weights[i]; num += num2; x *= this.Lacunarity; y *= this.Lacunarity; z *= this.Lacunarity; } float num3 = (float)(this.OctaveCount - this.OctaveCount); if (num3 > 0f) { num += num3 * (float)moduleBase.GetValue(x, y, z) * (float)this.m_weights[i]; } return (double)num; }
public void PostApply(ConfigNode node) { switch (type) { case NoiseType.Perlin: var perlin = new Perlin (); perlin.Quality = QualityMode.High; perlin.Seed = seed; perlin.OctaveCount = octaves; perlin.Frequency = frequency; perlin.Lacunarity = lacunarity; perlin.Persistence = persistence; Module = perlin; break; case NoiseType.ExDistPerlin: var exDistPerlin = new ExDistPerlin (); exDistPerlin.Quality = QualityMode.High; exDistPerlin.Seed = seed; exDistPerlin.OctaveCount = octaves; exDistPerlin.Frequency = frequency; exDistPerlin.Lacunarity = lacunarity; exDistPerlin.Persistence = persistence; exDistPerlin.Mu = mu; Module = exDistPerlin; break; case NoiseType.Billow: var billow = new Billow (); billow.Quality = QualityMode.High; billow.Seed = seed; billow.OctaveCount = octaves; billow.Frequency = frequency; billow.Lacunarity = lacunarity; billow.Persistence = persistence; Module = billow; break; case NoiseType.RidgedMultiFractal: var ridgedMultiFractal = new RiggedMultifractal (); ridgedMultiFractal.Quality = QualityMode.High; ridgedMultiFractal.Seed = seed; ridgedMultiFractal.OctaveCount = octaves; ridgedMultiFractal.Frequency = frequency; ridgedMultiFractal.Lacunarity = lacunarity; Module = ridgedMultiFractal; break; case NoiseType.Voronoi: var voronoi = new Voronoi (); voronoi.Seed = seed; voronoi.UseDistance = voronoiUseDistance; voronoi.Displacement = displacement; voronoi.Frequency = frequency; Module = voronoi; break; case NoiseType.Const: var constant = new Const (); constant.Value = constantValue; Module = constant; break; } }