using UnityEngine; using UnityEngine.InputSystem; public class Noise : MonoBehaviour { [SerializeField] private ComputeShader noiseShader; [Space(15)] public float frequency = 0.001f; public float amplitude = 1; public int octaves = 4; public float persistence = 0.5f; public void Generate(int numPointsPerAxis, int numThreadsPerAxis, Vector3 offset) { var pointsBuffer = Buffers.pointsBuffer; noiseShader.SetBuffer(0, "points", pointsBuffer); noiseShader.SetInt("numPointsPerAxis", numPointsPerAxis); noiseShader.SetFloat("frequency", frequency); noiseShader.SetInt("octaves", octaves); noiseShader.SetFloat("amplitude", amplitude); noiseShader.SetFloat("persistence", persistence); var vec4 = new Vector4(offset.x, offset.y, offset.z, 0); noiseShader.SetVector("offset", vec4); noiseShader.Dispatch(0, numThreadsPerAxis,numThreadsPerAxis,numThreadsPerAxis); #if UNITY_EDITOR Vector4[] arr = new Vector4[pointsBuffer.count]; Buffers.pointsBuffer.GetData(arr,0,0, pointsBuffer.count); var min = arr[0].w; var max = min; foreach (var p in arr) { if (min > p.w) min = p.w; if (max < p.w) max = p.w; } Debug.Log($"{min} || {max}"); #endif } }