【发布时间】:2020-04-20 08:57:51
【问题描述】:
我使用 Unity 中的 Perlin Noise 制作了一个 Noise 类,如下所示:
public static float[,] GetNoise(Vector2Int initialOffset, float scale, float persistance, float lacunarity, int octaves)
{
float[,] noiseMap = new float[Chunk.width, Chunk.height];
float maxHeight = 0;
float minHeight = 0;
for (int y = 0; y < Chunk.height; y++)
{
for (int x = 0; x < Chunk.width; x++)
{
float amplitude = 1;
float frequency = 1;
float noiseHeight = 0;
for (int oc = 0; oc < octaves; oc++)
{
float coordX = (x + initialOffset.x) / scale * frequency;
float coordY = (y + initialOffset.y) / scale * frequency;
float perlin = Mathf.PerlinNoise(coordX, coordY) * 2 - 1;
noiseHeight += perlin * amplitude;
amplitude *= persistance;
frequency *= lacunarity;
}
if (noiseHeight < minHeight)
{
minHeight = noiseHeight;
}
if (noiseHeight > maxHeight)
{
maxHeight = noiseHeight;
}
noiseMap[x, y] = noiseHeight;
}
}
for (int y = 0; y < Chunk.height; y++)
{
for (int x = 0; x < Chunk.width; x++)
{
noiseMap[x, y] = Mathf.InverseLerp(minHeight, maxHeight, noiseMap[x, y]);
}
}
return noiseMap;
}
我做错了什么?还是没有办法摆脱这些模式?
【问题讨论】:
-
有人能解释一下为什么不喜欢这个问题吗?有什么问题吗?
-
您是否尝试在后缀中添加噪音以增加更多随机性?看到这个:forum.unity.com/threads/perlin-noise-repeated-values.248132/…
-
您是否对 x 和 y 偏移使用不同的值?
-
@Jake 是的,偏移量是瓦片和原点(瓦片 0、0)之间的距离,我计算出每个块的大小乘以块的位置
-
@Kale_Surfer_Dude 我正在使用八度音阶,这算吗?我使用的设置是 0.5 表示持久性,2 表示空隙,4 表示八度音阶和 12 的比例
标签: unity3d perlin-noise