aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph/shaders_ng/shapecurve.vert
blob: 59f4ddb77d500e5eccf45edb397d83353baee674 (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
83
84
85
86
87
#version 440

layout(location = 0) in vec4 vertexCoord;
layout(location = 1) in vec4 vertexTexCoord;
layout(location = 2) in vec4 vertexGradient;
layout(location = 3) in vec2 normalVector;

layout(location = 0) out vec4 qt_TexCoord;
layout(location = 1) out vec4 gradient;

#if defined(LINEARGRADIENT)
layout(location = 2) out float gradTabIndex;
#elif defined(RADIALGRADIENT) || defined(CONICALGRADIENT)
layout(location = 2) out vec2 coord;
#endif

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 debug;
    float reserved3;

#if defined(STROKE)
    vec4 strokeColor;
    float strokeWidth;
    float reserved4;
    float reserved5;
    float reserved6;
#endif

#if defined(LINEARGRADIENT)
    vec2 gradientStart;
    vec2 gradientEnd;
#elif defined(RADIALGRADIENT)
    vec2 translationPoint;
    vec2 focalToCenter;
    float centerRadius;
    float focalRadius;
#elif defined(CONICALGRADIENT)
    vec2 translationPoint;
    float angle;
#else
    vec4 color;
#endif
} ubuf;

#define SQRT2 1.41421356237

vec4 addOffset(vec4 texCoord, vec2 offset, vec4 duvdxy)
{
    float dudx = duvdxy.x;
    float dvdx = duvdxy.y;
    float dudy = duvdxy.z;
    float dvdy = duvdxy.w;
    float u = offset.x * dudx + offset.y * dudy;
    float v = offset.x * dvdx + offset.y * dvdy;
    // special case external triangles for concave curves
    int specialCase = int(texCoord.z > 0) * (int(offset.x != 0) + int(offset.y != 0));
    return vec4(texCoord.x + u, texCoord.y + v, texCoord.z, float(specialCase));
}

void main()
{
    vec2 offset = normalVector * SQRT2/ubuf.matrixScale;

    qt_TexCoord = addOffset(vertexTexCoord, offset, vertexGradient);

    gradient = vertexGradient / ubuf.matrixScale;

#if defined(LINEARGRADIENT)
    vec2 gradVec = ubuf.gradientEnd - ubuf.gradientStart;
    gradTabIndex = dot(gradVec, vertexCoord.xy - ubuf.gradientStart.xy) / dot(gradVec, gradVec);
#elif defined(RADIALGRADIENT) || defined(CONICALGRADIENT)
    coord = vertexCoord.xy - ubuf.translationPoint;
#endif

#if QSHADER_VIEW_COUNT >= 2
    gl_Position = ubuf.qt_Matrix[gl_ViewIndex] * (vertexCoord + vec4(offset, 0, 0));
#else
    gl_Position = ubuf.qt_Matrix * (vertexCoord + vec4(offset, 0, 0));
#endif
}