2020-02-03 10:52:39 -08:00
|
|
|
#version 330
|
|
|
|
|
2021-01-18 16:39:29 -08:00
|
|
|
#INSERT camera_uniform_declarations.glsl
|
2020-06-02 16:18:44 -07:00
|
|
|
|
2020-02-03 10:52:39 -08:00
|
|
|
in vec4 color;
|
2021-11-01 13:05:13 -07:00
|
|
|
in float fill_all; // Either 0 or 1
|
2020-02-03 10:52:39 -08:00
|
|
|
in float uv_anti_alias_width;
|
|
|
|
|
2020-06-02 16:18:44 -07:00
|
|
|
in vec3 xyz_coords;
|
2020-06-03 17:10:33 -07:00
|
|
|
in float orientation;
|
2020-02-03 10:52:39 -08:00
|
|
|
in vec2 uv_coords;
|
|
|
|
in vec2 uv_b2;
|
2023-01-08 23:34:02 -05:00
|
|
|
in vec2 simp_coords;
|
2020-02-03 10:52:39 -08:00
|
|
|
in float bezier_degree;
|
|
|
|
|
|
|
|
out vec4 frag_color;
|
|
|
|
|
|
|
|
|
|
|
|
#INSERT quadratic_bezier_distance.glsl
|
2020-06-02 16:18:44 -07:00
|
|
|
|
2020-02-03 10:52:39 -08:00
|
|
|
|
|
|
|
float sdf(){
|
2020-06-03 17:10:33 -07:00
|
|
|
if(bezier_degree < 2){
|
|
|
|
return abs(uv_coords[1]);
|
|
|
|
}
|
|
|
|
float u2 = uv_b2.x;
|
|
|
|
float v2 = uv_b2.y;
|
|
|
|
// For really flat curves, just take the distance to x-axis
|
|
|
|
if(abs(v2 / u2) < 0.1 * uv_anti_alias_width){
|
|
|
|
return abs(uv_coords[1]);
|
|
|
|
}
|
2023-01-08 23:34:02 -05:00
|
|
|
vec2 p = simp_coords;
|
|
|
|
float Fp = (p.x * p.x - p.y);
|
2020-06-02 16:18:44 -07:00
|
|
|
// Sign takes care of whether we should be filling the inside or outside of curve.
|
2020-06-09 12:34:00 -07:00
|
|
|
float sgn = orientation * sign(v2);
|
2022-12-28 11:17:45 -08:00
|
|
|
if(sgn * Fp <= 0){
|
2021-02-03 17:22:28 +05:45
|
|
|
return 0.0;
|
2020-06-09 12:34:00 -07:00
|
|
|
}else{
|
|
|
|
return min_dist_to_curve(uv_coords, uv_b2, bezier_degree);
|
|
|
|
}
|
2020-02-03 10:52:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
if (color.a == 0) discard;
|
2020-06-06 16:55:56 -07:00
|
|
|
frag_color = color;
|
2020-05-31 17:02:05 -07:00
|
|
|
if (fill_all == 1.0) return;
|
2020-02-03 10:52:39 -08:00
|
|
|
frag_color.a *= smoothstep(1, 0, sdf() / uv_anti_alias_width);
|
2020-03-30 20:26:06 +02:00
|
|
|
}
|