public static SeamlessNoise ( float x, float y, float dx, float dy, float xyOffset ) : float | ||
x | float | |
y | float | |
dx | float | |
dy | float | |
xyOffset | float | |
return | float |
float SeamlessPerlinNoise2D(Vector2 p) { Vector2 move = (new Vector2(1, 1) + CMath.Hash21(seed)) * 100; p = (p + move) * frequence; return(SimplexNoise.SeamlessNoise(p.x, p.y, 10, 10, seed)); }
void GenerateTexture(Texture2D tex, float seed) { int w = tex.width; int h = tex.height; float noise; Color[] pixels = new Color[w * h]; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { noise = 0; for (int i = 0; i < passes; i++) { noise += (SimplexNoise.SeamlessNoise(x / (float)w, y / (float)h, scale * Mathf.Pow(2, i), scale * Mathf.Pow(2, i), seed)) * Mathf.Pow(1 / -persistence, i); } noise = Mathf.Abs(noise); float c = Mathf.Sin(noise); noise = Mathf.Tan(noise / Mathf.PI * 2); pixels[y * h + x] = new Color(c, c, c, noise); } } tex.SetPixels(pixels); }
public static Mesh RandomisedIcoSphere() { Mesh mesh = GetIcoSphereMesh(); Vector3[] verticies = mesh.vertices; int p = 0; int x = 0; int y = 0; while (p < verticies.Length) { //verticies [p] += new Vector3 (Random.Range (-0.1f, 0.1f), Random.Range (-0.1f, 0.1f), Random.Range (-0.1f, 0.1f)); verticies [p] += new Vector3(0.001f, 0.125f, 0.001f) * SimplexNoise.SeamlessNoise(verticies [p].x, verticies [p].z, 1, 1, Random.Range(0, 999)); x++; y++; p++; } mesh.vertices = verticies; mesh.RecalculateNormals(); return(mesh); }
void GenerateCloudNoise(ref Texture2D tex, int noiseWidth, int noiseHeight, int seed, int scale) { float[,] perlinNoise = PerlinNoise.GeneratePerlinNoise(seed, octaves, persistence, noiseWidth, noiseHeight); float noiseValue; for (int y = 0; y < noiseWidth; y++) { for (int x = 0; x < noiseHeight; x++) { noiseValue = perlinNoise[x, y]; noiseValue *= SimplexNoise.SeamlessNoise((float)x / (float)_texWidth, (float)y / (float)_texHeight, scale, scale, 0f); noiseValue = Mathf.Clamp(noiseValue, contrastLow, contrastHigh + contrastLow) - contrastLow; noiseValue = Mathf.Clamp(noiseValue, 0f, 1f); var brightOff = Random.Range(-0.01f, 0.01f); float r = Mathf.Clamp(CloudColor.r + brightOff, 0f, 1f); float g = Mathf.Clamp(CloudColor.g + brightOff, 0f, 1f); float b = Mathf.Clamp(CloudColor.b + brightOff, 0f, 1f); tex.SetPixel(x, y, new Color(r, g, b, noiseValue)); tex.SetPixel(511 - x, y, new Color(r, g, b, noiseValue)); tex.SetPixel(x, 511 - y, new Color(r, g, b, noiseValue)); tex.SetPixel(511 - x, 511 - y, new Color(r, g, b, noiseValue)); } } tex.Apply(); }
public Color[] createTextureClouds(int width) { Color[] colors = new Color[width * width]; Color[] simplex_colors = new Color[width * width]; for (int h = 0; h < width; h++) { for (int w = 0; w < width; w++) { Color temp_color = Color.clear; float simplex_scale = Random.Range(1, 4) * 2f; float simplex_seed = Random.Range(0f, 1f); float simplex_random = SimplexNoise.SeamlessNoise(w / (width * 1f), h / (width * 1f), simplex_scale, simplex_scale, simplex_seed); if (simplex_random > 0.5f) { temp_color = Color.white; } simplex_colors[w + (h * width)] = temp_color; } } simplex_colors = cellularAutomata2(cellularAutomata(simplex_colors, Color.clear), Color.clear); return(simplex_colors); }
public Color[] createTextureAtmosphere(int width) { Color[] colors = new Color[width * width]; Color[] simplex_colors = new Color[width * width]; for (int h = 0; h < width; h++) { for (int w = 0; w < width; w++) { Color temp_color = Color.clear; float simplex_scale = Random.Range(1, 3) * 5f; float simplex_seed = Random.Range(0f, 1f); float simplex_random = SimplexNoise.SeamlessNoise(w / (width * 1f), h / (width * 1f), simplex_scale, simplex_scale, simplex_seed); //temp_color = Color.Lerp(Color.black, Color.white, perlin_random); if (simplex_random > 0.3f) { temp_color = Color.white; } simplex_colors[w + (h * width)] = temp_color; } } simplex_colors = cellularAutomata(cellularAutomata(cellularAutomata(simplex_colors, Color.clear), Color.clear), Color.clear); return(simplex_colors); }
public static Texture2D CalculateSeamlessNoise(int width, int height, float scale, float xOrg, float yOrg, int seed, Gradient colouring) { Texture2D noiseTex = new Texture2D(width, height); Color[] pix = new Color[noiseTex.width * noiseTex.height]; float y = 0.0F; while (y < noiseTex.height) { float x = 0.0F; while (x < noiseTex.width) { float xCoord = xOrg + x / noiseTex.width; float yCoord = yOrg + y / noiseTex.height; float noise = SimplexNoise.SeamlessNoise(xCoord, yCoord, scale, scale, (float)seed); noise = (noise + 1.0f) * .5f; pix [(int)(y * noiseTex.width + x)] = colouring.Evaluate(noise); x++; } y++; } noiseTex.SetPixels(pix); noiseTex.Apply(); return(noiseTex); }
public float Evaluate(Vector3 point, NoiseSettings noiseSettings) { float noiseValue = 0; float frequency = noiseSettings.baseRoughness; float amplitude = 1; for (int i = 0; i < noiseSettings.octaves; i++) { float v = SimplexNoise.SeamlessNoise(point.x, point.y, frequency * noiseSettings.dx, frequency * noiseSettings.dy, noiseSettings.seed); noiseValue += (v + 1) * 0.5f * amplitude; frequency *= noiseSettings.roughness; amplitude *= noiseSettings.persistance; } return(noiseValue); }
private Color32[] GenerateColors() { var colors = new Color32[resolution.x * resolution.y]; float invWidth = 1f / resolution.x; float invHeight = 1f / resolution.y; for (int x = 0; x < resolution.x; x++) { for (int y = 0; y < resolution.y; y++) { float u = x * invWidth; float v = y * invHeight; int index = x + y * resolution.x; float t = SimplexNoise.SeamlessNoise(u, v, scale.x, scale.y, offset.x, offset.y); colors[index] = Color.Lerp(colorA, colorB, t); } } return(colors); }
// Update is called once per frame public IEnumerator _GenerationNoiseTexture(int textureWidth, Material mat) { Texture2D procedureTexture = new Texture2D(textureWidth, textureWidth); float f = 0f; Color pixel = Color.white; int seed = System.DateTime.Now.Millisecond; for (int w = 0; w < textureWidth; w++) { for (int h = 0; h < textureWidth; h++) { float noise = SimplexNoise.SeamlessNoise((float)w / textureWidth, (float)h / textureWidth, 10.0f, 10.0f, (float)seed); pixel = new Color(noise, noise, noise, 1.0f); // procedureTexture.SetPixel(w,h,pixel); procedureTexture.SetPixel(w, h, pixel); } } procedureTexture.Apply(); yield return(new WaitForSeconds(5f)); // Texture2DToPNG(procedureTexture, textureWidth, Application.dataPath + "/NoiseTexture", "Noise1.png"); }
void CreateTexture(Texture2D tex) { Color[] cols = tex.GetPixels(); for (int x = 0; x < tex.width; x++) { for (int y = 0; y < tex.height; y++) { float u = x * 1f / tex.width; float v = y * 1f / tex.height; int index = x + y * tex.width; switch (patternType) { case PatternType.Noise: // TODO Make tileable perlin noise. Maybe sample along two perpendicular circles in 4D float lightness = SimplexNoise.SeamlessNoise(u, v, HorizontalMultiplier, VerticalMultiplier, HorizontalOffset, VerticalOffset); // black / white: //cols [index] = lightness * Color.white; // linear interpolation between two given colors: cols[index] = lightness * color1 + (1 - lightness) * color2; break; case PatternType.Gradient: // from black to white: //cols [index] = u * Color.white; // linear interpolation between two given colors: //cols [index] = u * color1 + (1-u) * color2; // using the ColorGradient method below: cols [index] = ColorGradient(360f * u); break; case PatternType.CheckerBoard: // TODO: Create a two colored checkerboard here cols [index] = color1 * (Mathf.Floor(u * HorizontalMultiplier) / HorizontalMultiplier) + color2 * (Mathf.Floor(v * VerticalMultiplier) / VerticalMultiplier); break; case PatternType.Circle: // TODO: create an actual circle here cols [index] = color1 * (1 - 2 * Mathf.Abs(u - 0.5f) - 2 * Mathf.Abs(v - 0.5f)); break; case PatternType.Mandelbrot: cols [index] = Mandelbrot( (u - 0.5f) * HorizontalMultiplier + HorizontalOffset, (v - 0.5f) * VerticalMultiplier + VerticalOffset ); break; case PatternType.Custom: // TODO: experiment with different patterns here // A real chessboard: cols [index] = (Mathf.Floor(u * HorizontalMultiplier) + Mathf.Floor(v * VerticalMultiplier)) % 2 == 1 ? color1 : color2; break; } } } tex.SetPixels(cols); tex.Apply(); }
private void _GenerateNoiseOctaves() { Color[] pixelsForOctaves = new Color[width * height * 4]; Vector3 sunDir = sunDirection.normalized; Vector2[] displacements = new Vector2[3]; displacements[0] = new Vector2(Mathf.Floor(sunDir.x * 10.0f), Mathf.Floor(sunDir.z * 10.0f)); displacements[1] = displacements[0] * 2.0f; displacements[2] = displacements[0] * 3.0f; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { float scale = 2.0f; float noise = 0.0f; float[] noiseDisplaced = new float[3]; for (int o = 0; o < 4; o++) { // The real noise noise = SimplexNoise.SeamlessNoise((float)j / width, (float)i / height, scale, scale, 20.0f); noise = noise * 0.5f + 0.5f; for (int s = 0; s < 3; s++) { float yDisplaced = ((float)i + displacements[s].y) / height; float xDisplaced = ((float)j + displacements[s].x) / width; while (xDisplaced > 1.0f) { xDisplaced = xDisplaced - 1.0f; } while (yDisplaced > 1.0f) { yDisplaced = yDisplaced - 1.0f; } while (xDisplaced < 0.0f) { xDisplaced = xDisplaced + 1.0f; } while (yDisplaced < 0.0f) { yDisplaced = yDisplaced + 1.0f; } noiseDisplaced[s] = SimplexNoise.SeamlessNoise(xDisplaced, yDisplaced, scale, scale, 20.0f); noiseDisplaced[s] = noiseDisplaced[s] * 0.5f + 0.5f; } pixelsForOctaves[width * height * o + i * width + j] = new Color(noise, noiseDisplaced[0], noiseDisplaced[1], noiseDisplaced[2]); scale *= 2.0f; } } } List <Color> pixels = new List <Color>(pixelsForOctaves); for (int o = 0; o < 4; o++) { Texture2D octave = new Texture2D(width, height, TextureFormat.ARGB32, false, true); octave.filterMode = FilterMode.Bilinear; octave.wrapMode = TextureWrapMode.Repeat; octave.SetPixels(pixels.GetRange(width * height * o, width * height).ToArray()); octave.Apply(); byte[] bytes = octave.EncodeToPNG(); System.IO.File.WriteAllBytes(Application.dataPath + "/2DDynamicClouds/Textures/Octave" + o.ToString() + ".png", bytes); } }