aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph/shaders_ng/shapestroke.vert
blob: e358e059ebd5443526c6e22bad4c7e0185d6f7ee (plain)
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
#version 440

layout(location = 0) in vec4 vertexCoord;
layout(location = 1) in vec2 inA;
layout(location = 2) in vec2 inB;
layout(location = 3) in vec2 inC;
layout(location = 4) in vec2 normalVector;

layout(location = 0) out vec4 P;
layout(location = 1) out vec2 A;
layout(location = 2) out vec2 B;
layout(location = 3) out vec2 C;
layout(location = 4) out vec2 HG;
layout(location = 5) out float offset;


layout(std140, binding = 0) uniform buf {
#if QSHADER_VIEW_COUNT >= 2
    mat4 qt_Matrix[QSHADER_VIEW_COUNT];
#else
    mat4 qt_Matrix;
#endif

    float matrixScale;
    float opacity;
    float reserved2;
    float reserved3;

    vec4 strokeColor;

    float strokeWidth;
    float debug;
    float reserved5;
    float reserved6;
} ubuf;

#define SQRT2 1.41421356237

float qdot(vec2 a, vec2 b)
{
    return a.x * b.x + a.y * b.y;
}

void main()
{
    P = vertexCoord + vec4(normalVector, 0.0, 0.0) * SQRT2/ubuf.matrixScale;

    A = inA;
    B = inB;
    C = inC;

    // Find the parameters H, G for the depressed cubic
    // t^2+H*t+G=0
    // that results from the equation
    // Q'(s).(p-Q(s)) = 0
    // The last parameter is the static offset between s and t:
    // s = t - b/(3a)
    // use it to get back the parameter t

    // this is a constant for the curve
    float a = -2. * qdot(A, A);
    // this is a constant for the curve
    float b = -3. * qdot(A, B);
    //this is linear in p so it can be put into the shader with vertex data
    float c = 2. * qdot(A, P.xy) - qdot(B, B) - 2. * qdot(A, C);
    //this is linear in p so it can be put into the shader with vertex data
    float d = qdot(B, P.xy) - qdot(B, C);
    // convert to depressed cubic.
    // both functions are linear in c and d and thus linear in p
    float H = (3. * a * c - b * b) / (3. * a * a);
    float G = (2. * b * b * b - 9. * a * b * c + 27. * a * a * d) / (27. * a * a * a);
    HG = vec2(H, G);
    offset = b/(3*a);



#if QSHADER_VIEW_COUNT >= 2
    gl_Position = ubuf.qt_Matrix[gl_ViewIndex] * P;
#else
    gl_Position = ubuf.qt_Matrix * P;
#endif
}