我正在使用perlin噪聲函數來生成我正在製作的遊戲的數據,但由於某種原因,它不斷返回不同輸入的完全相同的結果。我花了4個小時試圖在我的FBM功能上進行調試,並且無法弄清楚,所以我嘗試了Ken Perlin改進的噪聲功能,並且發生了相同的事情。Perlin Noise函數爲不同的輸入返回相同的結果
有誰知道這是爲什麼?什麼是解決問題的好方法?我所能做的唯一事情就是在x和y座標中添加一個像.6473這樣的十進制值,這有助於提高其他問題的性能,例如在數組中重複自己的值。
這是一些測試代碼。我正在嘗試創建兩個填充了噪聲值的不同2D數組。 x和y輸入是我遊戲中的座標。在'* *'後面的行上,如果我不增加這些值,那麼這兩個數組都將填充全零。在該示例中,座標(0.0,-768.0)和(-1024.0,-768.0)返回完全相同的噪聲值。在我的遊戲中,9個不同的座標返回相同的值。
我使用該測試的柏林噪聲函數是here
public class TestPerlinMain
{
public static void main(String[] args)
{
int seed = 532434;
//create first noise array
double x = 0.0; //x-coordinate
double y = -768.0; //y-coordinate
float z = 10.0f;
double[][] test = new double[15][15];
System.out.println("Noise Array 1: ");
for(int i = 0; i < test.length; i++)
{
for(int j = 0; j < test[i].length; j++)
{
test[i][j] = ImprovedNoise.noise(x + (j * 64.0), y + (i * 64.0), 10.0);
x += .314f;//************
System.out.print(test[i][j] + " ");
}
y += .314f;//***********
}
System.out.println();
//create 2nd noise array
double x2 = -1024.0; //x coordinate
double y2 = -768.0; //y coordinate
float z2 = 10.0f;
System.out.println();
double[][] test2 = new double[15][15];
System.out.println("Noise Array 2: ");
for(int i = 0; i < test2.length; i++)
{
for(int j = 0; j < test2[i].length; j++)
{
test2[i][j] = ImprovedNoise.noise(x2 + (j * 64.0), y2 + (i * 64.0), 10.0);
x2 += .314f;//*************
System.out.print(test2[i][j] + " ");
}
y2 += .314f;//************
}
System.out.println();
}
我都試過了你我做了一個非int值,並得到了相同的結果,我也嘗試通過噪聲(j/4,i/4,z)來縮放噪聲,並獲得了相同的結果。另外,你的意思是一個大小爲256x256的tile或者一個包含256個tile的數組? – theDazzler 2012-03-06 03:47:27
我試圖在最後一段中提到的一點是,噪聲函數每256(在x,y和z中)重複,所以, (1,3)處的值與(257,259)或(1,769)或通常(x + 256n,y + 256m)處的值相同。由於1024和768是多個當然,第二個數組與第一個匹配。 – 2012-03-06 17:52:00
我回家時會看看。無論如何,我是一個FBM功能,我只是用它來測試。我昨天晚上做了一些改變,但是我不認爲這是理想的。 – theDazzler 2012-03-06 21:22:40