void Start() { GameObject cubeParent = new GameObject(); cubeParent.name = "Noise Cubes"; for (int x = 0; x < gridSize; x++) { for (int y = 0; y < gridSize; y++) { for (int z = 0; z < gridSize; z++) { float noiseValue = (float)NoiseS3D.NoiseCombinedOctaves(x * noiseScale, y * noiseScale, z * noiseScale); //remap the value to 0 - 1 for color purposes noiseValue = (noiseValue + 1) * 0.5f; GameObject noiseCube = GameObject.CreatePrimitive(PrimitiveType.Cube); noiseCube.GetComponent <Renderer>().sharedMaterial = Instantiate(noiseMat) as Material; Destroy(noiseCube.GetComponent <Collider>()); noiseCube.GetComponent <Renderer>().sharedMaterial.SetColor("_TintColor", new Color(noiseValue, noiseValue, noiseValue, noiseValue * 0.015f)); noiseCube.transform.SetParent(cubeParent.transform); noiseCube.transform.position = new Vector3(x, y, z); } } } cubeParent.transform.position -= new Vector3(gridSize / 2, 0, gridSize / 2); }
float[,] GenerateHeights() { Texture2D noiseTex = new Texture2D(xSize, ySize); noiseTex.filterMode = FilterMode.Point; float[,] heights = new float[xSize, ySize]; for (int x = 0; x < xSize; x++) { for (int y = 0; y < xSize; y++) { float xCoord = (float)(x - xSize / 2) / xSize * noiseScale + xOffset; float yCoord = (float)(y - ySize / 2) / ySize * noiseScale + yOffset; if (useOctaves) { NoiseS3D.octaves = octaves; heights[x, y] = (float)NoiseS3D.NoiseCombinedOctaves(xCoord, yCoord); } else { heights[x, y] = Mathf.PerlinNoise(xCoord, yCoord); } } } return(heights); }
public static Texture2D MakeTexture(int height, int width, int octaves, float noiseScale) { Texture2D noiseTex = new Texture2D(width, height); noiseTex.filterMode = FilterMode.Point; for (int x = 0; x < noiseTex.width; x++) { for (int y = 0; y < noiseTex.height; y++) { float noiseValue = 0; NoiseS3D.octaves = octaves; noiseValue = (float)NoiseS3D.NoiseCombinedOctaves(x * noiseScale, y * noiseScale); //remap the value to 0 - 1 for color purposes noiseValue = (noiseValue + 1) * 0.5f; noiseTex.SetPixel(x, y, new Color(noiseValue, noiseValue, noiseValue)); } } return(noiseTex); }
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; }