using UnityEngine;

public class NoiseGenerator
{
    public float GetNoise(float x, float y, float scale)
    {
        return Mathf.PerlinNoise(x * scale, y * scale) * 2f - 1f;
    }
    
    public float GetNoise(float x, float y, float z, float scale)
    {
        // 3D noise approximation using multiple 2D noise samples
        float xy = Mathf.PerlinNoise(x * scale, y * scale);
        float xz = Mathf.PerlinNoise(x * scale, z * scale);
        float yz = Mathf.PerlinNoise(y * scale, z * scale);
        
        return (xy + xz + yz) / 3f * 2f - 1f;
    }
    
    public float GetFractalNoise(float x, float y, float scale, int octaves = 4)
    {
        float value = 0f;
        float amplitude = 1f;
        float frequency = scale;
        float maxValue = 0f;
        
        for (int i = 0; i < octaves; i++)
        {
            value += Mathf.PerlinNoise(x * frequency, y * frequency) * amplitude;
            maxValue += amplitude;
            amplitude *= 0.5f;
            frequency *= 2f;
        }
        
        return (value / maxValue) * 2f - 1f;
    }
}