软件Perlin噪声实现

我已根据此处 , 此处 , 此处和此处的信息编写了2D Perlin噪声实现。 但是,输出看起来像这样 。

public static double Perlin(double X, double XScale, double Y, double YScale, double Persistance, double Octaves) { double total=0.0; for(int i=0;i> 16)); uint m_w = (uint) (18000 * (Y & 65535) + (Y >> 16)); uint ou = (m_z << 16) + m_w; return ((ou + 1.0) * 2.328306435454494e-10); } 

任何有关错误的输入都表示赞赏。

编辑:我找到了解决这个问题的方法:我使用了一个在加载时生成的双精度数组来解决这个问题。 但是,任何实现良好随机数发生器的方法都是值得赞赏的。

我想这个效果是由于你的噪音function(所有其他代码看起来都不错)。

function

 private static double Noise (int X, int Y) { uint m_z = (uint) (36969 * (X & 65535) + (X >> 16)); uint m_w = (uint) (18000 * (Y & 65535) + (Y >> 16)); uint ou = (m_z << 16) + m_w; return ((ou + 1.0) * 2.328306435454494e-10); } 

不是很嘈杂,但与输入的XY变量密切相关。 尝试使用您输入的任何其他伪随机函数。

我在C中重建了你的代码并遵循@Howard的建议,这段代码对我来说很有用。 我不确定你使用的Interpolatefunction。 我在代码中使用了线性插值。 我使用了以下噪音function:

 static double Noise2(int x, int y) { int n = x + y * 57; n = (n<<13) ^ n; return ( 1.0 - ( (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0); }