[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:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user