How to draw a circle
Draw a circle in a fragment shader without vertices.
Draw a circle in a fragment shader without vertices.
Vertice | Index | x | y |
---|---|---|---|
0 | 0 | 0 | 0 |
1 | 1 | 512 | 0 |
2 | 2 | 0 | 288 |
3 | 3 | 0 | 288 |
4 | 4 | 512 | 288 |
5 | 5 | 512 | 0 |
xxxxxxxxxx
precision mediump float;
uniform vec2 u_resolution;
void main() {
vec2 uv = gl_FragCoord.xy;
vec2 center = u_resolution * 0.5;
if (distance(uv, center) < 25.) {
gl_FragColor = vec4(0.027, 0.988, 0.341, 1.);
}
}
xxxxxxxxxx
precision mediump float;
attribute vec2 a_position;
uniform vec2 u_resolution;
void main() {
vec2 pos = a_position / u_resolution * 2.0 - 1.0;
gl_Position = vec4(pos.x, -pos.y, 0.0, 1.0);
}