diff --git a/engine/src/flutter/impeller/entity/contents/filters/color_matrix_filter_contents.cc b/engine/src/flutter/impeller/entity/contents/filters/color_matrix_filter_contents.cc index 78409bad75..b8084c9525 100644 --- a/engine/src/flutter/impeller/entity/contents/filters/color_matrix_filter_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/filters/color_matrix_filter_contents.cc @@ -77,16 +77,16 @@ std::optional ColorMatrixFilterContents::RenderFilter( FS::FragInfo frag_info; const float* matrix = matrix_.array; frag_info.color_v = Vector4(matrix[4], matrix[9], matrix[14], matrix[19]); + frag_info.texture_sampler_y_coord_scale = + input_snapshot->texture->GetYCoordScale(); // clang-format off - frag_info.color_m = - Matrix( - matrix[ 0], matrix[ 1], matrix[ 2], matrix[ 3], - matrix[ 5], matrix[ 6], matrix[ 7], matrix[ 8], - matrix[10], matrix[11], matrix[12], matrix[13], - matrix[15], matrix[16], matrix[17], matrix[18] - ); + frag_info.color_m = Matrix( + matrix[0], matrix[5], matrix[10], matrix[15], + matrix[1], matrix[6], matrix[11], matrix[16], + matrix[2], matrix[7], matrix[12], matrix[17], + matrix[3], matrix[8], matrix[13], matrix[18] + ); // clang-format on - auto sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler({}); FS::BindInputTexture(cmd, input_snapshot->texture, sampler); FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info)); diff --git a/engine/src/flutter/impeller/entity/entity_unittests.cc b/engine/src/flutter/impeller/entity/entity_unittests.cc index bdd5258304..90c44f756c 100644 --- a/engine/src/flutter/impeller/entity/entity_unittests.cc +++ b/engine/src/flutter/impeller/entity/entity_unittests.cc @@ -1556,35 +1556,6 @@ TEST_P(EntityTest, ColorMatrixFilterCoverageIsCorrect) { ASSERT_RECT_NEAR(actual.value(), expected); } -TEST_P(EntityTest, ColorMatrixFilter) { - auto image = CreateTextureForFixture("boston.jpg"); - ASSERT_TRUE(image); - - auto callback = [&](ContentContext& context, RenderPass& pass) -> bool { - // Set the color matrix filter. - FilterContents::ColorMatrix matrix = { - 1, 0, 0, 0, 0, // - 0, 3, 0, 0, 0, // - 0, 0, 1, 0, 0, // - 0, 0, 0, 1, 0, // - }; - - auto filter = - FilterContents::MakeColorMatrix(FilterInput::Make(image), matrix); - - // Define the entity with the color matrix filter. - Entity entity; - entity.SetTransformation(Matrix::MakeScale(GetContentScale()) * - Matrix::MakeTranslation({500, 300}) * - Matrix::MakeScale(Vector2{0.5, 0.5})); - entity.SetContents(filter); - return entity.Render(context, pass); - }; - - // Should output the boston image with a green filter. - ASSERT_TRUE(OpenPlaygroundHere(callback)); -} - TEST_P(EntityTest, ColorMatrixFilterEditable) { auto bay_bridge = CreateTextureForFixture("bay_bridge.jpg"); ASSERT_TRUE(bay_bridge); diff --git a/engine/src/flutter/impeller/entity/shaders/color_matrix_color_filter.frag b/engine/src/flutter/impeller/entity/shaders/color_matrix_color_filter.frag index 08adb27b66..47280649dd 100644 --- a/engine/src/flutter/impeller/entity/shaders/color_matrix_color_filter.frag +++ b/engine/src/flutter/impeller/entity/shaders/color_matrix_color_filter.frag @@ -3,6 +3,7 @@ // found in the LICENSE file. #include +#include // A color filter that transforms colors through a 4x5 color matrix. // @@ -28,6 +29,7 @@ uniform FragInfo { mat4 color_m; vec4 color_v; + float texture_sampler_y_coord_scale; } frag_info; uniform sampler2D input_texture; @@ -36,7 +38,8 @@ in vec2 v_position; out vec4 frag_color; void main() { - vec4 input_color = texture(input_texture, v_position); + vec4 input_color = IPSample(input_texture, v_position, + frag_info.texture_sampler_y_coord_scale); // unpremultiply first, as filter inputs are premultiplied. vec4 color = IPUnpremultiply(input_color);