mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Emissive is now LinearRgba on StandardMaterial (#13352)
StandardMaterial stores a LinearRgba instead of a Color for emissive Fixes #13212
This commit is contained in:
parent
ec01c2dc45
commit
44c0325ecd
10 changed files with 36 additions and 26 deletions
|
@ -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]),
|
||||
|
|
|
@ -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<StandardMaterialUniform> 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,
|
||||
|
|
|
@ -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()
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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()
|
||||
});
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
});
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue