I am creating a game in which a world map is generated using Perlin noise, and then specific points in the map are rendered using higher resolution Perlin noise. I am trying to do this by zooming in on specific points of the map, therefore rendering them at a high resolution (by dividing by a larger number in my Perlin calculations)
This works exactly as intended, up until I try to offset the Perlin noise from the center. As soon as this is done, zooming in no longer works-- When you zoom in, random noise is produced. I have ensured that the offset is remaining consistent, so it isn't that.
I have a feeling I'm misunderstanding something about how Perlin noise works, here. The following code works fine.
public void Generate()
{
var perlin = new Perlin();
for (int x = 0; x < 100; x++)
{
for (int y = 0; y < 100; y++)
{
TileBase tile = GetTile((1d + perlin.NoiseOctaves(
(double)(x - 50) / scale.value,
(double)(y - 50) / scale.value,
0.5d, 10, lacunarity.value, 1 - persistence.value)) / 2d);
tilemap.SetTile(new Vector3Int(x , y, 0), tile);
}
}
}
However, as soon as I try to offset x by a constant value in order to make the noise different, it breaks the zoom-in feature.
https://gyazo.com/a741bec0ec9e509e796a70d8750cf10d Expected behavior
https://gyazo.com/d3460e3cfbf7562b0582eacfd9b0d662 Offsetted, unexpected behavior
What could be going wrong? Am I misunderstanding something with Perlin noise? Any help is much appreciated!
Edit: The -50 in the calculation is because I am working with a 100 x 100 tile grid, and I am wanting to zoom in on the center, rather than on the bottom left corner as would be the default behavior. The offset code would look like this:
public void Generate()
{
var perlin = new Perlin();
for (int x = 0; x < 100; x++)
{
for (int y = 0; y < 100; y++)
{
TileBase tile = GetTile((1d + perlin.NoiseOctaves(
(double)(x - 50 + offsetX) / scale.value,
(double)(y - 50 + offsetX) / scale.value,
0.5d, 10, lacunarity.value, 1 - persistence.value)) / 2d);
tilemap.SetTile(new Vector3Int(x , y, 0), tile);
//tilemap.SetTile(new Vector3Int(x, y, 0), );
}
}
}
With the offsets being randomly generated integers.
- 50
your offset? If not, can you edit your question to show the code that adds the offset? \$\endgroup\$