euv_core/game/engine3d/material/struct.rs
1use super::*;
2
3/// Pre-baked 2D affine UV transform implementing `KHR_texture_transform`.
4#[derive(Clone, Copy, Data, Debug, PartialEq)]
5pub struct TextureTransform3D {
6 /// UV translation offset `(u, v)`.
7 #[get(type(copy))]
8 pub(crate) offset: Vec2,
9 /// Counter-clockwise UV rotation in radians.
10 #[get(type(copy))]
11 pub(crate) rotation: f32,
12 /// UV scale `(su, sv)`.
13 #[get(type(copy))]
14 pub(crate) scale: Vec2,
15 /// Pre-baked 2x3 affine matrix `[m00, m01, m02, m10, m11, m12]` for single-FMA shader UV evaluation.
16 #[get(type(copy))]
17 pub(crate) uv_matrix: [f32; 6],
18}
19
20/// Texture binding reference pairing a texture pool index, UV set, and optional `KHR_texture_transform`.
21#[derive(Clone, Copy, Data, Debug, PartialEq)]
22pub struct TextureSlot3D {
23 /// Texture asset index inside the scene texture table.
24 #[get(type(copy))]
25 pub(crate) texture_index: u32,
26 /// UV attribute channel index (`0` = `TEXCOORD_0`, `1` = `TEXCOORD_1`).
27 #[get(type(copy))]
28 pub(crate) tex_coord: u8,
29 /// Per-slot affine UV transform (`KHR_texture_transform`).
30 #[get(type(copy))]
31 pub(crate) transform: TextureTransform3D,
32}
33
34/// Complete 1:1 Blender 4.x/5.x Principled BSDF material supporting glTF 2.0 core and all KHR PBR extensions.
35#[derive(Clone, Data, Debug, PartialEq)]
36pub struct PrincipledMaterial3D {
37 /// Human-readable Blender material name.
38 pub(crate) name: String,
39 /// Linear base albedo RGBA multiplier (`[1.0, 1.0, 1.0, 1.0]` default).
40 #[get(type(copy))]
41 pub(crate) base_color_factor: [f32; 4],
42 /// Optional sRGB base color texture binding.
43 #[get(type(copy))]
44 pub(crate) base_color_texture: Option<TextureSlot3D>,
45 /// Metallic factor in `[0.0, 1.0]`.
46 #[get(type(copy))]
47 pub(crate) metallic_factor: f32,
48 /// Perceptual roughness factor in `[0.04, 1.0]`.
49 #[get(type(copy))]
50 pub(crate) roughness_factor: f32,
51 /// Optional linear metallic-roughness texture (`G` = roughness, `B` = metallic).
52 #[get(type(copy))]
53 pub(crate) metallic_roughness_texture: Option<TextureSlot3D>,
54 /// Optional tangent-space normal map binding.
55 #[get(type(copy))]
56 pub(crate) normal_texture: Option<TextureSlot3D>,
57 /// Normal map tangent-plane scale multiplier.
58 #[get(type(copy))]
59 pub(crate) normal_scale: f32,
60 /// Optional ambient occlusion map binding (`R` channel).
61 #[get(type(copy))]
62 pub(crate) occlusion_texture: Option<TextureSlot3D>,
63 /// Ambient occlusion strength in `[0.0, 1.0]`.
64 #[get(type(copy))]
65 pub(crate) occlusion_strength: f32,
66 /// Linear base emissive RGB color.
67 #[get(type(copy))]
68 pub(crate) emissive_factor: [f32; 3],
69 /// Optional sRGB emissive texture binding.
70 #[get(type(copy))]
71 pub(crate) emissive_texture: Option<TextureSlot3D>,
72 /// HDR emissive luminance multiplier from `KHR_materials_emissive_strength`.
73 #[get(type(copy))]
74 pub(crate) emissive_strength: f32,
75 /// Alpha compositing mode (`Opaque`, `Mask`, `Blend`).
76 #[get(type(copy))]
77 pub(crate) alpha_mode: AlphaMode3D,
78 /// Alpha cutout threshold when `alpha_mode == AlphaMode3D::Mask`.
79 #[get(type(copy))]
80 pub(crate) alpha_cutoff: f32,
81 /// Whether backface culling is disabled for thin double-sided geometry.
82 #[get(type(copy))]
83 pub(crate) double_sided: bool,
84 /// Whether lighting is bypassed (`KHR_materials_unlit`).
85 #[get(type(copy))]
86 pub(crate) unlit: bool,
87 /// Dielectric index of refraction from `KHR_materials_ior` (default `1.5`).
88 #[get(type(copy))]
89 pub(crate) ior: f32,
90 /// Dielectric specular intensity scalar from `KHR_materials_specular`.
91 #[get(type(copy))]
92 pub(crate) specular_factor: f32,
93 /// Dielectric specular tint RGB from `KHR_materials_specular`.
94 #[get(type(copy))]
95 pub(crate) specular_color_factor: [f32; 3],
96 /// Optional `KHR_materials_specular` factor texture (`A` channel).
97 #[get(type(copy))]
98 pub(crate) specular_texture: Option<TextureSlot3D>,
99 /// Optional `KHR_materials_specular` RGB tint texture.
100 #[get(type(copy))]
101 pub(crate) specular_color_texture: Option<TextureSlot3D>,
102 /// Clearcoat layer weight from `KHR_materials_clearcoat`.
103 #[get(type(copy))]
104 pub(crate) clearcoat_factor: f32,
105 /// Clearcoat layer roughness from `KHR_materials_clearcoat`.
106 #[get(type(copy))]
107 pub(crate) clearcoat_roughness_factor: f32,
108 /// Optional clearcoat intensity texture (`R` channel).
109 #[get(type(copy))]
110 pub(crate) clearcoat_texture: Option<TextureSlot3D>,
111 /// Optional clearcoat roughness texture (`G` channel).
112 #[get(type(copy))]
113 pub(crate) clearcoat_roughness_texture: Option<TextureSlot3D>,
114 /// Optional clearcoat tangent-space normal map.
115 #[get(type(copy))]
116 pub(crate) clearcoat_normal_texture: Option<TextureSlot3D>,
117 /// Optical transmission factor from `KHR_materials_transmission` (`0.0..=1.0`).
118 #[get(type(copy))]
119 pub(crate) transmission_factor: f32,
120 /// Optional optical transmission texture (`R` channel).
121 #[get(type(copy))]
122 pub(crate) transmission_texture: Option<TextureSlot3D>,
123 /// Refractive volume thickness from `KHR_materials_volume` in meters.
124 #[get(type(copy))]
125 pub(crate) thickness_factor: f32,
126 /// Beer-Lambert optical attenuation distance from `KHR_materials_volume`.
127 #[get(type(copy))]
128 pub(crate) attenuation_distance: f32,
129 /// Beer-Lambert optical attenuation color from `KHR_materials_volume`.
130 #[get(type(copy))]
131 pub(crate) attenuation_color: [f32; 3],
132 /// Grazing microfiber sheen RGB tint from `KHR_materials_sheen`.
133 #[get(type(copy))]
134 pub(crate) sheen_color_factor: [f32; 3],
135 /// Sheen layer roughness from `KHR_materials_sheen`.
136 #[get(type(copy))]
137 pub(crate) sheen_roughness_factor: f32,
138 /// Optional sRGB sheen color texture.
139 #[get(type(copy))]
140 pub(crate) sheen_color_texture: Option<TextureSlot3D>,
141 /// Optional linear sheen roughness texture (`A` channel).
142 #[get(type(copy))]
143 pub(crate) sheen_roughness_texture: Option<TextureSlot3D>,
144}
145
146/// Cache-aligned 160-byte GPU std140 material block uploaded to Metal/WGSL/GLSL/HLSL storage buffers.
147#[repr(C, align(16))]
148#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
149pub struct GpuMaterialData3D {
150 /// Linear base albedo RGBA multiplier.
151 #[get(type(copy))]
152 pub(crate) base_color_factor: [f32; 4],
153 /// Linear HDR emissive RGB (`emissive * emissive_strength`) and `alpha_cutoff` in `.w`.
154 #[get(type(copy))]
155 pub(crate) emissive_alpha_cutoff: [f32; 4],
156 /// `[metallic, roughness, ior, specular_factor]`.
157 #[get(type(copy))]
158 pub(crate) pbr_ior_specular: [f32; 4],
159 /// `[specular_color.r, specular_color.g, specular_color.b, clearcoat_factor]`.
160 #[get(type(copy))]
161 pub(crate) specular_color_clearcoat: [f32; 4],
162 /// `[clearcoat_roughness, normal_scale, occlusion_strength, transmission_factor]`.
163 #[get(type(copy))]
164 pub(crate) clearcoat_normal_occ_trans: [f32; 4],
165 /// `[attenuation_color.r, attenuation_color.g, attenuation_color.b, thickness_factor]`.
166 #[get(type(copy))]
167 pub(crate) volume_attenuation: [f32; 4],
168 /// `[sheen_color.r, sheen_color.g, sheen_color.b, sheen_roughness]`.
169 #[get(type(copy))]
170 pub(crate) sheen_color_roughness: [f32; 4],
171 /// Primary bindless texture indices `[base_color, metallic_roughness, normal, occlusion]`.
172 #[get(type(copy))]
173 pub(crate) tex_indices_a: [u32; 4],
174 /// Secondary bindless texture indices `[emissive, clearcoat, sheen, transmission]`.
175 #[get(type(copy))]
176 pub(crate) tex_indices_b: [u32; 4],
177 /// `[flags_bitmask, attenuation_distance.to_bits(), clearcoat_normal_tex, specular_tex]`.
178 #[get(type(copy))]
179 pub(crate) flags_volume: [u32; 4],
180}