diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index 5687675422ee5..bfdec7aaacdc8 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -995,8 +995,7 @@ fn load_material( // We need to operate in the Linear color space and be willing to exceed 1.0 in our channels let base_emissive = LinearRgba::rgb(emissive[0], emissive[1], emissive[2]); - let scaled_emissive = base_emissive * material.emissive_strength().unwrap_or(1.0); - let emissive = Color::from(scaled_emissive); + let emissive = base_emissive * material.emissive_strength().unwrap_or(1.0); StandardMaterial { base_color: Color::linear_rgba(color[0], color[1], color[2], color[3]), diff --git a/crates/bevy_pbr/src/pbr_material.rs b/crates/bevy_pbr/src/pbr_material.rs index 91cb1d21a207e..9ceefa0b59d78 100644 --- a/crates/bevy_pbr/src/pbr_material.rs +++ b/crates/bevy_pbr/src/pbr_material.rs @@ -1,5 +1,5 @@ use bevy_asset::Asset; -use bevy_color::Alpha; +use bevy_color::{Alpha, ColorToComponents}; use bevy_math::{Affine2, Affine3, Mat2, Mat3, Vec2, Vec3, Vec4}; use bevy_reflect::{std_traits::ReflectDefault, Reflect}; use bevy_render::{ @@ -75,20 +75,20 @@ pub struct StandardMaterial { /// This means that for a light emissive value, in darkness, /// you will mostly see the emissive component. /// - /// The default emissive color is [`Color::BLACK`], which doesn't add anything to the material color. + /// The default emissive color is [`LinearRgba::BLACK`], which doesn't add anything to the material color. /// /// To increase emissive strength, channel values for `emissive` /// colors can exceed `1.0`. For instance, a `base_color` of - /// `Color::linear_rgb(1.0, 0.0, 0.0)` represents the brightest + /// `LinearRgba::rgb(1.0, 0.0, 0.0)` represents the brightest /// red for objects that reflect light, but an emissive color - /// like `Color::linear_rgb(1000.0, 0.0, 0.0)` can be used to create + /// like `LinearRgba::rgb(1000.0, 0.0, 0.0)` can be used to create /// intensely bright red emissive effects. /// /// Increasing the emissive strength of the color will impact visual effects /// like bloom, but it's important to note that **an emissive material won't /// light up surrounding areas like a light source**, /// it just adds a value to the color seen on screen. - pub emissive: Color, + pub emissive: LinearRgba, /// The weight in which the camera exposure influences the emissive color. /// A value of `0.0` means the emissive color is not affected by the camera exposure. @@ -689,7 +689,7 @@ impl Default for StandardMaterial { base_color: Color::WHITE, base_color_channel: UvChannel::Uv0, base_color_texture: None, - emissive: Color::BLACK, + emissive: LinearRgba::BLACK, emissive_exposure_weight: 0.0, emissive_channel: UvChannel::Uv0, emissive_texture: None, @@ -972,12 +972,12 @@ impl AsBindGroupShaderType for StandardMaterial { flags |= StandardMaterialFlags::ATTENUATION_ENABLED; } - let mut emissive = LinearRgba::from(self.emissive).to_f32_array(); + let mut emissive = self.emissive.to_vec4(); emissive[3] = self.emissive_exposure_weight; StandardMaterialUniform { - base_color: LinearRgba::from(self.base_color).to_f32_array().into(), - emissive: emissive.into(), + base_color: LinearRgba::from(self.base_color).to_vec4(), + emissive: self.emissive.to_vec4(), roughness: self.perceptual_roughness, metallic: self.metallic, reflectance: self.reflectance, diff --git a/examples/3d/3d_scene.rs b/examples/3d/3d_scene.rs index 9b57373ec7936..df3b226732577 100644 --- a/examples/3d/3d_scene.rs +++ b/examples/3d/3d_scene.rs @@ -18,14 +18,20 @@ fn setup( // circular base commands.spawn(PbrBundle { mesh: meshes.add(Circle::new(4.0)), - material: materials.add(Color::WHITE), + material: materials.add(StandardMaterial { + base_color: Color::WHITE, + ..Default::default() + }), transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)), ..default() }); // cube commands.spawn(PbrBundle { mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)), - material: materials.add(Color::srgb_u8(124, 144, 255)), + material: materials.add(StandardMaterial { + base_color: Srgba::rgb_u8(124, 144, 255).into(), + ..Default::default() + }), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }); diff --git a/examples/3d/3d_viewport_to_world.rs b/examples/3d/3d_viewport_to_world.rs index 9e4e4f73da3ed..12e12c475f4c0 100644 --- a/examples/3d/3d_viewport_to_world.rs +++ b/examples/3d/3d_viewport_to_world.rs @@ -52,7 +52,10 @@ fn setup( commands.spawn(( PbrBundle { mesh: meshes.add(Plane3d::default().mesh().size(20., 20.)), - material: materials.add(Color::srgb(0.3, 0.5, 0.3)), + material: materials.add(StandardMaterial { + base_color: LinearRgba::rgb(0.3, 0.5, 0.3).into(), + ..default() + }), ..default() }, Ground, diff --git a/examples/3d/anti_aliasing.rs b/examples/3d/anti_aliasing.rs index fc698733e3eb8..107c3e4f31f17 100644 --- a/examples/3d/anti_aliasing.rs +++ b/examples/3d/anti_aliasing.rs @@ -261,7 +261,10 @@ fn setup( // Plane commands.spawn(PbrBundle { mesh: meshes.add(Plane3d::default().mesh().size(50.0, 50.0)), - material: materials.add(Color::srgb(0.1, 0.2, 0.1)), + material: materials.add(StandardMaterial { + base_color: LinearRgba::rgb(0.1, 0.2, 0.1).into(), + ..Default::default() + }), ..default() }); diff --git a/examples/3d/bloom_3d.rs b/examples/3d/bloom_3d.rs index 36d178491be62..c39f575616395 100644 --- a/examples/3d/bloom_3d.rs +++ b/examples/3d/bloom_3d.rs @@ -41,15 +41,15 @@ fn setup_scene( )); let material_emissive1 = materials.add(StandardMaterial { - emissive: Color::linear_rgb(13.99, 5.32, 2.0), // 4. Put something bright in a dark environment to see the effect + emissive: LinearRgba::rgb(13.99, 5.32, 2.0), // 4. Put something bright in a dark environment to see the effect ..default() }); let material_emissive2 = materials.add(StandardMaterial { - emissive: Color::linear_rgb(2.0, 13.99, 5.32), + emissive: LinearRgba::rgb(2.0, 13.99, 5.32), ..default() }); let material_emissive3 = materials.add(StandardMaterial { - emissive: Color::linear_rgb(5.32, 2.0, 13.99), + emissive: LinearRgba::rgb(5.32, 2.0, 13.99), ..default() }); let material_non_emissive = materials.add(StandardMaterial { diff --git a/examples/3d/lighting.rs b/examples/3d/lighting.rs index db8a728102c3a..ff0abb5319fae 100644 --- a/examples/3d/lighting.rs +++ b/examples/3d/lighting.rs @@ -146,7 +146,7 @@ fn setup( mesh: meshes.add(Sphere::new(0.1).mesh().uv(32, 18)), material: materials.add(StandardMaterial { base_color: RED.into(), - emissive: Color::linear_rgba(4.0, 0.0, 0.0, 0.0), + emissive: LinearRgba::new(4.0, 0.0, 0.0, 0.0), ..default() }), ..default() @@ -174,7 +174,7 @@ fn setup( mesh: meshes.add(Capsule3d::new(0.1, 0.125)), material: materials.add(StandardMaterial { base_color: LIME.into(), - emissive: Color::linear_rgba(0.0, 4.0, 0.0, 0.0), + emissive: LinearRgba::new(0.0, 4.0, 0.0, 0.0), ..default() }), ..default() @@ -199,7 +199,7 @@ fn setup( mesh: meshes.add(Sphere::new(0.1).mesh().uv(32, 18)), material: materials.add(StandardMaterial { base_color: BLUE.into(), - emissive: Color::linear_rgba(0.0, 0.0, 713.0, 0.0), + emissive: LinearRgba::new(0.0, 0.0, 713.0, 0.0), ..default() }), ..default() diff --git a/examples/3d/spotlight.rs b/examples/3d/spotlight.rs index b05fc9ff2f566..c5cba47894ad7 100644 --- a/examples/3d/spotlight.rs +++ b/examples/3d/spotlight.rs @@ -79,12 +79,12 @@ fn setup( let sphere_mesh_direction = meshes.add(Sphere::new(0.1).mesh().uv(32, 18)); let red_emissive = materials.add(StandardMaterial { base_color: RED.into(), - emissive: Color::linear_rgba(1.0, 0.0, 0.0, 0.0), + emissive: LinearRgba::new(1.0, 0.0, 0.0, 0.0), ..default() }); let maroon_emissive = materials.add(StandardMaterial { base_color: MAROON.into(), - emissive: Color::linear_rgba(0.369, 0.0, 0.0, 0.0), + emissive: LinearRgba::new(0.369, 0.0, 0.0, 0.0), ..default() }); diff --git a/examples/3d/transmission.rs b/examples/3d/transmission.rs index 0fea6d0cf200d..c0a8768e45c49 100644 --- a/examples/3d/transmission.rs +++ b/examples/3d/transmission.rs @@ -144,8 +144,7 @@ fn setup( green: scaled_white.green + scaled_orange.green, blue: scaled_white.blue + scaled_orange.blue, alpha: 1.0, - } - .into(); + }; commands.spawn(( PbrBundle { diff --git a/examples/ecs/iter_combinations.rs b/examples/ecs/iter_combinations.rs index cb946bfc79a64..0e18b06e9db1c 100644 --- a/examples/ecs/iter_combinations.rs +++ b/examples/ecs/iter_combinations.rs @@ -99,7 +99,7 @@ fn generate_bodies( mesh: meshes.add(Sphere::new(1.0).mesh().ico(5).unwrap()), material: materials.add(StandardMaterial { base_color: ORANGE_RED.into(), - emissive: (LinearRgba::from(ORANGE_RED) * 2.).into(), + emissive: LinearRgba::from(ORANGE_RED) * 2., ..default() }), ..default()