// Returns -1.0 to 1.0 public float get(int i, int j, int k) { var value = generator .noise((startX + i) * frequency, (startY + j) * frequency, (startZ + k) * frequency) * 5.0f; return(value); }
public bool Lookup(SimplexNoiseGenerator noiseGen, Vector3 pos) { pos.x += PosOffset; pos.y += PosOffset; pos.z += PosOffset; pos *= PosScale; return(noiseGen.noise(pos.x, pos.y, pos.z) > NoiseThreshold); }
public void LoadChunk(Vector3i key, BlockType[,,] output) { for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { int wx = key.x * 16 + x; int wz = key.z * 16 + z; float foo; //float foo = Mathf.PerlinNoise(wx*0.1f, wz*0.1f); //foo = Mathf.Cos(foo*Mathf.PI)*0.5f + 0.5f; //foo *= foo; //foo *= 0.15f; foo = Mathf.PerlinNoise(123 + wx * 0.02f, 456 + wz * 0.02f) * 0.8f; foo *= 64; foo += 64; for (int y = 0; y < 16; y++) { BlockType block; int wy = key.y * 16 + y; if (wy > foo) { // Air above ground level block = BlockType.Empty; } else { // default to dirt block = new BlockType(1); if (wy < (foo - 1) * 0.95f) { // bottom is stone block = new BlockType(2); } else if (wy > (foo - 1)) { // top layer is grass block = new BlockType(3); } } if (block != BlockType.Empty) { float caves = _simplex.noise(wx * 0.05f, wy * 0.05f, wz * 0.05f); if (caves > 0.05f) { // hole block = BlockType.Empty; } } output[x, y, z] = block; } } } }
private float Lookup(Vector3 pos) { float height = GetHeight(pos / Chunk.BlockSize); pos = entity.TransformVertex(pos); pos += new Vector3(30000.0f, 30000.0f, 30000.0f); return(noiseGen.noise(pos.x, pos.y, pos.z) * info.HeightScale * planetScale + (info.HeightLimit * planetScale - height)); }
void Prepare() { var sn = new SimplexNoiseGenerator(); for (int x = 0; x < lEdge; x++) { for (int y = 0; y < lEdge; y++) { for (int z = 0; z < lEdge; z++) { var i = x + lEdge * y + lEdge * lEdge * z; var val = sn.noise(x, y, z); data[i] = new Vector4(x, y, z, val); } } } }
public static float[,] GenerateNoiseMap(NoiseType noiseType, int width, int height, float scale, int offsetX, int offsetY, int octaves, float persistence, float lacunarity, float noiseRedistributionFactor) { float[,] noiseMap = new float[width, height]; float maxPossibleHeight = 0f; float amplitude = 1; float frequency = 1; // Find max possible height to normalize heightmap globally for (int i = 0; i < octaves; i++) { maxPossibleHeight += amplitude; amplitude *= persistence; } for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float noiseHeight = 0; amplitude = 1; frequency = 1; for (int i = 0; i < octaves; i++) { float sampleX = (float)(x + offsetX) / (float)width * scale * frequency; float sampleY = (float)(y + offsetY) / (float)height * scale * frequency; float noiseValue; if (noiseType == NoiseType.Perlin) { noiseValue = Mathf.PerlinNoise(sampleX, sampleY) * 2 - 1; } else if (noiseType == NoiseType.Simplex) { noiseValue = simplexNoiseGenerator.noise(sampleX, sampleY, 0) * 2; } else { noiseValue = 0f; } noiseHeight += noiseValue * amplitude; amplitude *= persistence; frequency *= lacunarity; } noiseMap[x, y] = noiseHeight; } } // Normalize map and apply noise redistribution for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { noiseMap[x, y] = Mathf.InverseLerp(-maxPossibleHeight, maxPossibleHeight, noiseMap[x, y]); noiseMap[x, y] = Mathf.Pow(noiseMap[x, y], noiseRedistributionFactor); } } return(noiseMap); }