fix linear-sRGB color mismatch
This commit is contained in:
parent
02707dd095
commit
7b4ff19784
34
src/lib.rs
34
src/lib.rs
|
|
@ -18,7 +18,7 @@ pub struct RedrawArgs {
|
|||
impl Default for RedrawArgs {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
background: vec4(0.05, 0.20, 0.85, 1.00),
|
||||
background: vec4(0.25, 0.49, 0.93, 1.00),
|
||||
cam_yaw: std::f32::consts::FRAC_PI_4,
|
||||
cam_pitch: std::f32::consts::FRAC_PI_6,
|
||||
cam_distance: 3.,
|
||||
|
|
@ -71,6 +71,31 @@ fn cube(a: f32, b: f32) -> render::mesh::CpuMeshIndexed {
|
|||
mesh
|
||||
}
|
||||
|
||||
fn srgb_to_linear(color: Vec3) -> Vec3 {
|
||||
color.map(|x| {
|
||||
if x > 0.04045 {
|
||||
((x + 0.055) / 1.055).powf(2.4)
|
||||
} else {
|
||||
x / 12.92
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn srgba_to_linear(color: Vec4) -> Vec4 {
|
||||
let alpha = color.w;
|
||||
let color = srgb_to_linear(vec3(color.x, color.y, color.z));
|
||||
vec4(color.x, color.y, color.z, alpha)
|
||||
}
|
||||
|
||||
fn color_to_wgpu(color: Vec4) -> wgpu::Color {
|
||||
wgpu::Color {
|
||||
r: color.x.into(),
|
||||
g: color.y.into(),
|
||||
b: color.z.into(),
|
||||
a: color.w.into(),
|
||||
}
|
||||
}
|
||||
|
||||
impl Core {
|
||||
pub fn new(gpu: Gpu, pixel_size: UVec2) -> Self {
|
||||
let Gpu {
|
||||
|
|
@ -133,12 +158,7 @@ impl Core {
|
|||
depth_slice: None,
|
||||
resolve_target: None,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(wgpu::Color {
|
||||
r: args.background.x.into(),
|
||||
g: args.background.y.into(),
|
||||
b: args.background.z.into(),
|
||||
a: args.background.w.into(),
|
||||
}),
|
||||
load: wgpu::LoadOp::Clear(color_to_wgpu(srgba_to_linear(args.background))),
|
||||
store: wgpu::StoreOp::Store,
|
||||
},
|
||||
})],
|
||||
|
|
|
|||
|
|
@ -168,8 +168,8 @@
|
|||
<property name="color">
|
||||
<color>
|
||||
<red>0</red>
|
||||
<green>32</green>
|
||||
<blue>60</blue>
|
||||
<green>99</green>
|
||||
<blue>133</blue>
|
||||
</color>
|
||||
</property>
|
||||
</widget>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user