From 228e7aa6184539acfcbaff5f7957bc4361ac3453 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Wed, 23 Aug 2023 17:17:44 -0700 Subject: [PATCH] Add support for KHR_materials_emissive_strength (#9553) # Objective - Fix blender gltf imports with emissive materials - Progress towards https://github.com/bevyengine/bevy/issues/5178 ## Solution - Upgrade to gltf-rs 1.3 supporiting [KHR_materials_emissive_strength](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_emissive_strength/README.md) --- ## Changelog - GLTF files using `emissiveStrength` (such as those exported by blender) are now supported ## Migration Guide - The GLTF asset loader will now factor in `emissiveStrength` when converting to Bevy's `StandardMaterial::emissive`. Blender will export emissive materials using this field. Remove the field from your GLTF files or manually modify your materials post-asset-load to match how Bevy would load these files in previous versions. --- crates/bevy_gltf/Cargo.toml | 3 ++- crates/bevy_gltf/src/loader.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/bevy_gltf/Cargo.toml b/crates/bevy_gltf/Cargo.toml index 80291f06e22ac..9a86255e7521e 100644 --- a/crates/bevy_gltf/Cargo.toml +++ b/crates/bevy_gltf/Cargo.toml @@ -28,9 +28,10 @@ bevy_tasks = { path = "../bevy_tasks", version = "0.12.0-dev" } bevy_utils = { path = "../bevy_utils", version = "0.12.0-dev" } # other -gltf = { version = "1.0.0", default-features = false, features = [ +gltf = { version = "1.3.0", default-features = false, features = [ "KHR_lights_punctual", "KHR_materials_unlit", + "KHR_materials_emissive_strength", "extras", "names", "utils", diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index cdce72b1d9985..7b737fec0ed74 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -678,7 +678,8 @@ fn load_material(material: &Material, load_context: &mut LoadContext) -> Handle< Some(Face::Back) }, occlusion_texture, - emissive: Color::rgb_linear(emissive[0], emissive[1], emissive[2]), + emissive: Color::rgb_linear(emissive[0], emissive[1], emissive[2]) + * material.emissive_strength().unwrap_or(1.0), emissive_texture, unlit: material.unlit(), alpha_mode: alpha_mode(material),