void Update() { for (int i = 0; i < originalVertices.Count; ++i) { //Vector3 dir = normals[i]; float r1 = (float)NoiseS3D.Noise(originalVertices[i].x * scale + 1001.12441, originalVertices[i].y * scale, originalVertices[i].z * scale, Time.time * speed); float r2 = (float)NoiseS3D.Noise(originalVertices[i].x * scale + 124.1278, originalVertices[i].y * scale, originalVertices[i].z * scale, Time.time * speed); float r3 = (float)NoiseS3D.Noise(originalVertices[i].x * scale + 5201.75141, originalVertices[i].y * scale, originalVertices[i].z * scale, Time.time * speed); Vector3 dir = new Vector3(r1, r2, r3).normalized; modifiedVertices[i] = originalVertices[i] + dir * amplitude * (float)NoiseS3D.Noise(originalVertices[i].x * scale, originalVertices[i].y * scale, originalVertices[i].z * scale, Time.time * speed); } UploadVertices(); }
void MakeTexture() { if (useSeed) { NoiseS3D.seed = seed; } if (noiseTex) { Destroy(noiseTex); } noiseTex = new Texture2D(Screen.width, Screen.height); noiseTex.filterMode = FilterMode.Point; for (int x = 0; x < noiseTex.width; x++) { for (int y = 0; y < noiseTex.height; y++) { float noiseValue = 0; if (UseOctaves) { NoiseS3D.octaves = octaves; noiseValue = (float)NoiseS3D.NoiseCombinedOctaves(x * noiseScale, y * noiseScale); } else { noiseValue = (float)NoiseS3D.Noise(x * noiseScale, y * noiseScale); } //remap the value to 0 - 1 for color purposes noiseValue = (noiseValue + 1) * 0.5f; if (colorize) { noiseTex.SetPixel(x, y, Color.HSVToRGB(1f - noiseValue, 1, 1)); } else { noiseTex.SetPixel(x, y, new Color(noiseValue, noiseValue, noiseValue)); } } } noiseTex.Apply(); noiseImage.texture = noiseTex; }
void Update() { id = EventsManager.I.getEventID(); px = transform.localPosition.x; py = transform.localPosition.y; x = NoiseS3D.Noise(Time.time); if (id < 20) { transform.localPosition = new Vector3(px, py, 1f + (float)x); } else { transform.localPosition = new Vector3(px, py, 1f + (float)x / 10f); } }
IEnumerator ApplyPerlinNoise() { if (genType == GenerationType.Mesh) { for (int i = 0; i < vertices.Length; i++) { float noise = (float)NoiseS3D.Noise((vertices[i].x + perlinOffset) * perlinScale, (vertices[i].z + perlinOffset) * perlinScale) * perlinMagnitude; vertices[i].y += noise; mesh.vertices = vertices; if (useVisualisation) { visCounter++; if (visCounter > visCounterTarget) { visCounter = 0; yield return(null); } } } StartCoroutine(GenerateNodes()); } else if (genType == GenerationType.HexTile) { for (int i = 0; i < hexGrid.Length; i++) { float noise = (float)NoiseS3D.Noise((hexGrid[i].transform.position.x + perlinOffset) * perlinScale, (hexGrid[i].transform.position.z + perlinOffset) * perlinScale) * perlinMagnitude; hexGrid[i].transform.Translate(Vector3.up * noise); if (useVisualisation) { visCounter++; if (visCounter > visCounterTarget) { visCounter = 0; yield return(null); } } } StartCoroutine(ColorMeHexes()); } yield break; }
private float RipleNoise(Vector3 point, Vector3 origin, Vector3 offset) { Vector3 position = point + origin + offset; float noise = 0; float localScale = noiseSettings.roughness; float localMagnitude = 1; for (int i = 0; i < noiseSettings.noiseLevels; i++) { float detail = 1 - Mathf.Abs((float)(NoiseS3D.Noise(position.x * localScale, position.y * localScale, position.z * localScale))); detail *= detail; detail = (detail) * localMagnitude; noise += detail; localScale *= noiseSettings.frequency; localMagnitude *= noiseSettings.dampValue; } noise = Mathf.Max(0, noise - noiseSettings.minValue); return(noise * noiseSettings.magnitude); }
//this was used to compare the values from the normal noise function and the gpu version and make sure they match up void tmpArrayTestTexture() { NoiseS3D.octaves = 1; NoiseS3D.seed = 10; Vector2[] noiseData = new Vector2[100]; for (int t = 0; t < 100; t++) { noiseData[t] = new Vector2(t, Random.Range(0, 100000)); } float[] outputNormal = new float[100]; for (int t = 0; t < 100; t++) { outputNormal[t] = (((float)NoiseS3D.Noise(noiseData[t].x * 0.01, noiseData[t].y * 0.01)) + 1) * 0.5f; } float[] outputNoise = NoiseS3D.NoiseArrayGPU(noiseData); for (int t = 0; t < 100; t++) { Debug.Log("norm" + t + " = " + outputNormal[t] + " : array" + t + " = " + outputNoise[t]); } }
/// <summary> /// return value x = {0, 1} /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> /// <returns></returns> double GetNoise(double x, double y, double z) { var k = (noiseCore.Noise(x, y, z) + 1) * 0.5; // {0-1} return(k); }
// Use this for initialization void Start() { //tmpArrayTestTexture(); //return; int testCount = (int)(testRes.x * testRes.y); sw.Start(); for (int i = 0; i < iterations; i++) { for (int t = 0; t < testCount; t++) { float noiseValue = Mathf.PerlinNoise(i, t); } } sw.Stop(); Debug.Log("Unity 2D perlin noise: " + sw.ElapsedMilliseconds / iterations + " Avg milliseconds to perform " + testCount + " noise calls."); outputText.text += "Unity 2D perlin noise: " + sw.ElapsedMilliseconds / iterations + " Avg milliseconds to perform " + testCount + " noise calls.\n"; sw.Reset(); sw.Start(); for (int i = 0; i < iterations; i++) { for (int t = 0; t < testCount; t++) { double noiseValue = NoiseS3D.Noise(i, t); } } sw.Stop(); Debug.Log("NoiseS3D 2D noise : " + sw.ElapsedMilliseconds / iterations + " Avg milliseconds to perform " + testCount + " noise calls."); outputText.text += "NoiseS3D 2D noise: " + sw.ElapsedMilliseconds / iterations + " Avg milliseconds to perform " + testCount + " noise calls.\n"; sw.Reset(); NoiseS3D.octaves = 1; sw.Start(); for (int i = 0; i < iterations; i++) { RenderTexture noiseTex = NoiseS3D.GetNoiseRenderTexture((int)testRes.x, (int)testRes.y); } sw.Stop(); Debug.Log("NoiseS3D 2D noise RenderTexture on GPU: " + sw.ElapsedMilliseconds / iterations + " Avg milliseconds to perform " + testCount + " noise calls."); outputText.text += "NoiseS3D 2D noise RenderTexture on GPU: " + sw.ElapsedMilliseconds / iterations + " Avg milliseconds to perform " + testCount + " noise calls.\n"; sw.Reset(); NoiseS3D.octaves = 1; sw.Start(); for (int i = 0; i < iterations; i++) { Texture2D noiseTex = NoiseS3D.GetNoiseTexture((int)testRes.x, (int)testRes.y); } sw.Stop(); Debug.Log("NoiseS3D 2D noise Texture2D on GPU: " + sw.ElapsedMilliseconds / iterations + " Avg milliseconds to perform " + testCount + " noise calls."); outputText.text += "NoiseS3D 2D noise Texture2D on GPU: " + sw.ElapsedMilliseconds / iterations + " Avg milliseconds to perform " + testCount + " noise calls.\n"; sw.Reset(); sw.Stop(); //create this data outside of the timer, otherwise its not fair comparision bc the other tests did not need to create data Vector2[] noiseData = new Vector2[testCount]; for (int t = 0; t < testCount; t++) { noiseData[t] = new Vector2(t, Random.Range(0, 100000)); } sw.Reset(); NoiseS3D.octaves = 1; sw.Start(); for (int i = 0; i < iterations; i++) { float[] outputNoise = NoiseS3D.NoiseArrayGPU(noiseData); } sw.Stop(); Debug.Log("NoiseS3D 2D noise array on GPU not including array creation: " + sw.ElapsedMilliseconds / iterations + " Avg milliseconds to perform " + testCount + " noise calls."); outputText.text += "NoiseS3D 2D noise array on GPU not including array creation: " + sw.ElapsedMilliseconds / iterations + " Avg milliseconds to perform " + testCount + " noise calls.\n"; sw.Reset(); NoiseS3D.octaves = 1; sw.Start(); for (int i = 0; i < iterations; i++) { Vector2[] noiseOutput = new Vector2[testCount]; for (int t = 0; t < testCount; t++) { noiseOutput[t] = new Vector2(i, t); } float[] outputNoise = NoiseS3D.NoiseArrayGPU(noiseOutput); } sw.Stop(); Debug.Log("NoiseS3D 2D noise array on GPU including array creation: " + sw.ElapsedMilliseconds / iterations + " Avg milliseconds to perform " + testCount + " noise calls."); outputText.text += "NoiseS3D 2D noise array on GPU including array creation: " + sw.ElapsedMilliseconds / iterations + " Avg milliseconds to perform " + testCount + " noise calls.\n"; sw.Reset(); }