Skip to content

Commit

Permalink
[Impeller] Optimize the calculation of interpolant value of linear gr…
Browse files Browse the repository at this point in the history
…adient (#40085)

[Impeller] Optimize the calculation of interpolant value of linear gradient
  • Loading branch information
ColdPaleLight committed Mar 8, 2023
1 parent 7684aa0 commit 694a14c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions impeller/entity/shaders/linear_gradient_fill.frag
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions impeller/entity/shaders/linear_gradient_ssbo_fill.frag
Expand Up @@ -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);
Expand Down

0 comments on commit 694a14c

Please sign in to comment.