Open yjh0502 opened 1 year ago
Some errors could be fixed by un-premultiplying colors from egui
.
diff --git a/src/painter.rs b/src/painter.rs
index 5c07f5b..8696332 100644
--- a/src/painter.rs
+++ b/src/painter.rs
@@ -205,11 +205,19 @@ impl Painter {
pos.push(Point::new(fixed_pos.x, fixed_pos.y));
texs.push(Point::new(v.uv.x, v.uv.y));
+
+ let c = v.color;
+ let c = Color::from_argb(c.a(), c.r(), c.g(), c.b());
+ // un-premultply color
+ let mut cf = skia_safe::Color4f::from(c);
+ cf.r /= cf.a;
+ cf.g /= cf.a;
+ cf.b /= cf.a;
colors.push(Color::from_argb(
- v.color.a(),
- v.color.r(),
- v.color.g(),
- v.color.b(),
+ c.a(),
+ (cf.r * 255.0) as u8,
+ (cf.g * 255.0) as u8,
+ (cf.b * 255.0) as u8,
));
});
Hi! I applied your fix in #7, improving on the color test results. But as you already mentioned it's not perfect yet so I'll leave this issue open for now. I also tested if I could get this to work by changing the type of the created skia texture but it didn't seem to make any difference. Happy to accept a PR if someone figures out how to fix the additive blending and linear interpolation test cases!
The colors on rendered images are all messed up (weird pink tinge), I wonder if this is related?
I tried rendering a gradient texture and when I sample the color with a color picker, the red and the blue components appear to be swapped. I fixed it with this:
let scol = [0x1E, 0x55, 0xFF];
let ecol = [0xFA, 0x0D, 0xD4];
// TODO: skia has r/b colors swapped for some reason, fix this
let start_color = Color32::from_rgb(scol[2], scol[1], scol[0]);
let end_color = Color32::from_rgb(ecol[2], ecol[1], ecol[0]);
let gradient = Gradient::linear(start_color, end_color);
before: https://cdn.jb55.com/s/0cdefad30a081797.png after swapping r/b: https://cdn.jb55.com/s/2da42af5f9f69756.png
While tracking down rendering errors, I found that color rendering is broken with cpu rendering (
cpu_fix
). Here's a code snippet to render ColorTest.This is cpu-rendered image, generate from a code above, which shows errors.
Here's a side-by-side screenshot, comparing cpu-rendered with webgl one (from https://egui.rs)