Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/bevy_camera/src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ pub enum CompositingSpace {
/// Gamma-encoded blending. Matches most image editors. Uses default sRGB target.
#[default]
Srgb,
/// Linear light blending. Physically correct. Requires [`Hdr`].
/// Linear light blending. Physically correct.
Linear,
/// Perceptually uniform blending. Often smoother gradients. Requires [`Hdr`].
/// Perceptually uniform blending. Often smoother gradients. Requires [`Hdr`] because its value can be outside [0, 1].
Oklab,
}
12 changes: 12 additions & 0 deletions crates/bevy_color/src/srgba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,18 @@ impl From<Srgba> for Xyza {
}
}

#[cfg(feature = "wgpu-types")]
impl From<Srgba> for wgpu_types::Color {
fn from(color: Srgba) -> Self {
wgpu_types::Color {
r: color.red as f64,
g: color.green as f64,
b: color.blue as f64,
a: color.alpha as f64,
}
}
}

/// Error returned if a hex string could not be parsed as a color.
#[derive(Debug, Error, PartialEq, Eq)]
pub enum HexColorError {
Expand Down
22 changes: 8 additions & 14 deletions crates/bevy_render/src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::{
};
use alloc::sync::{Arc, Weak};
use bevy_app::{App, Plugin};
use bevy_color::{LinearRgba, Oklaba};
use bevy_color::{LinearRgba, Oklaba, Srgba};
use bevy_derive::{Deref, DerefMut};
use bevy_ecs::prelude::*;
use bevy_image::ToExtents;
Expand Down Expand Up @@ -1177,19 +1177,13 @@ pub fn prepare_view_targets(
};

// Convert clear color to the format expected by the main texture
let converted_clear_color: Option<WgpuColor> = clear_color.map(|color| {
let linear: LinearRgba = color.into();
if camera
.compositing_space
.is_some_and(|s| s == CompositingSpace::Oklab)
{
// Main texture stores Oklab; convert linear RGB to Oklab for correct clear
let oklab: Oklaba = linear.into();
oklab.into()
} else {
linear.into()
}
});
let converted_clear_color: Option<WgpuColor> =
clear_color.map(|color| match camera.compositing_space {
// If main texture stores Oklab or Srgb, convert Color to it for correct clear.
Some(CompositingSpace::Oklab) => Oklaba::from(color).into(),
Some(CompositingSpace::Srgb) => Srgba::from(color).into(),
_ => LinearRgba::from(color).into(),
Comment thread
beicause marked this conversation as resolved.
Outdated
});

let key: MainTextureKey = (
camera.target.clone(),
Expand Down