MythTV  master
mythrenderopenglshaders.h
Go to the documentation of this file.
1 #ifndef MYTHRENDER_OPENGL_SHADERS_H
2 #define MYTHRENDER_OPENGL_SHADERS_H
3 
4 #include <QString>
5 
6 static const QString kDefaultVertexShader =
7 "attribute vec2 a_position;\n"
8 "attribute vec4 a_color;\n"
9 "attribute vec2 a_texcoord0;\n"
10 "varying vec4 v_color;\n"
11 "varying vec2 v_texcoord0;\n"
12 "uniform mat4 u_projection;\n"
13 "uniform mat4 u_transform;\n"
14 "void main() {\n"
15 " gl_Position = u_projection * u_transform * vec4(a_position, 0.0, 1.0);\n"
16 " v_texcoord0 = a_texcoord0;\n"
17 " v_color = a_color;\n"
18 "}\n";
19 
20 static const QString kDefaultFragmentShader =
21 "uniform sampler2D s_texture0;\n"
22 "varying highp vec4 v_color;\n"
23 "varying highp vec2 v_texcoord0;\n"
24 "void main(void)\n"
25 "{\n"
26 " gl_FragColor = texture2D(s_texture0, v_texcoord0) * v_color;\n"
27 "}\n";
28 
29 static const QString kDefaultFragmentShaderLimited =
30 "uniform sampler2D s_texture0;\n"
31 "varying highp vec4 v_color;\n"
32 "varying highp vec2 v_texcoord0;\n"
33 "void main(void)\n"
34 "{\n"
35 " gl_FragColor = (texture2D(s_texture0, v_texcoord0) * v_color * vec4(0.85882, 0.85882, 0.85882, 1.0)) + vec4(0.06274, 0.06274, 0.06274, 0.0);\n"
36 "}\n";
37 
38 static const QString kSimpleVertexShader =
39 "attribute vec2 a_position;\n"
40 "attribute vec4 a_color;\n"
41 "varying vec4 v_color;\n"
42 "uniform mat4 u_projection;\n"
43 "uniform mat4 u_transform;\n"
44 "void main() {\n"
45 " gl_Position = u_projection * u_transform * vec4(a_position, 0.0, 1.0);\n"
46 " v_color = a_color;\n"
47 "}\n";
48 
49 static const QString kSimpleFragmentShader =
50 "varying highp vec4 v_color;\n"
51 "void main(void)\n"
52 "{\n"
53 " gl_FragColor = v_color;\n"
54 "}\n";
55 
56 static const QString kDrawVertexShader =
57 "attribute vec2 a_position;\n"
58 "attribute vec4 a_color;\n"
59 "varying vec4 v_color;\n"
60 "varying vec2 v_position;\n"
61 "uniform mat4 u_projection;\n"
62 "uniform mat4 u_transform;\n"
63 "void main() {\n"
64 " gl_Position = u_projection * u_transform * vec4(a_position, 0.0, 1.0);\n"
65 " v_color = a_color;\n"
66 " v_position = a_position;\n"
67 "}\n";
68 
69 static const QString kSDF =
70 "highp float SignedDistance(highp vec2 p, highp vec2 b, highp float r)\n"
71 "{\n"
72 " return length(max(abs(p) - b + r, 0.0)) - r;\n"
73 "}\n";
74 
75 static const QString kRoundedRectShader =
76 "varying highp vec4 v_color;\n"
77 "varying highp vec2 v_position;\n"
78 "uniform highp mat4 u_parameters;\n"
79 + kSDF +
80 "void main(void)\n"
81 "{\n"
82 " highp float dist = SignedDistance(v_position - u_parameters[0].xy,\n"
83 " u_parameters[1].xy, u_parameters[0].z);\n"
84 " gl_FragColor = v_color * vec4(1.0, 1.0, 1.0, smoothstep(0.0, -1.0, dist));\n"
85 "}\n";
86 
87 static const QString kRoundedEdgeShader =
88 "varying highp vec4 v_color;\n"
89 "varying highp vec2 v_position;\n"
90 "uniform highp mat4 u_parameters;\n"
91 + kSDF +
92 "void main(void)\n"
93 "{\n"
94 " highp float outer = SignedDistance(v_position - u_parameters[0].xy,\n"
95 " u_parameters[1].xy, u_parameters[0].z);\n"
96 " highp float inner = SignedDistance(v_position - u_parameters[0].xy,\n"
97 " u_parameters[1].zw, u_parameters[0].w);\n"
98 " highp float both = smoothstep(0.0, -1.0, outer) * smoothstep(-1.0, 0.0, inner);\n"
99 " gl_FragColor = vec4(v_color.rgb, v_color.a * both);\n"
100 "}\n";
101 #endif
kSimpleFragmentShader
static const QString kSimpleFragmentShader
Definition: mythrenderopenglshaders.h:49
kDrawVertexShader
static const QString kDrawVertexShader
Definition: mythrenderopenglshaders.h:56
kRoundedRectShader
static const QString kRoundedRectShader
Definition: mythrenderopenglshaders.h:75
kDefaultVertexShader
static const QString kDefaultVertexShader
Definition: mythrenderopenglshaders.h:6
kSimpleVertexShader
static const QString kSimpleVertexShader
Definition: mythrenderopenglshaders.h:38
kSDF
static const QString kSDF
Definition: mythrenderopenglshaders.h:69
kDefaultFragmentShader
static const QString kDefaultFragmentShader
Definition: mythrenderopenglshaders.h:20
kDefaultFragmentShaderLimited
static const QString kDefaultFragmentShaderLimited
Definition: mythrenderopenglshaders.h:29
kRoundedEdgeShader
static const QString kRoundedEdgeShader
Definition: mythrenderopenglshaders.h:87