Skip to content

Instantly share code, notes, and snippets.

@todorok1
Created January 6, 2021 16:51
Show Gist options
  • Select an option

  • Save todorok1/5e558a13e74540bd8800ff582c11d55d to your computer and use it in GitHub Desktop.

Select an option

Save todorok1/5e558a13e74540bd8800ff582c11d55d to your computer and use it in GitHub Desktop.
パーリンノイズを重ね合わせてより自然な地形を作ることを目指したサンプル
/// <Summary>
/// 複数のパーリンノイズを重ね合わせるメソッドです。
/// </Summary>
float GetAddedPerlinNoise(float xPos, float yPos)
{
// 重ね合わせの回数が0の場合はそのまま0を返します。
if (addTimes == 0)
{
return 0f;
}
// 乱数のシードを設定します。
Random.InitState(seed);
// パーリンノイズの値を指定回数だけ加算します。
float perlinValue = 0f;
for (int i = 0; i < addTimes; i++)
{
float offsetValue = Random.value;
float xOffset = offsetValue * fieldSizeX;
float yOffset = offsetValue * fieldSizeZ;
float scaleOffset = Random.Range(0.8f, 1.25f);
float xValue = (xPos + xOffset) * scaleOffset;
float yValue = (yPos + yOffset) * scaleOffset;
perlinValue += Mathf.PerlinNoise(xValue, yValue);
}
// 重ね合わせた回数で平均を取ります。
perlinValue = perlinValue / addTimes;
return perlinValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment