Skip to content

Commit 3697288

Browse files
endankegithub-actions[bot]
authored andcommitted
Add u_trim_gradient_mix_range to mix gradient with trim color
GitOrigin-RevId: f2b0487cfd9001cf2c74c8cbe2bfab774becc5ce
1 parent 32404c1 commit 3697288

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/shaders/line.fragment.glsl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ uniform highp float u_floor_width_scale;
88
uniform float u_alpha_discard_threshold;
99
uniform highp vec2 u_trim_offset;
1010
uniform highp vec2 u_trim_fade_range;
11+
uniform highp vec2 u_trim_gradient_mix_range;
1112
uniform lowp vec4 u_trim_color;
1213

1314
in vec2 v_width2;
@@ -119,12 +120,14 @@ void main() {
119120
highp float start_transition = max(0.0, min(1.0, (line_progress - trim_start) / max(u_trim_fade_range[0], 1.0e-9)));
120121
highp float end_transition = max(0.0, min(1.0, (trim_end - line_progress) / max(u_trim_fade_range[1], 1.0e-9)));
121122
highp float transition_factor = min(start_transition, end_transition);
122-
#ifdef LINE_GRADIENT_AS_TRIM_COLOR
123-
out_color = mix(color, out_color, transition_factor);
124-
#else
125-
out_color = mix(out_color, u_trim_color, transition_factor);
123+
highp float gradient_trim_color_mix_factor = 0.0;
124+
#ifdef RENDER_LINE_GRADIENT
125+
gradient_trim_color_mix_factor = smoothstep(u_trim_gradient_mix_range.x, u_trim_gradient_mix_range.y, line_progress);
126126
#endif
127-
127+
highp vec4 trim_color = mix(u_trim_color, out_color, gradient_trim_color_mix_factor);
128+
// Note: if u_trim_gradient_mix_range.x < 1.0 the non-trimmed part will use the non-gradient color
129+
// This sets the usage of line-gradient as a trim-color
130+
out_color = mix(u_trim_gradient_mix_range.x < 1.0 ? color : out_color, trim_color, transition_factor);
128131
trim_alpha = 1.0 - transition_factor;
129132
}
130133
#endif

0 commit comments

Comments
 (0)