[Impeller] Correct advanced blending behavior. (flutter/engine#43283)
Investigated as part of https://github.com/flutter/flutter/issues/127232. This took some time to work out, but: * The amount of blending applied to the source color needs to be weighted by the destination alpha, which is pretty sensible behavior. This is in addition to applying source-over behavior with the resulting blended color. * All of the blend functions assume that the color is already premultiplied, so remove the unpremultiply/premultiply surrounding the blend call. All of the blend modes now visually match up with the [Flutter docs](https://api.flutter.dev/flutter/dart-ui/BlendMode.html), except for ColorBurn and Saturation, which appear to have a slight miscalculation going on with the red channel.
This commit is contained in:
@@ -38,16 +38,14 @@ void main() {
|
||||
) *
|
||||
blend_info.dst_input_alpha;
|
||||
|
||||
f16vec4 dst = IPHalfUnpremultiply(dst_sample);
|
||||
f16vec4 dst = dst_sample;
|
||||
f16vec4 src = blend_info.color_factor > 0.0hf
|
||||
? blend_info.color
|
||||
: IPHalfUnpremultiply(
|
||||
Sample(texture_sampler_src, // sampler
|
||||
v_src_texture_coords // texture coordinates
|
||||
) *
|
||||
blend_info.src_input_alpha);
|
||||
|
||||
f16vec4 blended = f16vec4(Blend(dst.rgb, src.rgb), 1.0hf) * dst.a;
|
||||
: Sample(texture_sampler_src, // sampler
|
||||
v_src_texture_coords // texture coordinates
|
||||
) *
|
||||
blend_info.src_input_alpha;
|
||||
|
||||
f16vec4 blended = mix(src, f16vec4(Blend(dst.rgb, src.rgb), dst.a), dst.a);
|
||||
frag_color = mix(dst_sample, blended, src.a);
|
||||
}
|
||||
|
||||
@@ -37,14 +37,12 @@ out vec4 frag_color;
|
||||
|
||||
void main() {
|
||||
f16vec4 dst_sample = f16vec4(ReadDestination());
|
||||
f16vec4 dst = IPHalfUnpremultiply(dst_sample);
|
||||
f16vec4 src = IPHalfUnpremultiply(
|
||||
f16vec4(texture(texture_sampler_src, // sampler
|
||||
v_src_texture_coords // texture coordinates
|
||||
)) *
|
||||
frag_info.src_input_alpha);
|
||||
f16vec4 dst = dst_sample;
|
||||
f16vec4 src = f16vec4(texture(texture_sampler_src, // sampler
|
||||
v_src_texture_coords // texture coordinates
|
||||
)) *
|
||||
frag_info.src_input_alpha;
|
||||
|
||||
f16vec4 blended = f16vec4(Blend(dst.rgb, src.rgb), 1.0hf) * dst.a;
|
||||
|
||||
frag_color = vec4(mix(dst_sample, blended, src.a));
|
||||
f16vec4 blended = mix(src, f16vec4(Blend(dst.rgb, src.rgb), dst.a), dst.a);
|
||||
frag_color = vec4(mix(dst, blended, src.a));
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user