[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.
This commit is contained in:
Jonah Williams
2024-03-26 13:48:04 -07:00
committed by GitHub
parent 3eb642ef4c
commit 92abaefe25
5 changed files with 21 additions and 21 deletions

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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
}
}
}