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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
|
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
** This file is part of the QtOpenGL module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the either Technology Preview License Agreement or the
** Beta Release License Agreement.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain
** additional rights. These rights are described in the Nokia Qt LGPL
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
** $QT_END_LICENSE$
**
****************************************************************************/
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#ifndef QGL_ENGINE_SHADER_SOURCE_H
#define QGL_ENGINE_SHADER_SOURCE_H
#include "qglengineshadermanager_p.h"
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(OpenGL)
static const char* const qglslMainVertexShader = "\
void setPosition();\
void main(void)\
{\
setPosition();\
}";
static const char* const qglslMainWithTexCoordsVertexShader = "\
attribute lowp vec2 textureCoordArray; \
varying lowp vec2 textureCoords; \
void setPosition();\
void main(void) \
{\
setPosition();\
textureCoords = textureCoordArray; \
}";
static const char* const qglslPositionOnlyVertexShader = "\
attribute highp vec4 vertexCoordsArray;\
uniform highp mat4 pmvMatrix;\
void setPosition(void)\
{\
gl_Position = pmvMatrix * vertexCoordsArray;\
}";
// Pattern Brush - This assumes the texture size is 8x8 and thus, the inverted size is 0.125
static const char* const qglslPositionWithPatternBrushVertexShader = "\
attribute highp vec4 vertexCoordsArray; \
uniform highp mat4 pmvMatrix; \
uniform mediump vec2 halfViewportSize; \
uniform mediump vec2 invertedTextureSize; \
uniform mediump mat3 brushTransform; \
varying mediump vec2 patternTexCoords; \
void setPosition(void) { \
gl_Position = pmvMatrix * vertexCoordsArray;\
gl_Position.xy = gl_Position.xy / gl_Position.w; \
mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \
gl_Position.w = invertedHTexCoordsZ; \
patternTexCoords.xy = (hTexCoords.xy * 0.125) * invertedHTexCoordsZ; \
patternTexCoords.y = -patternTexCoords.y; \
}";
static const char* const qglslAffinePositionWithPatternBrushVertexShader
= qglslPositionWithPatternBrushVertexShader;
static const char* const qglslPatternBrushSrcFragmentShader = "\
uniform sampler2D brushTexture;\
uniform lowp vec4 patternColor; \
varying mediump vec2 patternTexCoords;\
lowp vec4 srcPixel() { \
return patternColor * texture2D(brushTexture, patternTexCoords).r; \
}\n";
// Linear Gradient Brush
static const char* const qglslPositionWithLinearGradientBrushVertexShader = "\
attribute highp vec4 vertexCoordsArray; \
uniform highp mat4 pmvMatrix; \
uniform mediump vec2 halfViewportSize; \
uniform highp vec3 linearData; \
uniform highp mat3 brushTransform; \
varying mediump float index ; \
void setPosition() { \
gl_Position = pmvMatrix * vertexCoordsArray;\
gl_Position.xy = gl_Position.xy / gl_Position.w; \
mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \
gl_Position.w = invertedHTexCoordsZ; \
index = (dot(linearData.xy, hTexCoords.xy) * linearData.z) * invertedHTexCoordsZ; \
}";
static const char* const qglslAffinePositionWithLinearGradientBrushVertexShader
= qglslPositionWithLinearGradientBrushVertexShader;
static const char* const qglslLinearGradientBrushSrcFragmentShader = "\
uniform sampler2D brushTexture; \
varying mediump float index; \
lowp vec4 srcPixel() { \
mediump vec2 val = vec2(index, 0.5); \
return texture2D(brushTexture, val); \
}\n";
// Conical Gradient Brush
static const char* const qglslPositionWithConicalGradientBrushVertexShader = "\
attribute highp vec4 vertexCoordsArray;\
uniform highp mat4 pmvMatrix;\
uniform mediump vec2 halfViewportSize; \
uniform highp mat3 brushTransform; \
varying highp vec2 A; \
void setPosition(void)\
{\
gl_Position = pmvMatrix * vertexCoordsArray;\
gl_Position.xy = gl_Position.xy / gl_Position.w; \
mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \
gl_Position.w = invertedHTexCoordsZ; \
A = hTexCoords.xy * invertedHTexCoordsZ; \
}";
static const char* const qglslAffinePositionWithConicalGradientBrushVertexShader
= qglslPositionWithConicalGradientBrushVertexShader;
static const char* const qglslConicalGradientBrushSrcFragmentShader = "\n\
#define INVERSE_2PI 0.1591549430918953358 \n\
uniform sampler2D brushTexture; \n\
uniform mediump float angle; \
varying highp vec2 A; \
lowp vec4 srcPixel() { \
highp float t; \
if (abs(A.y) == abs(A.x)) \
t = (atan(-A.y + 0.002, A.x) + angle) * INVERSE_2PI; \
else \
t = (atan(-A.y, A.x) + angle) * INVERSE_2PI; \
return texture2D(brushTexture, vec2(t - floor(t), 0.5)); \
}";
// Radial Gradient Brush
static const char* const qglslPositionWithRadialGradientBrushVertexShader = "\
attribute highp vec4 vertexCoordsArray;\
uniform highp mat4 pmvMatrix;\
uniform mediump vec2 halfViewportSize; \
uniform highp mat3 brushTransform; \
uniform highp vec2 fmp; \
varying highp float b; \
varying highp vec2 A; \
void setPosition(void) \
{\
gl_Position = pmvMatrix * vertexCoordsArray;\
gl_Position.xy = gl_Position.xy / gl_Position.w; \
mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \
gl_Position.w = invertedHTexCoordsZ; \
A = hTexCoords.xy * invertedHTexCoordsZ; \
b = 2.0 * dot(A, fmp); \
}";
static const char* const qglslAffinePositionWithRadialGradientBrushVertexShader
= qglslPositionWithRadialGradientBrushVertexShader;
static const char* const qglslRadialGradientBrushSrcFragmentShader = "\
uniform sampler2D brushTexture; \
uniform highp float fmp2_m_radius2; \
uniform highp float inverse_2_fmp2_m_radius2; \
varying highp float b; \
varying highp vec2 A; \
lowp vec4 srcPixel() { \
highp float c = -dot(A, A); \
highp vec2 val = vec2((-b + sqrt(b*b - 4.0*fmp2_m_radius2*c)) * inverse_2_fmp2_m_radius2, 0.5); \
return texture2D(brushTexture, val); \
}";
// Texture Brush
static const char* const qglslPositionWithTextureBrushVertexShader = "\
attribute highp vec4 vertexCoordsArray; \
uniform highp mat4 pmvMatrix; \
uniform mediump vec2 halfViewportSize; \
uniform mediump vec2 invertedTextureSize; \
uniform mediump mat3 brushTransform; \
varying mediump vec2 brushTextureCoords; \
void setPosition(void) { \
gl_Position = pmvMatrix * vertexCoordsArray;\
gl_Position.xy = gl_Position.xy / gl_Position.w; \
mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \
gl_Position.w = invertedHTexCoordsZ; \
brushTextureCoords.xy = (hTexCoords.xy * invertedTextureSize) * gl_Position.w; \
brushTextureCoords.y = -brushTextureCoords.y; \
}";
static const char* const qglslAffinePositionWithTextureBrushVertexShader
= qglslPositionWithTextureBrushVertexShader;
static const char* const qglslTextureBrushSrcFragmentShader = "\
varying mediump vec2 brushTextureCoords; \
uniform sampler2D brushTexture; \
lowp vec4 srcPixel() { \
return texture2D(brushTexture, brushTextureCoords); \
}";
// Solid Fill Brush
static const char* const qglslSolidBrushSrcFragmentShader = "\
uniform lowp vec4 fragmentColor; \
lowp vec4 srcPixel() { \
return fragmentColor; \
}";
static const char* const qglslImageSrcFragmentShader = "\
varying highp vec2 textureCoords; \
uniform sampler2D imageTexture; \
lowp vec4 srcPixel() { \
return texture2D(imageTexture, textureCoords); \
}";
static const char* const qglslNonPremultipliedImageSrcFragmentShader = "\
varying highp vec2 textureCoords; \
uniform sampler2D imageTexture; \
lowp vec4 srcPixel() { \
lowp vec4 sample = texture2D(imageTexture, textureCoords); \
sample.rgb = sample.rgb * sample.a; \
return sample; \
}";
static const char* const qglslShockingPinkSrcFragmentShader = "\
lowp vec4 srcPixel() { \
return vec4(0.98, 0.06, 0.75, 1.0); \
}";
static const char* const qglslMainFragmentShader_CMO = "\
uniform lowp float globalOpacity; \
lowp vec4 srcPixel(); \
lowp vec4 applyMask(lowp vec4); \
lowp vec4 compose(lowp vec4); \
void main() { \
gl_FragColor = applyMask(compose(srcPixel()*globalOpacity))); \
}";
static const char* const qglslMainFragmentShader_CM = "\
lowp vec4 srcPixel(); \
lowp vec4 applyMask(lowp vec4); \
lowp vec4 compose(lowp vec4); \
void main() { \
gl_FragColor = applyMask(compose(srcPixel())); \
}";
static const char* const qglslMainFragmentShader_MO = "\
uniform lowp float globalOpacity; \
lowp vec4 srcPixel(); \
lowp vec4 applyMask(lowp vec4); \
void main() { \
gl_FragColor = applyMask(srcPixel()*globalOpacity); \
}";
static const char* const qglslMainFragmentShader_M = "\
lowp vec4 srcPixel(); \
lowp vec4 applyMask(lowp vec4); \
void main() { \
gl_FragColor = applyMask(srcPixel()); \
}";
static const char* const qglslMainFragmentShader_CO = "\
uniform lowp float globalOpacity; \
lowp vec4 srcPixel(); \
lowp vec4 compose(lowp vec4); \
void main() { \
gl_FragColor = compose(srcPixel()*globalOpacity); \
}";
static const char* const qglslMainFragmentShader_C = "\
lowp vec4 srcPixel(); \
lowp vec4 compose(lowp vec4); \
void main() { \
gl_FragColor = compose(srcPixel()); \
}";
static const char* const qglslMainFragmentShader_O = "\
uniform lowp float globalOpacity; \
lowp vec4 srcPixel(); \
void main() { \
gl_FragColor = srcPixel()*globalOpacity; \
}";
static const char* const qglslMainFragmentShader = "\
lowp vec4 srcPixel(); \
void main() { \
gl_FragColor = srcPixel(); \
}";
static const char* const qglslMaskFragmentShader = "\
varying highp vec2 textureCoords;\
uniform sampler2D maskTexture;\
lowp vec4 applyMask(lowp vec4 src) \
{\
lowp vec4 mask = texture2D(maskTexture, textureCoords); \
return src * mask.r; \
}";
/*
Left to implement:
RgbMaskFragmentShader,
RgbMaskWithGammaFragmentShader,
MultiplyCompositionModeFragmentShader,
ScreenCompositionModeFragmentShader,
OverlayCompositionModeFragmentShader,
DarkenCompositionModeFragmentShader,
LightenCompositionModeFragmentShader,
ColorDodgeCompositionModeFragmentShader,
ColorBurnCompositionModeFragmentShader,
HardLightCompositionModeFragmentShader,
SoftLightCompositionModeFragmentShader,
DifferenceCompositionModeFragmentShader,
ExclusionCompositionModeFragmentShader,
*/
QT_END_NAMESPACE
QT_END_HEADER
#endif // GLGC_SHADER_SOURCE_H
|