Skip to content

Commit e9020d5

Browse files
committed
Create SmoothEllipseShader.c
Retina Display support for ellipse()
1 parent a98d735 commit e9020d5

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

SmoothEllipseShader.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
// Renders a stroked ellipse
3+
//
4+
5+
//Default precision qualifier
6+
precision highp float;
7+
8+
//This represents the current texture on the mesh
9+
uniform lowp sampler2D texture;
10+
11+
//The interpolated texture coordinate for this fragment
12+
varying highp vec2 vTexCoord;
13+
14+
//Ellipse parameters
15+
uniform lowp vec4 fillColor;
16+
uniform lowp vec4 strokeColor;
17+
18+
uniform highp vec2 radius;
19+
uniform highp float strokeWidth;
20+
21+
void main()
22+
{
23+
highp vec2 RadiusAA = vec2(radius.x - 2.0, radius.y - 2.0);
24+
25+
highp vec2 scaledPointSq = vec2( (vTexCoord.x * radius.x) *
26+
(vTexCoord.x * radius.x),
27+
(vTexCoord.y * radius.y) *
28+
(vTexCoord.y * radius.y) );
29+
30+
highp float c = (scaledPointSq.x / (radius.x*radius.x)) +
31+
(scaledPointSq.y / (radius.y*radius.y));
32+
33+
highp float cAA = (scaledPointSq.x / (RadiusAA.x*RadiusAA.x)) +
34+
(scaledPointSq.y / (RadiusAA.y*RadiusAA.y));
35+
36+
highp vec2 innerRadius = vec2( radius.x - strokeWidth * 2.0,
37+
radius.y - strokeWidth * 2.0 );
38+
39+
highp vec2 innerRadiusAA = vec2( radius.x - strokeWidth * 2.0 - 2.0,
40+
radius.y - strokeWidth * 2.0 - 2.0 );
41+
42+
highp float cInner = (scaledPointSq.x / (innerRadius.x*innerRadius.x)) +
43+
(scaledPointSq.y / (innerRadius.y*innerRadius.y));
44+
45+
highp float cInnerAA = (scaledPointSq.x /
46+
(innerRadiusAA.x*innerRadiusAA.x)) +
47+
(scaledPointSq.y /
48+
(innerRadiusAA.y*innerRadiusAA.y));
49+
50+
//Premult
51+
lowp vec4 fragCol = mix( fillColor, strokeColor,
52+
smoothstep( cInner / cInnerAA, 1.0, cInner ) );
53+
54+
gl_FragColor = mix( fragCol, vec4(0,0,0,0),
55+
smoothstep( c / cAA, 1.0, c ) );
56+
}

0 commit comments

Comments
 (0)