public GetValue ( double x, double y, double z ) : double | ||
x | double | The input coordinate on the x-axis. |
y | double | The input coordinate on the y-axis. |
z | double | The input coordinate on the z-axis. |
Résultat | double |
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); }
/// <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); }
public void Generate() { // Create the module network ModuleBase moduleBase; switch(noise) { case NoiseType.Billow: moduleBase = new Billow(); break; case NoiseType.RiggedMultifractal: moduleBase = new RiggedMultifractal(); break; case NoiseType.Voronoi: moduleBase = new Voronoi(); break; case NoiseType.Mix: Perlin perlin = new Perlin(); RiggedMultifractal rigged = new RiggedMultifractal(); moduleBase = new Add(perlin, rigged); break; default: moduleBase = new Perlin(); break; } // Initialize the noise map this.m_noiseMap = new Noise2D(resolution, resolution, moduleBase); this.m_noiseMap.GeneratePlanar( offset + -1 * 1/zoom, offset + offset + 1 * 1/zoom, offset + -1 * 1/zoom, offset + 1 * 1/zoom); Debug.Log (moduleBase.GetValue (0, 0, UnityEngine.Random.value)); // Generate the textures this.m_textures[0] = this.m_noiseMap.GetTexture(LibNoise.Unity.Gradient.Grayscale); this.m_textures[0].Apply(); this.m_textures[1] = this.m_noiseMap.GetTexture(LibNoise.Unity.Gradient.Terrain); this.m_textures[1].Apply(); this.m_textures[2] = this.m_noiseMap.GetNormalMap(3.0f); this.m_textures[2].Apply(); //display on plane GetComponent<Renderer>().material.mainTexture = m_textures[0]; //write images to disk File.WriteAllBytes(Application.dataPath + "/../Gray.png", m_textures[0].EncodeToPNG() ); File.WriteAllBytes(Application.dataPath + "/../Terrain.png", m_textures[1].EncodeToPNG() ); File.WriteAllBytes(Application.dataPath + "/../Normal.png", m_textures[2].EncodeToPNG() ); Debug.Log("Wrote Textures out to "+Application.dataPath + "/../"); }
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); }
/// <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 float[,] update(int seed, int x, int y, int w, int h, float scaleX = 1.0f, float scaleY = 1.0f) { generator.Frequency = 1.0 / size; generator.OctaveCount = 1; generator.Seed = seed + localSeed; generator.Quality = LibNoise.Unity.QualityMode.Low; //PerlinNoise perlin = new PerlinNoise(generator.Seed); string key = PerlinCache.makeKey("perlin", generator.Frequency, generator.Seed, octaveCount, x, y, w, h, scaleX, scaleY, curve); float[,] temp = null; if (PerlinCache.hasKey(key)) { temp = PerlinCache.getCache(key); } else { temp = new float[w, h]; for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { float tempX = x + i; float tempY = y + j; float val = 0f; float cp = 0.5f; for (int o = 0; o < octaveCount; o++) { float signal = (float)generator.GetValue(tempX * scaleX, tempY * scaleY, 0); //float signal = (float)perlin.Noise(tempX * scaleX * generator.Frequency, tempY * scaleY * generator.Frequency, 0); //float signal = 0.2f; val += (curve.Evaluate(signal * 0.4f + 0.5f) - 0.5f) * 2f * cp; tempX *= 1.83456789f; tempY *= 1.83456789f; cp *= 0.5f; } temp[i, j] = (val * 0.5f + 0.5f); } } PerlinCache.addCache(key, temp); } float[,] values = new float[w, h]; for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { values[i, j] = temp[i, j] * scale + bias; } } return(values); }
public override double GetValue(double x, double y, double z) { ModuleBase moduleBase = new Perlin(this.Frequency, this.Lacunarity, 0.5, this.OctaveCount, this.Seed, QualityMode.Medium); x *= this.m_frequency; y *= this.m_frequency; z *= this.m_frequency; float num = (float)this.m_offset + (float)moduleBase.GetValue(x, y, z); x *= this.m_lacunarity; y *= this.m_lacunarity; z *= this.m_lacunarity; int i; for (i = 1; i < this.m_octaveCount; i++) { float num2 = (float)this.m_offset + (float)Utils.GradientCoherentNoise3D(x, y, z, (long)this.m_seed, this.m_quality); num2 *= (float)this.m_weights[i]; num2 *= num; num += num2; x *= this.m_lacunarity; y *= this.m_lacunarity; z *= this.m_lacunarity; } float num3 = (float)(this.m_octaveCount - this.m_octaveCount); if (num3 > 0f) { float num2 = (float)this.m_offset + (float)moduleBase.GetValue(x, y, z); num2 *= (float)this.m_weights[i]; num2 *= num; num2 *= num3; num += num2; } return((double)num); }
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; }
// Use this for initialization void Start() { Perlin noise = new Perlin(); Mesh mesh = GetComponent<MeshFilter>().mesh; Vector3[] vertices = mesh.vertices; var i=0; while (i < vertices.Length) { float y = (float)noise.GetValue(0, i*1.3f, 0); vertices[i] += new Vector3(0, y, 0) * 2.0f; i++; } mesh.vertices = vertices; mesh.RecalculateNormals(); mesh.RecalculateBounds(); }
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 override double GetValue(double x, double y, double z) { ModuleBase moduleBase = new Perlin(this.Frequency, this.Lacunarity, this.Persistence, this.OctaveCount, this.Seed, QualityMode.Medium); x *= this.m_frequency; y *= this.m_frequency; z *= this.m_frequency; float num = (float)this.m_offset + (float)Utils.GradientCoherentNoise3D(x, y, z, (long)this.m_seed, this.m_quality); float num2 = (float)this.m_gain * num; x *= this.m_lacunarity; y *= this.m_lacunarity; z *= this.m_lacunarity; int num3 = 1; while (num2 > 0.001f && num3 < this.m_octaveCount) { if (num2 > 1f) { num2 = 1f; } float num4 = (float)this.m_offset + (float)Utils.GradientCoherentNoise3D(x, y, z, (long)this.m_seed, this.m_quality); num4 *= (float)this.m_weights[num3]; num4 *= num; num += num4; num2 *= (float)this.m_gain * num4; x *= this.m_lacunarity; y *= this.m_lacunarity; z *= this.m_lacunarity; num3++; } float num5 = (float)(this.m_octaveCount - this.m_octaveCount); if (num5 > 0f) { float num4 = (float)moduleBase.GetValue(x, y, z); num4 *= (float)this.m_weights[num3]; num4 *= num; num4 *= num5; num += num4; } return((double)num); }
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; }
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; }
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; }