From c80016a9ef91da2362d6874c130941efcf36ac00 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Thu, 9 Jan 2025 03:01:52 +0100 Subject: add more gltf extensions --- doc/resources.md | 78 ++++++++++++++++++++++++++++++++----------------- shared/src/resources.rs | 5 ++++ world/Cargo.toml | 3 ++ world/src/mesh.rs | 13 +++++++-- 4 files changed, 69 insertions(+), 30 deletions(-) diff --git a/doc/resources.md b/doc/resources.md index a6b885b..4931f51 100644 --- a/doc/resources.md +++ b/doc/resources.md @@ -27,38 +27,62 @@ ## MeshPart -Combinations of g__, va__ and tex_* are multiplied except normal which is added. -Defaults should be the identity for that operation, so default is 1 / white -except normals are zero. - -| Key | Value Type | | -| ---------------- | ------------- | ------------------ | -| index | Resource | | -| g_metallic | f32 | | -| g_roughness | f32 | | -| g_albedo | Vec3 | | -| g_transmission | f32 | | -| g_emission | Vec3 | | -| va_position | [Resource; 3] | | -| va_normal | [Resource; 3] | | -| va_texcoord | [Resource; 2] | | -| va_roughness | Resource | | -| va_metallic | Resource | | -| va_albedo | [Resource; 3] | | -| va_transmission | Resource | | -| va_emission | Resource | | -| tex_normal | Resource | Use color channels | -| tex_roughness | Resource | Use green channel | -| tex_metallic | Resource | Use blue channel | -| tex_albedo | Resource | Use color channels | -| tex_transmission | Resource | Use alpha channel | -| tex_emission | Resource | Use color channels | +Combinations of g_\*, va_\* and tex_\* are multiplied except normal which is +added. Defaults should be the identity for that operation, so default is 1 / +white except normals are zero. + +| Key | Value Type | | | +| ------------------ | ------------- | - | ------------------ | +| index | Resource | | | +| g_metallic | Float | | | +| g_roughness | Float | | | +| g_albedo | Vec3 | | | +| g_alpha | Float | | | +| g_transmission | Float | | | +| g_emission | Vec3 | | | +| g_refractive_index | Float | | | +| g_attenuation | Vec3 | | | +| g_dispersion | Float | | | +| g_thickness | Float | | | +| va_position | [Resource; 3] | | | +| va_normal | [Resource; 3] | | | +| va_texcoord | [Resource; 2] | | | +| va_roughness | Resource | | | +| va_metallic | Resource | | | +| va_albedo | [Resource; 3] | | | +| va_alpha | Resource | | | +| va_transmission | Resource | | | +| va_emission | Resource | | | +| tex_normal | Resource | | Use color channels | +| tex_roughness | Resource | | Use green channel | +| tex_metallic | Resource | | Use blue channel | +| tex_albedo | Resource | | Use color channels | +| tex_alpha | Resource | | Use alpha channel | +| tex_transmission | Resource | | Use red channel | +| tex_emission | Resource | | Use color channels | +| tex_thickness | Resource | | Use green channels | + +- **Attenuation**: Attenuation coefficient for each color channel due to + scattering within the material volume expressed as e-folding distance (m^-1). + See [KHR_materials_volume]. +- **Transmission**: Equivalent to `transmissionFactor` and `transmissionTexture` + of [KHR_materials_transmission]. +- **Refractive Index**: Equivalent to `ior` of [KHR_materials_ior] +- **Thickness**: Equivalent to `thicknessFactor` and `thicknessTexture` of + [KHR_materials_volume]. +- **Dispersion**: 20 / Abbe Number. Equivalent to `dispersion` of + [KHR_materials_dispersion]. + +[KHR_materials_transmission]: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_transmission +[KHR_materials_ior]: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_ior +[KHR_materials_volume]: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_volume +[KHR_materials_dispersion]: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_dispersion ## LightPart | Key | Value Type | | -------- | ---------- | -| radius | f32 | +| radius | Float | | emission | Vec3 | ## EnvironmentPart diff --git a/shared/src/resources.rs b/shared/src/resources.rs index 628fa1e..08fb6f5 100644 --- a/shared/src/resources.rs +++ b/shared/src/resources.rs @@ -51,6 +51,10 @@ pub struct MeshPart { pub g_transmission: Option, pub g_alpha: Option, pub g_emission: Option, + pub g_thickness: Option, + pub g_refractive_index: Option, + pub g_attenuation: Option, + pub g_dispersion: Option, pub va_position: Option<[Resource; 3]>, pub va_normal: Option<[Resource; 3]>, pub va_texcoord: Option<[Resource; 2]>, @@ -67,6 +71,7 @@ pub struct MeshPart { pub tex_transmission: Option>, pub tex_alpha: Option>, pub tex_emission: Option>, + pub tex_thickness: Option>, } #[derive(Debug, Default, Clone)] diff --git a/world/Cargo.toml b/world/Cargo.toml index 11272ed..51437d5 100644 --- a/world/Cargo.toml +++ b/world/Cargo.toml @@ -12,6 +12,9 @@ gltf = { version = "1.4.1", features = [ "names", "KHR_lights_punctual", "KHR_materials_transmission", + "KHR_materials_ior", + "KHR_materials_volume", + "KHR_materials_emissive_strength", ] } log = "0.4.22" weareshared = { path = "../shared" } diff --git a/world/src/mesh.rs b/world/src/mesh.rs index 3190c28..216f8f3 100644 --- a/world/src/mesh.rs +++ b/world/src/mesh.rs @@ -283,10 +283,17 @@ pub fn import_mesh( tex_emission, tex_transmission, index, + // not yet implemented + g_attenuation: None, + g_dispersion: None, + g_refractive_index: None, + g_thickness: None, + tex_thickness: None, + // not supported by gltf va_transmission: None, - va_emission: None, // not supported by gltf - va_metallic: None, // not supported by gltf - va_roughness: None, // not supported by gltf + va_emission: None, + va_metallic: None, + va_roughness: None, })?; let mat = node.transform().matrix(); let aff = Affine3A::from_cols_array_2d(&[ -- cgit v1.2.3-70-g09d2