6 precision mediump float;
9 #define ROUND_STARTCAP 0x1
10 #define ROUND_ENDCAP 0x2
11 #define SQUARE_STARTCAP 0x4
12 #define SQUARE_ENDCAP 0x8
13 precision mediump float;
18 uniform int antiAliasing;
20 uniform vec2 startAngle;
21 uniform vec2 endAngle;
32 float uvPixel = length( dFdx( vUV ) ) * 2.0;
33 float dx = mix( 0.0001, uvPixel, antiAliasing > 0 );
34 float radius2 = mix( 1.0 - radius * uvPixel - dx , -radius , step( 0.0, -radius ) );
39 vec2 uv = fract(vUV) * 2.0 - 1.0;
41 float ang_img = endAngle.y * startAngle.x - endAngle.x * startAngle.y;
42 float half1 = uv.x * startAngle.x - uv.y * startAngle.y;
43 float half2 = uv.y * endAngle.y - uv.x * endAngle.x;
44 float len = length(uv);
45 float equalAngles = step(0.99999, dot(endAngle, startAngle));
46 float right_side = step(0.0, ang_img);
47 vec2 uv_norm = normalize(uv);
48 float cap_radius = -0.5 + radius2 / 2.0;
52 /******************************************
54 * if( len > radius1 || len < radius2 )
56 circle = alpha = smoothstep( len, len + dx, radius1 ) * smoothstep( -len, -len + dx, -radius2 );
57 float half1_step = smoothstep( -dx, 0.0, half1 );
58 float half2_step = smoothstep( -dx, 0.0, half2 );
60 float neg_angimg = max( half1_step, half2_step );
61 float pos_angimg = min( half1_step, half2_step );
62 /******************************************
66 alpha *= max(smoothstep( 0.0, dx, half1 ), smoothstep( 0.0, dx, half2));
70 alpha *= min(smoothstep( 0.0, dx, half1 ) , smoothstep( 0.0, dx, half2 ));
73 alpha *= mix( neg_angimg, pos_angimg, step(0.0, ang_img) );
75 alpha = mix( alpha, mix( circle, 0.0, right_side ), equalAngles );
77 if((arcCaps & ROUND_STARTCAP) > 0)
79 len = length(uv - normalize( vec2( startAngle.y, startAngle.x )) * (1.0 + cap_radius));
80 alpha = max(alpha, smoothstep(cap_radius, cap_radius + dx, -len) );
82 if((arcCaps & ROUND_ENDCAP) > 0)
84 len = length(uv - normalize( vec2( endAngle.y, endAngle.x )) * (1.0 + cap_radius));
85 alpha = max(alpha, smoothstep(cap_radius, cap_radius + dx, -len) );
88 if((arcCaps & SQUARE_STARTCAP) > 0)
90 sq_plane = -uv.x * startAngle.y - uv.y * startAngle.x;
91 square_cap = min(step( 0.0, -half1 ), smoothstep( cap_radius, cap_radius + dx, half1 ));
92 square_cap = min(square_cap, smoothstep( radius2, radius2 + dx, -sq_plane ));
93 square_cap = min(square_cap, smoothstep( -1.0, -1.0 + dx, sq_plane ));
94 alpha = max(square_cap, alpha);
97 if((arcCaps & SQUARE_ENDCAP) > 0)
99 sq_plane = -uv.x * endAngle.y - uv.y * endAngle.x;
100 square_cap = min(step( 0.0, -half2 ), smoothstep( cap_radius, cap_radius + dx, half2 ));
101 square_cap = min(square_cap, smoothstep( radius2, radius2 + dx, -sq_plane ));
102 square_cap = min(square_cap, smoothstep( -1.0, -1.0 + dx, sq_plane ));
103 alpha = max(square_cap, alpha);
111 FragColor = vec4(vec3(uColor), uColor.a * alpha);