store color in linear

This commit is contained in:
2025-09-20 13:34:04 -04:00
parent e35e72402f
commit 3653f24e06
3 changed files with 25 additions and 22 deletions

View File

@@ -106,7 +106,7 @@ fn draw_texture(region: Region, info: TextureInfo) -> vec4<f32> {
}
fn draw_rounded_rect(region: Region, rect: Rect) -> vec4<f32> {
var color = read_color(rect.color);
var color = unpack4x8unorm(rect.color);
let edge = 0.5;
@@ -133,20 +133,3 @@ fn distance_from_rect(pixel_pos: vec2<f32>, rect_center: vec2<f32>, rect_corner:
return length(max(q, vec2(0.0))) - radius;
}
fn read_color(c: u32) -> vec4<f32> {
let color = unpack4x8unorm(c);
return vec4(
srgb_to_linear(color.r),
srgb_to_linear(color.g),
srgb_to_linear(color.b),
color.a,
);
}
fn srgb_to_linear(c: f32) -> f32 {
if c <= 0.04045 {
return c / 12.92;
} else {
return pow((c + 0.055) / 1.055, 2.4);
}
}