//! [`Material`]: a PBR-lite surface description.
//!
//! Stage 4 keeps materials to the parameters the basic lit pass consumes:
//! an albedo (base) color plus metallic/roughness factors. Textures, emissive,
//! and the full PBR set arrive with the shader system in a later stage.

use serde::{Deserialize, Serialize};

use crate::math::Color;

/// A PBR-lite material: base color and metallic/roughness factors.
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub struct Material {
    /// Base (albedo) color, linear RGBA.
    pub albedo: Color,
    /// Metalness in `[0, 1]` (0 = dielectric, 1 = metal).
    pub metallic: f32,
    /// Perceptual roughness in `[0, 1]` (0 = mirror, 1 = fully rough).
    pub roughness: f32,
}

impl Default for Material {
    /// A neutral mid-gray dielectric.
    fn default() -> Self {
        Self {
            albedo: Color::rgb(0.8, 0.8, 0.8),
            metallic: 0.0,
            roughness: 0.6,
        }
    }
}

impl Material {
    /// A matte, non-metallic material of the given color.
    pub fn diffuse(albedo: Color) -> Self {
        Self {
            albedo,
            metallic: 0.0,
            roughness: 0.9,
        }
    }

    /// A metallic material of the given color and roughness.
    pub fn metal(albedo: Color, roughness: f32) -> Self {
        Self {
            albedo,
            metallic: 1.0,
            roughness: roughness.clamp(0.0, 1.0),
        }
    }
}
