[Impeller] Optimize the calculation of interpolant value of linear gradient (flutter/engine#40085)

[Impeller] Optimize the calculation of interpolant value of linear gradient
This commit is contained in:
ColdPaleLight
2023-03-08 08:46:05 +08:00
committed by GitHub
parent 9bc89c950c
commit bf7cfcf102
2 changed files with 8 additions and 8 deletions

View File

@@ -22,10 +22,10 @@ in vec2 v_position;
out vec4 frag_color;
void main() {
float len = length(frag_info.end_point - frag_info.start_point);
float dot = dot(v_position - frag_info.start_point,
frag_info.end_point - frag_info.start_point);
float t = dot / (len * len);
vec2 start_to_end = frag_info.end_point - frag_info.start_point;
vec2 start_to_position = v_position - frag_info.start_point;
float t =
dot(start_to_position, start_to_end) / dot(start_to_end, start_to_end);
frag_color = IPSampleLinearWithTileMode(
texture_sampler, vec2(t, 0.5), frag_info.texture_sampler_y_coord_scale,
frag_info.half_texel, frag_info.tile_mode);

View File

@@ -30,10 +30,10 @@ in vec2 v_position;
out vec4 frag_color;
void main() {
float len = length(frag_info.end_point - frag_info.start_point);
float dot = dot(v_position - frag_info.start_point,
frag_info.end_point - frag_info.start_point);
float t = dot / (len * len);
vec2 start_to_end = frag_info.end_point - frag_info.start_point;
vec2 start_to_position = v_position - frag_info.start_point;
float t =
dot(start_to_position, start_to_end) / dot(start_to_end, start_to_end);
if ((t < 0.0 || t > 1.0) && frag_info.tile_mode == kTileModeDecal) {
frag_color = vec4(0);