use crate::Float;
use crate::core::geometry::{Point3f, Vector3f};
use crate::core::texture::{TextureEvalContext, TextureMapping3D};
use crate::utils::noise::fbm;

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct WindyTexture {
    pub mapping: TextureMapping3D,
}

impl WindyTexture {
    pub fn evaluate(&self, ctx: &TextureEvalContext) -> Float {
        let c = self.mapping.map(ctx);
        let wind_strength = fbm(
            Point3f::from(0.1 * Vector3f::from(c.p)),
            0.1 * c.dpdx,
            0.1 * c.dpdy,
            0.5,
            3,
        );
        let wave_height = fbm(c.p, c.dpdx, c.dpdy, 0.5, 6);
        wind_strength.abs() * wave_height
    }
}
