Archived
Private
Public Access
1
0
This repository has been archived on 2026-02-04. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
ProjectBackup/Unity/Minecraft/Assets/Scripts/Noise.cs
2022-11-12 13:10:03 +01:00

28 lines
978 B
C#

using Terrain;
using UnityEngine;
public static class Noise {
public static float Get2dPerlin(in Vector2 position, in float offset, in float scale) {
return Mathf.PerlinNoise(
(position.x + 0.1f) / WorldData.ChunkSize.x * scale + offset,
(position.y + 0.1f) / WorldData.ChunkSize.x * scale + offset
);
}
public static bool Get3dPerlin(in Vector3 position, in float offset, in float scale, in float threshold) {
float x = (position.x + offset + 0.1f) * scale;
float y = (position.y + offset + 0.1f) * scale;
float z = (position.z + offset + 0.1f) * scale;
float AB = Mathf.PerlinNoise(x, y);
float BC = Mathf.PerlinNoise(y, z);
float AC = Mathf.PerlinNoise(x, z);
float BA = Mathf.PerlinNoise(y, x);
float CB = Mathf.PerlinNoise(z, y);
float CA = Mathf.PerlinNoise(z, x);
return (AB + BC + AC + BA + CB + CA) / 6f > threshold;
}
}