Skip to content

Instantly share code, notes, and snippets.

@todorok1
Created January 7, 2021 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todorok1/ca2ad2d1a44b1ef81c5dd3a2931a49f1 to your computer and use it in GitHub Desktop.
Save todorok1/ca2ad2d1a44b1ef81c5dd3a2931a49f1 to your computer and use it in GitHub Desktop.
TerrainのHeightMapを生成するスクリプト(エディタ拡張のクラス)
/// <Summary>
/// 複数のパーリンノイズをかけ合わせるメソッドです。
/// </Summary>
float GetMultiplePerlinNoise(float xPos, float yPos, int terrainSizeX, int terrainSizeZ, TerrainGenerator generator)
{
// 乱数のシードを設定します。
Random.InitState(generator.seed);
// パーリンノイズの値を指定回数だけ乗算します。
float perlinValue = Mathf.PerlinNoise(xPos, yPos);
for (int i = 0; i < generator.multipleTimes; i++)
{
float offsetValue = Random.value;
float xOffset = offsetValue * terrainSizeX;
float yOffset = offsetValue * terrainSizeZ;
float scaleOffset = Random.Range(0.8f, 1.25f);
float xValue = (xPos + xOffset) * scaleOffset;
float yValue = (yPos + yOffset) * scaleOffset;
float value = Mathf.PerlinNoise(xValue, yValue);
perlinValue *= Mathf.Clamp01(value);
}
return perlinValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment