File: arrowheads.vert

package info (click to toggle)
python-vispy 0.16.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,112 kB
  • sloc: python: 61,648; javascript: 6,800; ansic: 2,104; makefile: 141; sh: 6
file content (83 lines) | stat: -rw-r--r-- 2,168 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
 * Copyright (c) Vispy Development Team
 * Distributed under the (new) BSD License. See LICENSE.txt for more info.
 *
 * This file contains the vertex shader template for arrow heads.
 *
 * Variables
 * ---------
 * $transform
 *     Projection matrix of vertex to the screen
 *
 * Attributes
 * ----------
 * v1
 *     The first vertex of the arrow body
 * v2
 *     The second vertex of the arrow body. This will also be the center
 *     location of the arrow head. Using v1, we determine a direction vector
 *     to automatically determine the orientation.
 * size
 *     Size of the arrow head in pixels
 * color
 *     The color of the arrow head
 * v_linewidth
 *     The width for the stroke or outline of the shape.
 *
 * Varyings
 * --------
 * v_size
 *     The arrow head size in pixels
 * v_point_size
 *     The actual size of the point used for drawing. This is larger than the
 *     given arrow head size to make sure rotating goes well, and allows some
 *     space for anti-aliasing.
 * v_color
 *     The color for the arrow head
 * v_orientation
 *     A direction vector for the orientation of the arrow head
 * v_antialias
 *     Anti-alias width
 * v_linewidth
 *     Width for the stroke or outline of the shape.
 */

#include "math/constants.glsl"

// Uniforms
// ------------------------------------
uniform float antialias;

// Attributes
// ------------------------------------
attribute vec4  v1;
attribute vec4  v2;
attribute float size;
attribute vec4  color;
attribute float linewidth;

// Varyings
// ------------------------------------
varying float v_size;
varying float v_point_size;
varying vec4  v_color;
varying vec3  v_orientation;
varying float v_antialias;
varying float v_linewidth;

// Main (hooked)
// ------------------------------------
void main (void)
{
    v_size        = size;
    v_point_size  = M_SQRT2 * size + 2.0 * (linewidth + 2.0*antialias);
    v_antialias   = antialias;
    v_color       = color;
    v_linewidth   = linewidth;

    vec3 body = $transform(v2).xyz - $transform(v1).xyz;
    v_orientation = (body / length(body));

    gl_Position = $transform(v2);
    gl_PointSize = v_point_size;
}