renderer/metal,opengl: premult alpha for fragment shaders for images

Fixes #1346
This commit is contained in:
Mitchell Hashimoto
2024-01-21 14:07:16 -08:00
parent 628b54fbb5
commit 5622ab370f
2 changed files with 8 additions and 2 deletions

View File

@ -328,7 +328,12 @@ fragment float4 image_fragment(
// BGRA8Unorm. So we need to convert it. We should really be converting
// our texture to BGRA8Unorm.
uint4 rgba = image.sample(textureSampler, in.tex_coord);
return float4(rgba) / 255.0f;
// Convert to float4 and premultiply the alpha. We should also probably
// premultiply the alpha in the texture.
float4 result = float4(rgba) / 255.0f;
result.rgb *= result.a;
return result;
}
//-------------------------------------------------------------------

View File

@ -7,5 +7,6 @@ layout(location = 0) out vec4 out_FragColor;
uniform sampler2D image;
void main() {
out_FragColor = texture(image, tex_coord);
vec4 color = texture(image, tex_coord);
out_FragColor = vec4(color.rgb * color.a, color.a);
}