metal: premult alpha for fg color

This commit is contained in:
Mitchell Hashimoto
2023-02-24 08:39:55 -08:00
parent 35cb9d20b1
commit 60b2603304
2 changed files with 5 additions and 3 deletions

View File

@ -1299,8 +1299,8 @@ fn initPipelineState(device: objc.Object, library: objc.Object) !objc.Object {
attachment.setProperty("blendingEnabled", true);
attachment.setProperty("rgbBlendOperation", @enumToInt(MTLBlendOperation.add));
attachment.setProperty("alphaBlendOperation", @enumToInt(MTLBlendOperation.add));
attachment.setProperty("sourceRGBBlendFactor", @enumToInt(MTLBlendFactor.source_alpha));
attachment.setProperty("sourceAlphaBlendFactor", @enumToInt(MTLBlendFactor.source_alpha));
attachment.setProperty("sourceRGBBlendFactor", @enumToInt(MTLBlendFactor.one));
attachment.setProperty("sourceAlphaBlendFactor", @enumToInt(MTLBlendFactor.one));
attachment.setProperty("destinationRGBBlendFactor", @enumToInt(MTLBlendFactor.one_minus_source_alpha));
attachment.setProperty("destinationAlphaBlendFactor", @enumToInt(MTLBlendFactor.one_minus_source_alpha));
}

View File

@ -188,8 +188,10 @@ fragment float4 uber_fragment(
float2 size = float2(textureGreyscale.get_width(), textureGreyscale.get_height());
float2 coord = in.tex_coord / size;
// We premult the alpha to our whole color since our blend function
// uses One/OneMinusSourceAlpha to avoid blurry edges.
float a = textureGreyscale.sample(textureSampler, coord).r;
return float4(in.color.rgb, in.color.a * a);
return in.color * a;
}
case MODE_FG_COLOR: {