Hi all,
Could anyone enlighten me a bit on some OpenGL concepts, and the arrow shaders? I'll take the curved arrows as an example:
https://github.com/glumpy/glumpy/blob/master/glumpy/library/arrows/curved.glslMain vertex shader:
https://github.com/glumpy/glumpy/blob/master/glumpy/library/arrows/arrow.vertFragment shader:
https://github.com/glumpy/glumpy/blob/master/glumpy/library/arrows/arrow.fragThis is how I understand it currently:
1. You pass positions of the arrows as VBO to the vertex shader
2. Arrows are drawn with GL points mode
3. Only one vertex is given per arrow, so some special handling for colouring the arrow is needed
4. That's why gl_PointSize is increased. But how does this work exactly? Do you get a X by X square which represents a point, and the individual pixels are coloured in by the fragment shader?
5. Why the sqrt(2) size + 2 (linewidth + 1.5 * antialias) for point size?
vec2 start = -vec2(body/2.0, 0.0);
vec2 end = +vec2(body/2.0, 0.0);
float height = 0.5;
6. Define a start and end point of the arrow. I'm not sure how this works, as it's sort of fixed. Arrow is by default oriented in the X direction?
vec2 p1 = end - head*vec2(+1.0,+height);
vec2 p2 = end - head*vec2(+1.0,-height);
vec2 p3 = end;
// Head : 3 circles
vec2 c1 = circle_from_2_points(p1, p3, 1.25*body).zw;
float d1 = length(texcoord - c1) - 1.25*body;
vec2 c2 = circle_from_2_points(p2, p3, 1.25*body).xy;
float d2 = length(texcoord - c2) - 1.25*body;
vec2 c3 = circle_from_2_points(p1, p2, max(body-head, 1.0*body)).xy;
float d3 = length(texcoord - c3) - max(body-head, 1.0*body);
7. First define some points: two points on the side of the arrow head, and one on the tip of the arrow.
8. Second, define some circles. Why and what is the zw property used for c1?
9. For c3: max(body-head, 1.0*body), I don't understand this one, why multiply body with 1.0? Won't this always return body?
10. What is the role of texcoord? It guess it contains the current pixel coordinates in the current point. And a rotation transform is applied to it.
11. And then we compute some distance to something. This distance is then used to determine the color for the current pixel.
Thanks in advance!