From 92abaefe25d6bba03c38c01f8ece7594a41f53d4 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Tue, 26 Mar 2024 13:48:04 -0700 Subject: [PATCH] [Impeller] use screen space coordinates for dithering. (flutter/engine#51668) Currently we're using the canvas coordinate positions for dithering. This usually works, but if the gradient includes a transform, then we might end up with 1 canvas coordinate pt = multiple physical pixels. This can result dithering artifacts since larger blocks will get the same color weight. instead we can use gl_FragCoord.xy to get the screenspace coordinates which aren't effect by this transform. Fixes https://github.com/flutter/flutter/issues/145481 ## Before ![flutter_04](https://github.com/flutter/engine/assets/8975114/5f5c19a5-575b-45fb-8f58-c5dc4e46dfb1) ## After ![flutter_05](https://github.com/flutter/engine/assets/8975114/8e80c967-a73d-433c-a16d-918f2aa042db) Using the app from https://github.com/flutter/flutter/issues/145481 but with the scaling factor increased to 10.0. --- .../shaders/conical_gradient_ssbo_fill.frag | 2 +- .../shaders/linear_gradient_ssbo_fill.frag | 2 +- .../shaders/radial_gradient_ssbo_fill.frag | 2 +- .../shaders/sweep_gradient_ssbo_fill.frag | 2 +- engine/src/flutter/impeller/tools/malioc.json | 34 +++++++++---------- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/engine/src/flutter/impeller/entity/shaders/conical_gradient_ssbo_fill.frag b/engine/src/flutter/impeller/entity/shaders/conical_gradient_ssbo_fill.frag index 80289969b1..432152ea82 100644 --- a/engine/src/flutter/impeller/entity/shaders/conical_gradient_ssbo_fill.frag +++ b/engine/src/flutter/impeller/entity/shaders/conical_gradient_ssbo_fill.frag @@ -65,5 +65,5 @@ void main() { } frag_color = IPPremultiply(result_color) * frag_info.alpha; - frag_color = IPOrderedDither8x8(frag_color, v_position); + frag_color = IPOrderedDither8x8(frag_color, gl_FragCoord.xy); } diff --git a/engine/src/flutter/impeller/entity/shaders/linear_gradient_ssbo_fill.frag b/engine/src/flutter/impeller/entity/shaders/linear_gradient_ssbo_fill.frag index dcfc5918a1..e64c33b4d1 100644 --- a/engine/src/flutter/impeller/entity/shaders/linear_gradient_ssbo_fill.frag +++ b/engine/src/flutter/impeller/entity/shaders/linear_gradient_ssbo_fill.frag @@ -61,5 +61,5 @@ void main() { } frag_color = IPPremultiply(frag_color) * frag_info.alpha; - frag_color = IPOrderedDither8x8(frag_color, v_position); + frag_color = IPOrderedDither8x8(frag_color, gl_FragCoord.xy); } diff --git a/engine/src/flutter/impeller/entity/shaders/radial_gradient_ssbo_fill.frag b/engine/src/flutter/impeller/entity/shaders/radial_gradient_ssbo_fill.frag index afb5d7a799..2a7390ce39 100644 --- a/engine/src/flutter/impeller/entity/shaders/radial_gradient_ssbo_fill.frag +++ b/engine/src/flutter/impeller/entity/shaders/radial_gradient_ssbo_fill.frag @@ -61,5 +61,5 @@ void main() { } frag_color = IPPremultiply(result_color) * frag_info.alpha; - frag_color = IPOrderedDither8x8(frag_color, v_position); + frag_color = IPOrderedDither8x8(frag_color, gl_FragCoord.xy); } diff --git a/engine/src/flutter/impeller/entity/shaders/sweep_gradient_ssbo_fill.frag b/engine/src/flutter/impeller/entity/shaders/sweep_gradient_ssbo_fill.frag index 00a39ccbd5..20d7f7d91b 100644 --- a/engine/src/flutter/impeller/entity/shaders/sweep_gradient_ssbo_fill.frag +++ b/engine/src/flutter/impeller/entity/shaders/sweep_gradient_ssbo_fill.frag @@ -62,5 +62,5 @@ void main() { } frag_color = IPPremultiply(result_color) * frag_info.alpha; - frag_color = IPOrderedDither8x8(frag_color, v_position); + frag_color = IPOrderedDither8x8(frag_color, gl_FragCoord.xy); } diff --git a/engine/src/flutter/impeller/tools/malioc.json b/engine/src/flutter/impeller/tools/malioc.json index 02522dda4a..0e196dad7d 100644 --- a/engine/src/flutter/impeller/tools/malioc.json +++ b/engine/src/flutter/impeller/tools/malioc.json @@ -1126,7 +1126,7 @@ "shortest_path_cycles": [ 0.5, 0.109375, - 0.328125, + 0.296875, 0.5, 0.0, 0.25, @@ -1136,9 +1136,9 @@ "load_store" ], "total_cycles": [ - 1.4500000476837158, + 1.4249999523162842, 0.862500011920929, - 1.4500000476837158, + 1.4249999523162842, 0.875, 4.0, 0.25, @@ -1147,8 +1147,8 @@ }, "stack_spill_bytes": 0, "thread_occupancy": 100, - "uniform_registers_used": 46, - "work_registers_used": 20 + "uniform_registers_used": 44, + "work_registers_used": 17 } } } @@ -8336,7 +8336,7 @@ "shortest_path_cycles": [ 0.5625, 0.203125, - 0.296875, + 0.265625, 0.5625, 0.0, 0.25, @@ -8346,9 +8346,9 @@ "load_store" ], "total_cycles": [ - 0.78125, + 0.75, 0.421875, - 0.78125, + 0.75, 0.625, 4.0, 0.25, @@ -8358,7 +8358,7 @@ "stack_spill_bytes": 0, "thread_occupancy": 100, "uniform_registers_used": 24, - "work_registers_used": 20 + "work_registers_used": 17 } } } @@ -9205,7 +9205,7 @@ "shortest_path_cycles": [ 0.5625, 0.21875, - 0.3125, + 0.28125, 0.5625, 0.0, 0.25, @@ -9215,9 +9215,9 @@ "load_store" ], "total_cycles": [ - 0.75, + 0.71875, 0.421875, - 0.75, + 0.71875, 0.625, 4.0, 0.25, @@ -9227,7 +9227,7 @@ "stack_spill_bytes": 0, "thread_occupancy": 100, "uniform_registers_used": 22, - "work_registers_used": 20 + "work_registers_used": 17 } } } @@ -10013,7 +10013,7 @@ "shortest_path_cycles": [ 0.8125, 0.421875, - 0.359375, + 0.328125, 0.8125, 0.0, 0.25, @@ -10025,7 +10025,7 @@ "total_cycles": [ 0.875, 0.6875, - 0.800000011920929, + 0.762499988079071, 0.875, 4.0, 0.25, @@ -10034,8 +10034,8 @@ }, "stack_spill_bytes": 0, "thread_occupancy": 100, - "uniform_registers_used": 28, - "work_registers_used": 23 + "uniform_registers_used": 26, + "work_registers_used": 20 } } }