Skip to main content

re_core/
material.rs

1use serde::{Deserialize, Serialize};
2
3/// Simple PBR-style material, maps directly onto glTF `pbrMetallicRoughness`.
4#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
5pub struct Material {
6    pub name: String,
7    /// Linear RGBA base color.
8    pub base_color: [f32; 4],
9    pub metallic: f32,
10    pub roughness: f32,
11    /// Linear RGB emissive factor.
12    pub emissive: [f32; 3],
13    #[serde(default)]
14    pub double_sided: bool,
15    /// Optional albedo/base-color texture path (relative to asset dir).
16    #[serde(default)]
17    pub albedo_texture_id: Option<String>,
18    /// Optional normal map texture path (relative to asset dir).
19    #[serde(default)]
20    pub normal_texture_id: Option<String>,
21}
22
23impl Default for Material {
24    fn default() -> Self {
25        Self {
26            name: "default".into(),
27            base_color: [0.8, 0.8, 0.8, 1.0],
28            metallic: 0.0,
29            roughness: 0.6,
30            emissive: [0.0, 0.0, 0.0],
31            double_sided: false,
32            albedo_texture_id: None,
33            normal_texture_id: None,
34        }
35    }
36}
37
38impl Material {
39    pub fn colored(name: &str, rgba: [f32; 4]) -> Self {
40        Self {
41            name: name.into(),
42            base_color: rgba,
43            ..Default::default()
44        }
45    }
46}