fix calls to as_rgba_linear (#3200)
# Objective - After #3192, some places where `as_rgba_linear` was called were doing too many conversions ## Solution - Fix the conversions
This commit is contained in:
parent
e8412df021
commit
3de391be21
@ -90,7 +90,7 @@ impl RenderAsset for CustomMaterial {
|
|||||||
extracted_asset: Self::ExtractedAsset,
|
extracted_asset: Self::ExtractedAsset,
|
||||||
(render_device, custom_pipeline): &mut SystemParamItem<Self::Param>,
|
(render_device, custom_pipeline): &mut SystemParamItem<Self::Param>,
|
||||||
) -> Result<Self::PreparedAsset, PrepareAssetError<Self::ExtractedAsset>> {
|
) -> Result<Self::PreparedAsset, PrepareAssetError<Self::ExtractedAsset>> {
|
||||||
let color: Vec4 = extracted_asset.color.as_rgba_linear().into();
|
let color = Vec4::from_slice(&extracted_asset.color.as_linear_rgba_f32());
|
||||||
let buffer = render_device.create_buffer_with_data(&BufferInitDescriptor {
|
let buffer = render_device.create_buffer_with_data(&BufferInitDescriptor {
|
||||||
contents: color.as_std140().as_bytes(),
|
contents: color.as_std140().as_bytes(),
|
||||||
label: None,
|
label: None,
|
||||||
|
@ -238,7 +238,7 @@ impl RenderAsset for StandardMaterial {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let value = StandardMaterialUniformData {
|
let value = StandardMaterialUniformData {
|
||||||
base_color: material.base_color.as_rgba_linear().into(),
|
base_color: material.base_color.as_linear_rgba_f32().into(),
|
||||||
emissive: material.emissive.into(),
|
emissive: material.emissive.into(),
|
||||||
roughness: material.perceptual_roughness,
|
roughness: material.perceptual_roughness,
|
||||||
metallic: material.metallic,
|
metallic: material.metallic,
|
||||||
|
@ -509,7 +509,6 @@ pub fn prepare_lights(
|
|||||||
) {
|
) {
|
||||||
light_meta.view_gpu_lights.clear();
|
light_meta.view_gpu_lights.clear();
|
||||||
|
|
||||||
let ambient_color = ambient_light.color.as_rgba_linear() * ambient_light.brightness;
|
|
||||||
// Pre-calculate for PointLights
|
// Pre-calculate for PointLights
|
||||||
let cube_face_projection =
|
let cube_face_projection =
|
||||||
Mat4::perspective_infinite_reverse_rh(std::f32::consts::FRAC_PI_2, 1.0, 0.1);
|
Mat4::perspective_infinite_reverse_rh(std::f32::consts::FRAC_PI_2, 1.0, 0.1);
|
||||||
@ -555,7 +554,8 @@ pub fn prepare_lights(
|
|||||||
let mut view_lights = Vec::new();
|
let mut view_lights = Vec::new();
|
||||||
|
|
||||||
let mut gpu_lights = GpuLights {
|
let mut gpu_lights = GpuLights {
|
||||||
ambient_color: ambient_color.into(),
|
ambient_color: Vec4::from_slice(&ambient_light.color.as_linear_rgba_f32())
|
||||||
|
* ambient_light.brightness,
|
||||||
n_point_lights: point_lights.iter().len() as u32,
|
n_point_lights: point_lights.iter().len() as u32,
|
||||||
n_directional_lights: directional_lights.iter().len() as u32,
|
n_directional_lights: directional_lights.iter().len() as u32,
|
||||||
point_lights: [GpuPointLight::default(); MAX_POINT_LIGHTS],
|
point_lights: [GpuPointLight::default(); MAX_POINT_LIGHTS],
|
||||||
@ -622,7 +622,7 @@ pub fn prepare_lights(
|
|||||||
projection: cube_face_projection,
|
projection: cube_face_projection,
|
||||||
// premultiply color by intensity
|
// premultiply color by intensity
|
||||||
// we don't use the alpha at all, so no reason to multiply only [0..3]
|
// we don't use the alpha at all, so no reason to multiply only [0..3]
|
||||||
color: (light.color.as_rgba_linear() * light.intensity).into(),
|
color: Vec4::from_slice(&light.color.as_linear_rgba_f32()) * light.intensity,
|
||||||
radius: light.radius,
|
radius: light.radius,
|
||||||
position: light.transform.translation,
|
position: light.transform.translation,
|
||||||
inverse_square_range: 1.0 / (light.range * light.range),
|
inverse_square_range: 1.0 / (light.range * light.range),
|
||||||
@ -669,7 +669,7 @@ pub fn prepare_lights(
|
|||||||
gpu_lights.directional_lights[i] = GpuDirectionalLight {
|
gpu_lights.directional_lights[i] = GpuDirectionalLight {
|
||||||
// premultiply color by intensity
|
// premultiply color by intensity
|
||||||
// we don't use the alpha at all, so no reason to multiply only [0..3]
|
// we don't use the alpha at all, so no reason to multiply only [0..3]
|
||||||
color: (light.color.as_rgba_linear() * intensity).into(),
|
color: Vec4::from_slice(&light.color.as_linear_rgba_f32()) * intensity,
|
||||||
dir_to_light,
|
dir_to_light,
|
||||||
// NOTE: * view is correct, it should not be view.inverse() here
|
// NOTE: * view is correct, it should not be view.inverse() here
|
||||||
view_projection: projection * view,
|
view_projection: projection * view,
|
||||||
|
@ -633,12 +633,21 @@ impl From<Vec4> for Color {
|
|||||||
|
|
||||||
impl From<Color> for wgpu::Color {
|
impl From<Color> for wgpu::Color {
|
||||||
fn from(color: Color) -> Self {
|
fn from(color: Color) -> Self {
|
||||||
let color = color.as_rgba_linear();
|
if let Color::RgbaLinear {
|
||||||
wgpu::Color {
|
red,
|
||||||
r: color.r() as f64,
|
green,
|
||||||
g: color.g() as f64,
|
blue,
|
||||||
b: color.b() as f64,
|
alpha,
|
||||||
a: color.a() as f64,
|
} = color.as_rgba_linear()
|
||||||
|
{
|
||||||
|
wgpu::Color {
|
||||||
|
r: red as f64,
|
||||||
|
g: green as f64,
|
||||||
|
b: blue as f64,
|
||||||
|
a: alpha as f64,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
unreachable!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user