2020-09-18 12:42:36 +00:00
|
|
|
// VERTEX_SHADER
|
2021-01-26 11:32:04 +00:00
|
|
|
uniform vec4 u_geometry;
|
2020-09-18 12:42:36 +00:00
|
|
|
|
2021-01-26 11:32:04 +00:00
|
|
|
_NOPERSPECTIVE_ _OUT_ vec2 coord;
|
2020-09-18 12:42:36 +00:00
|
|
|
|
|
|
|
void main() {
|
2021-01-26 11:32:04 +00:00
|
|
|
gl_Position = u_projection * (u_modelview * vec4(aPosition, 0.0, 1.0));
|
|
|
|
|
|
|
|
vec2 mv0 = u_modelview[0].xy;
|
|
|
|
vec2 mv1 = u_modelview[1].xy;
|
|
|
|
vec2 offset = aPosition - u_geometry.xy;
|
|
|
|
vec2 dir = vec2(dot(mv0, offset),
|
|
|
|
dot(mv1, offset));
|
|
|
|
|
|
|
|
coord = dir * u_geometry.zw;
|
2020-09-18 12:42:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// FRAGMENT_SHADER:
|
|
|
|
#ifdef GSK_LEGACY
|
|
|
|
uniform int u_num_color_stops;
|
|
|
|
#else
|
|
|
|
uniform highp int u_num_color_stops;
|
|
|
|
#endif
|
|
|
|
|
2021-01-26 11:49:16 +00:00
|
|
|
uniform bool u_repeat;
|
2021-01-26 11:32:04 +00:00
|
|
|
uniform vec2 u_range;
|
|
|
|
uniform float u_color_stops[6 * 5];
|
|
|
|
|
|
|
|
_NOPERSPECTIVE_ _IN_ vec2 coord;
|
|
|
|
|
|
|
|
float get_offset(int index) {
|
|
|
|
return u_color_stops[5 * index];
|
|
|
|
}
|
2020-09-18 12:42:36 +00:00
|
|
|
|
2021-01-26 11:32:04 +00:00
|
|
|
vec4 get_color(int index) {
|
|
|
|
int base = 5 * index + 1;
|
2020-09-18 12:42:36 +00:00
|
|
|
|
2021-01-26 11:32:04 +00:00
|
|
|
return vec4(u_color_stops[base],
|
|
|
|
u_color_stops[base + 1],
|
|
|
|
u_color_stops[base + 2],
|
|
|
|
u_color_stops[base + 3]);
|
2020-09-18 12:42:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void main() {
|
2021-01-26 11:32:04 +00:00
|
|
|
// Reverse scale
|
|
|
|
float offset = length(coord) * u_range.x + u_range.y;
|
2020-09-18 12:42:36 +00:00
|
|
|
|
2021-01-26 11:49:16 +00:00
|
|
|
if (u_repeat) {
|
|
|
|
offset = fract(offset);
|
|
|
|
}
|
|
|
|
|
2021-01-26 11:32:04 +00:00
|
|
|
if (offset < get_offset(0)) {
|
|
|
|
gskSetOutputColor(gsk_scaled_premultiply(get_color(0), u_alpha));
|
2020-09-18 12:42:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-26 11:32:04 +00:00
|
|
|
int n = u_num_color_stops - 1;
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
float curr_offset = get_offset(i);
|
|
|
|
float next_offset = get_offset(i + 1);
|
2020-09-18 12:42:36 +00:00
|
|
|
|
2021-01-26 11:32:04 +00:00
|
|
|
if (offset >= curr_offset && offset < next_offset) {
|
|
|
|
float f = (offset - curr_offset) / (next_offset - curr_offset);
|
|
|
|
vec4 curr_color = gsk_premultiply(get_color(i));
|
|
|
|
vec4 next_color = gsk_premultiply(get_color(i + 1));
|
|
|
|
vec4 color = mix(curr_color, next_color, f);
|
2020-09-18 12:42:36 +00:00
|
|
|
|
2021-01-26 11:32:04 +00:00
|
|
|
gskSetOutputColor(color * u_alpha);
|
|
|
|
return;
|
2020-09-18 12:42:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-26 11:32:04 +00:00
|
|
|
gskSetOutputColor(gsk_scaled_premultiply(get_color(n), u_alpha));
|
2020-09-18 12:42:36 +00:00
|
|
|
}
|