From 0fc3da0f4b8921e183c90e555b6d58a096c1530a Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Fri, 9 Sep 2022 18:06:18 -0700 Subject: [PATCH] [Impeller] Premultiply gradient alpha after the gradient LUT is generated (flutter/engine#36064) --- engine/src/flutter/impeller/aiks/aiks_unittests.cc | 2 +- .../flutter/impeller/entity/shaders/linear_gradient_fill.frag | 1 + .../flutter/impeller/entity/shaders/radial_gradient_fill.frag | 1 + .../flutter/impeller/entity/shaders/sweep_gradient_fill.frag | 1 + engine/src/flutter/impeller/geometry/gradient.cc | 2 +- 5 files changed, 5 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/impeller/aiks/aiks_unittests.cc b/engine/src/flutter/impeller/aiks/aiks_unittests.cc index d66cbe4d40..be11f22006 100644 --- a/engine/src/flutter/impeller/aiks/aiks_unittests.cc +++ b/engine/src/flutter/impeller/aiks/aiks_unittests.cc @@ -336,7 +336,7 @@ TEST_P(AiksTest, CanRenderLinearGradient) { auto tile_mode = tile_modes[selected_tile_mode]; paint.color_source = [tile_mode]() { std::vector colors = {Color{0.9568, 0.2627, 0.2118, 1.0}, - Color{0.1294, 0.5882, 0.9529, 1.0}}; + Color{0.1294, 0.5882, 0.9529, 0.0}}; std::vector stops = {0.0, 1.0}; auto contents = std::make_shared(); diff --git a/engine/src/flutter/impeller/entity/shaders/linear_gradient_fill.frag b/engine/src/flutter/impeller/entity/shaders/linear_gradient_fill.frag index 467c4222ab..77c03fbd28 100644 --- a/engine/src/flutter/impeller/entity/shaders/linear_gradient_fill.frag +++ b/engine/src/flutter/impeller/entity/shaders/linear_gradient_fill.frag @@ -30,4 +30,5 @@ void main() { gradient_info.texture_sampler_y_coord_scale, gradient_info.tile_mode, gradient_info.tile_mode); + frag_color = vec4(frag_color.xyz * frag_color.a, frag_color.a); } diff --git a/engine/src/flutter/impeller/entity/shaders/radial_gradient_fill.frag b/engine/src/flutter/impeller/entity/shaders/radial_gradient_fill.frag index 402969484f..c400fef17a 100644 --- a/engine/src/flutter/impeller/entity/shaders/radial_gradient_fill.frag +++ b/engine/src/flutter/impeller/entity/shaders/radial_gradient_fill.frag @@ -26,4 +26,5 @@ void main() { gradient_info.texture_sampler_y_coord_scale, gradient_info.tile_mode, gradient_info.tile_mode); + frag_color = vec4(frag_color.xyz * frag_color.a, frag_color.a); } diff --git a/engine/src/flutter/impeller/entity/shaders/sweep_gradient_fill.frag b/engine/src/flutter/impeller/entity/shaders/sweep_gradient_fill.frag index 674791f7e4..08733dc3f6 100644 --- a/engine/src/flutter/impeller/entity/shaders/sweep_gradient_fill.frag +++ b/engine/src/flutter/impeller/entity/shaders/sweep_gradient_fill.frag @@ -30,4 +30,5 @@ void main() { gradient_info.texture_sampler_y_coord_scale, gradient_info.tile_mode, gradient_info.tile_mode); + frag_color = vec4(frag_color.xyz * frag_color.a, frag_color.a); } diff --git a/engine/src/flutter/impeller/geometry/gradient.cc b/engine/src/flutter/impeller/geometry/gradient.cc index 150aa92e3e..6859fa0ab1 100644 --- a/engine/src/flutter/impeller/geometry/gradient.cc +++ b/engine/src/flutter/impeller/geometry/gradient.cc @@ -9,7 +9,7 @@ namespace impeller { static void AppendColor(const Color& color, std::vector* colors) { - auto converted = color.Premultiply().ToR8G8B8A8(); + auto converted = color.ToR8G8B8A8(); colors->push_back(converted[0]); colors->push_back(converted[1]); colors->push_back(converted[2]);