fix(Metal): use sRGB texture format for gamma correct interpolation

otherwise images will be too dark when scaled
This commit is contained in:
Qwerasd
2025-05-15 12:06:30 -06:00
parent 1d0cb1a9b0
commit e2f3b6211f
3 changed files with 9 additions and 8 deletions

View File

@@ -96,6 +96,7 @@ pub const MTLVertexStepFunction = enum(c_ulong) {
pub const MTLPixelFormat = enum(c_ulong) {
r8unorm = 10,
rgba8unorm = 70,
rgba8unorm_srgb = 71,
rgba8uint = 73,
bgra8unorm = 80,
bgra8unorm_srgb = 81,

View File

@@ -441,7 +441,7 @@ pub const Image = union(enum) {
};
// Set our properties
desc.setProperty("pixelFormat", @intFromEnum(mtl.MTLPixelFormat.rgba8unorm));
desc.setProperty("pixelFormat", @intFromEnum(mtl.MTLPixelFormat.rgba8unorm_srgb));
desc.setProperty("width", @as(c_ulong, @intCast(p.width)));
desc.setProperty("height", @as(c_ulong, @intCast(p.height)));

View File

@@ -668,12 +668,12 @@ fragment float4 image_fragment(
float4 rgba = image.sample(textureSampler, in.tex_coord);
return load_color(
uchar4(rgba * 255.0),
// We assume all images are sRGB regardless of the configured colorspace
// TODO: Maybe support wide gamut images?
false,
uniforms.use_linear_blending
);
if (!uniforms.use_linear_blending) {
rgba = unlinearize(rgba);
}
rgba.rgb *= rgba.a;
return rgba;
}