[Impeller] Do SourceOver alpha compositing for advanced blends; write results to the pass with kSource (flutter/engine#36658)

This commit is contained in:
Brandon DeRosier 2022-10-07 20:47:11 -07:00 committed by GitHub
parent 28ba2f96a9
commit 6d2aa4806d
3 changed files with 15 additions and 11 deletions

View File

@ -93,7 +93,8 @@ static std::optional<Snapshot> AdvancedBlend(
});
auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);
auto options = OptionsFromPassAndEntity(pass, entity);
auto options = OptionsFromPass(pass);
options.blend_mode = BlendMode::kSource;
std::shared_ptr<Pipeline<PipelineDescriptor>> pipeline =
std::invoke(pipeline_proc, renderer, options);

View File

@ -205,7 +205,7 @@ bool EntityPass::Render(ContentContext& renderer,
Entity entity;
entity.SetContents(contents);
entity.SetBlendMode(BlendMode::kSourceOver);
entity.SetBlendMode(BlendMode::kSource);
entity.Render(renderer, *render_pass);
}
@ -535,7 +535,7 @@ bool EntityPass::OnRender(
FilterContents::MakeBlend(result.entity.GetBlendMode(), inputs);
contents->SetCoverageCrop(result.entity.GetCoverage());
result.entity.SetContents(std::move(contents));
result.entity.SetBlendMode(BlendMode::kSourceOver);
result.entity.SetBlendMode(BlendMode::kSource);
}
//--------------------------------------------------------------------------

View File

@ -23,12 +23,14 @@ in vec2 v_src_texture_coords;
out vec4 frag_color;
void main() {
vec4 dst = IPUnpremultiply(IPSampleWithTileMode(
texture_sampler_dst, // sampler
v_dst_texture_coords, // texture coordinates
blend_info.dst_y_coord_scale, // y coordinate scale
kTileModeDecal // tile mode
));
vec4 dst_sample =
IPSampleWithTileMode(texture_sampler_dst, // sampler
v_dst_texture_coords, // texture coordinates
blend_info.dst_y_coord_scale, // y coordinate scale
kTileModeDecal // tile mode
);
vec4 dst = IPUnpremultiply(dst_sample);
vec4 src = blend_info.color_factor > 0
? blend_info.color
: IPUnpremultiply(IPSampleWithTileMode(
@ -38,7 +40,8 @@ void main() {
kTileModeDecal // tile mode
));
vec3 blended = Blend(dst.rgb, src.rgb);
vec4 blended = vec4(Blend(dst.rgb, src.rgb), 1) * dst.a;
frag_color = vec4(blended, 1) * src.a * dst.a;
frag_color = mix(dst_sample, blended, src.a);
//frag_color = dst_sample;
}