Using Perlin Noise to generate an infinite world

So i have this function :


public PerlinNoise(int width, int height, int freq, float persistency,
			   int density, float sharpness, int detail, float amplitude, long seed)

It generates me perfectly good Perlin Noise. I’m using it to create a 2d height map.

I just can’t seem to figure out how to get an infinite world out of it. Say i generate a 1024x1024 map with it. That’s cool, i have a 1024x1024 grid. Now, how do i get past that? If every pixel is a 3d block in-game, how can i calculate past the initial first 1024 ?

Adapt the perlin noise function to take x & z values instead of a seed value, then you can get height data for any x,z location. If you use doubles for x & z you’ll get a very, very big (near-infinite) landscape.

Can’t seem to get it to work perfectly.

I have this: (not the complete Perlin code here)


public PerlinNoise(int width, int height, int startFreqX, int endFreqX, int startFreqY, int endFreqY, float persistency,
			   int density, float cloudSharpness, int detail, float amplitude, long seed)


public void run()
		{
                        Random r = new Random();
                        r.setSeed(seed);
			BufferedImage temp = new BufferedImage(endFreqX, endFreqY ,
					BufferedImage.TYPE_4BYTE_ABGR);
			Graphics2D g = temp.createGraphics();
			// generate a low-res random image
			for (int i = 0; i < endFreqX ; i++)
			{
				for (int j = 0; j < endFreqY; j++)
				{
                                        int val = r.nextInt(255);
                               
					g.setColor(new Color(val, val, val, (int) (alpha * 0xFF)));
					g.fillRect(i, j, 1, 1);
				}
			}
			g.dispose();
			// re-scale the image up using interpolation (in this case, linear)
			image = new BufferedImage(width, height,
					BufferedImage.TYPE_4BYTE_ABGR);
			g = image.createGraphics();
			g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
					RenderingHints.VALUE_INTERPOLATION_BILINEAR);

			g.drawImage(temp, 0, 0, width, height, startFreqX, startFreqY, endFreqX , endFreqY , null);
			g.dispose();
		}
	}

With these parameters
(256, 128, 0, 24, 0, 12, 8.0f, 120, 0.10f, 5, 0.99f, 1l) i get a 256x128 b&w map.

Now, i want to work in 128x128 blocks. To get the first block, i enter:
(128,128, 0, 12, 0, 12, 8.0f, 120, 0.10f, 5, 0.99f, 1l)

And to get the second block to the right, i enter:
(128,128, 12, 24, 0, 12, 8.0f, 120, 0.10f, 5, 0.99f, 1l)

I almost works, you can clearly see the resemblance, but there’s always a few pixels different near the edge. It’s not acceptable for map generation.

What is wrong ?

I’ll repeat what SimonH said. You have to feed coordinates, otherwise “edges” of your precomputed regions will not match. Since you’re combining multiple “frequencies” (or zoom/scale levels) of noise, the coordinates must match at all levels.

Ok, I see what was wrong. I was not using a real Perlin noise algorithm, but a function that creates noise by re-scaling a low-res noise bitmap… It’s working fine now.

Could you post your Perlin noise function please?