Texture2D AltGenTex(Vector3[] verts, ModuleBase module) { Texture2D tex = new Texture2D((int) Mathf.Sqrt(verts.Length), (int) Mathf.Sqrt(verts.Length)); int reso = (int) Mathf.Sqrt(verts.Length); int pixelx = 0; int pixely = 0; for (int i = 0; i < verts.Length; i++) { verts[i] = transform.TransformPoint(verts[i]); if (pixelx == reso) { pixelx = 0; pixely += 1; } float noiseval = (float) module.GetValue(verts[i]); noiseval = Mathf.Clamp(noiseval + 0.5f, 0f, 1f); Color pixelColor = new Color(noiseval, noiseval, noiseval, 0); tex.SetPixel(pixelx, pixely, pixelColor); tex.Apply(); pixelx += 1; } tex.Apply(); return tex; }
/// <summary> /// Initializes a new instance of Noise2D. /// </summary> /// <param name="width">The width of the noise map.</param> /// <param name="height">The height of the noise map.</param> /// <param name="generator">The generator module.</param> public Noise2D(int width, int height, ModuleBase generator) { this.m_generator = generator; this.m_width = width; this.m_height = height; this.m_data = new float[width, height]; }
public bool ConditionMet(int x, int y, int z, ModuleBase noise) { if (y < 4) return false; if (z%4 != 0) return false; if (x%4 != 0) return false; return noise.GetValue(x/10.0, y/10.0, z/10.0) > 0.5; }
//Allows objects to be placed with ease by useing lat, long(-180, 180) public Vector3 SurfacePoint(float latitude, float longitude, float raddif, ModuleBase noi, GameObject planetObject) { GenerateNoise(); Mathf.Clamp(latitude, -90, 90); Mathf.Clamp(longitude, -180, 180); Vector3 spoint; float lat = latitude * Mathf.PI/180; float lon = longitude * Mathf.PI/180; float rad = radius; spoint.x = (-rad * Mathf.Cos(lat) * Mathf.Cos(lon)); spoint.y = (rad * Mathf.Sin(lat)); spoint.z = (rad * Mathf.Cos(lat) * Mathf.Sin(lon)); spoint = spoint + planetObject.transform.position; //cubedpoint = (cubizePoint2(spoint.normalized) * radius) + planetObject.transform.position; //((float) noi.GetValue((truevpos[i].normalized * radius) + planetPos)) * noisemod) //truevpos = position - planetpos //((truevpos[i].normalized * radius) + planetPos) //(float) noi.GetValue((truevpos[i].normalized * radius) + planetPos)) * noisemod) Vector3 trueplanetPos = spoint - planetPosition; raddif = (float) noi.GetValue(spoint); //Debug.Log(raddif); rad = radius + (raddif * noisemod); spoint.x = (-rad * Mathf.Cos(lat) * Mathf.Cos(lon)); spoint.y = (rad * Mathf.Sin(lat)); spoint.z = (rad * Mathf.Cos(lat) * Mathf.Sin(lon)); //noi.GetValue(truevpos[i])) * noisemod) //rad = (float) noise.GetValue((cubizePoint2(spoint.normalized) * radius) - transform.position); //Debug.Log(rad); return (spoint + planetObject.transform.position); }
/// <summary> /// Initializes a new instance of Noise2D. /// </summary> /// <param name="size">The width and height of the noise map.</param> /// <param name="generator">The generator module.</param> public Noise2D(int size, ModuleBase generator) : this(size, size, generator) { }
public void Initialize (int seed, ModuleBase inputModule) { turbulenceModule = new Turbulence (power, inputModule); turbulenceModule.Frequency = frequency; turbulenceModule.Roughness = roughness; turbulenceModule.Seed = seed; }
void GenerateNoise() { mountainTerrain.OctaveCount = Octaves; mountainTerrain.Frequency = 2f; baseFlatTerrain.OctaveCount = Octaves; terrainType.OctaveCount = Octaves; Voronoi vnoise = new Voronoi(); vnoise.Frequency = 5f; Perlin pnoise = new Perlin(); pnoise.Frequency = 2f; Scale scaledvnoise = new Scale(Scalarv, Scalarv, Scalarv, vnoise); Scale scaledpnoise = new Scale(Scalarv, Scalarv, Scalarv, pnoise); baseFlatTerrain.Frequency = 2.0f; ScaleBias flatTerrain = new ScaleBias(0.125, -0.75, baseFlatTerrain); terrainType.Frequency = 0.5f; terrainType.Persistence = 0.25; Select noiseSelect = new Select(scaledpnoise, scaledvnoise, terrainType); Select terrainSelector = new Select(flatTerrain, mountainTerrain, terrainType); terrainSelector.SetBounds(0.0, 1000.0); terrainSelector.FallOff = 0.125; Turbulence finalTerrain = new Turbulence(0.25, terrainSelector); finalTerrain.Frequency = 4.0f; noise = new Scale(Scalarv, Scalarv, Scalarv, finalTerrain); //noise = new Add(new Scale(Scalarv, Scalarv, Scalarv, finalTerrain), noiseSelect); //noise = new Add(noise, scaledvnoise); }
void GenerateNoise() { mountainTerrain.OctaveCount = Octaves; mountainTerrain.Frequency = 2f; baseFlatTerrain.OctaveCount = Octaves; terrainType.OctaveCount = Octaves; baseFlatTerrain.Frequency = 2.0f; ScaleBias flatTerrain = new ScaleBias(0.125, -0.75, baseFlatTerrain); terrainType.Frequency = 0.5f; terrainType.Persistence = 0.25; Select terrainSelector = new Select(flatTerrain, mountainTerrain, terrainType); terrainSelector.SetBounds(0.0, 1000.0); terrainSelector.FallOff = 0.125; Turbulence finalTerrain = new Turbulence(0.25, terrainSelector); finalTerrain.Frequency = 2.0f; noise = new Scale(Scalarv, Scalarv, Scalarv, finalTerrain); }
/// <summary> /// Initializes a new instance of Noise2D. /// </summary> /// <param name="width">The width of the noise map.</param> /// <param name="height">The height of the noise map.</param> /// <param name="generator">The generator module.</param> public Noise2D(int width, int height, ModuleBase generator) { this.m_generator = generator; this.m_width = width; this.m_height = height; this.m_data = new float[width, height]; this.m_ucWidth = width + m_ucBorder * 2; this.m_ucHeight = height + m_ucBorder * 2; this.m_ucData = new float[width + m_ucBorder * 2, height + m_ucBorder * 2]; }
Texture2D GenerateTexture(Vector3 start, Vector3 end, int resolution, ModuleBase noise) { Texture2D texture = new Texture2D(resolution, resolution); //since this is for square planes texture is always square texture.Apply(); //Cases for planes on a cube Vector3 testpoint = start; float addamount; if (start.x == end.x) //Then get y and z { Debug.Log(xc); int pixelx = 0; int pixely = 0; addamount = Mathf.Abs(start.y - end.y)/ resolution; //Gets the amount to add to testpoint for (int i = 0; i < resolution*resolution; i++) { if (pixelx == resolution) { pixelx = 0; pixely += 1; } if (pixely == resolution) { //This shouldn't happen ever but if it does add code to end loop } if (testpoint.y == end.y) { testpoint.y = start.y; testpoint.z += addamount; } if (testpoint.z == end.z) { //Shouldn't happen either, but in case add code to stop loop } if (testpoint.y < end.y) { //Do the getting value and setting value on texture, then //addamount to tespoint.y and +=1 on pixelx float pixelval = (float) noise.GetValue(testpoint); pixelval = Mathf.Clamp(pixelval + 0.5f, 0f, 1f); Color pixelColor = new Color(pixelval, pixelval, pixelval, 0); texture.SetPixel(pixelx, pixely, pixelColor); texture.Apply(); pixelx += 1; testpoint.y += addamount; } } } if (start.y == end.y) //Then get x and z { Debug.Log(yc); int pixelx = 0; int pixely = 0; addamount = Mathf.Abs(start.x - end.x)/ resolution; //Gets the amount to add to testpoint for (int i = 0; i < resolution*resolution; i++) { if (pixelx == resolution) { pixelx = 0; pixely += 1; } if (pixely == resolution) { //This shouldn't happen ever but if it does add code to end loop } if (testpoint.x == end.x) { testpoint.x = start.x; testpoint.z += addamount; } if (testpoint.z == end.z) { //Shouldn't happen either, but in case add code to stop loop } if (testpoint.x < end.x) { //Do the getting value and setting value on texture, then //addamount to tespoint.y and +=1 on pixelx float pixelval = (float) noise.GetValue(testpoint); pixelval = Mathf.Clamp(pixelval + 0.5f, 0f, 1f); Color pixelColor = new Color(pixelval, pixelval, pixelval, 0); texture.SetPixel(pixelx, pixely, pixelColor); texture.Apply(); pixelx += 1; testpoint.x += addamount; } } } if (start.z == end.z) //Then get x and y { Debug.Log(zc); int pixelx = 0; int pixely = 0; addamount = Mathf.Abs(start.x - end.x)/ resolution; //Gets the amount to add to testpoint for (int i = 0; i < resolution*resolution; i++) { if (pixelx == resolution) { pixelx = 0; pixely += 1; } if (pixely == resolution) { //This shouldn't happen ever but if it does add code to end loop } if (testpoint.x == end.x) { testpoint.x = start.x; testpoint.y += addamount; } if (testpoint.y == end.y) { //Shouldn't happen either, but in case add code to stop loop } if (testpoint.x < end.x) { //Do the getting value and setting value on texture, then //addamount to tespoint.y and +=1 on pixelx float pixelval = (float) noise.GetValue(testpoint); pixelval = Mathf.Clamp(pixelval + 0.5f, 0f, 1f); Color pixelColor = new Color(pixelval, pixelval, pixelval, 0); texture.SetPixel(pixelx, pixely, pixelColor); texture.Apply(); pixelx += 1; testpoint.x += addamount; } } } return texture; }
void Spherify(float radius, ModuleBase noi) { Vector3[] vertices = qMesh.vertices; Vector3[] verticesN = qMesh.vertices; Vector3[] normals = qMesh.normals; Vector3[] truevpos = qMesh.vertices; for (int i = 0; i < vertices.Length; i++) { truevpos[i] = (transform.TransformPoint(vertices[i])) - planetPos; verticesN[i] = (((truevpos[i].normalized) * (radius + (((float) noi.GetValue((truevpos[i].normalized * radius) + planetPos)) * noisemod)))) - (relativePos); //Debug.Log(planetMaker.name + (truevpos[i].normalized * radius)); } transform.rotation = Quaternion.Euler(0,0,0); qMesh.vertices = verticesN; qMesh.RecalculateNormals(); qMesh.RecalculateBounds(); }
Texture2D AltGenTex(Vector3[] verts, ModuleBase module) { Texture2D tex = new Texture2D((int) Mathf.Sqrt(verts.Length), (int) Mathf.Sqrt(verts.Length)); Vector3[] interpolatedPoints = new Vector3[verts.Length]; int reso = (int) Mathf.Sqrt(verts.Length); int pixelx = 0; int pixely = 0; for (int i = 0; i < verts.Length; i++) { if (i < verts.Length - 1) { interpolatedPoints[i] = ((verts[i] + verts[i+1])/2); } verts[i] = transform.TransformPoint(verts[i]) - planetPos; if (pixelx == reso) { pixelx = 0; pixely += 1; } float noiseval = (float) module.GetValue((verts[i].normalized * rad) + planetPos); noiseval = Mathf.Clamp((noiseval + 0.5f)/2f, 0f, 1f); Color pixelColor = new Color(noiseval, noiseval, noiseval, 0); tex.SetPixel(pixelx, pixely, pixelColor); tex.Apply(); pixelx += 1; } tex.wrapMode = TextureWrapMode.Clamp; tex.Apply(); return tex; }
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; } }
// Use this for initialization void Start() { PerlinGenerator = new Perlin(); float random = UnityEngine.Random.Range(-99999f, 99999f); Debug.Log(string.Format("Accepted x:{0}, y:{1}, z:{2} and got {3}", random, random, random, PerlinGenerator.GetValue(new Vector3(random, random, random)))); int ChunkCount = Mathf.CeilToInt(Radius / Chunk.CHUNK_SIZE); for (int x = -ChunkCount; x < ChunkCount; x++) { Debug.Log(string.Format("Planet creation is on iteration x:{0}", x)); for (int y = -ChunkCount; y < ChunkCount; y++) { for (int z = -ChunkCount; z < ChunkCount; z++) { CreateChunk(x * 16, y * 16, z * 16); } } } GenerationComplete = true; }