author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 02 Feb 2010 00:43:10 +0200 | |
changeset 3 | 41300fa6a67c |
parent 0 | 1918ee327afb |
child 4 | 3b1da2848fc7 |
child 7 | f7bc934e204c |
child 18 | 2f34d5167611 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 |
** All rights reserved. |
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtOpenGL module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
// |
|
43 |
// W A R N I N G |
|
44 |
// ------------- |
|
45 |
// |
|
46 |
// This file is not part of the Qt API. It exists purely as an |
|
47 |
// implementation detail. This header file may change from version to |
|
48 |
// version without notice, or even be removed. |
|
49 |
// |
|
50 |
// We mean it. |
|
51 |
// |
|
52 |
||
53 |
||
54 |
#ifndef QGL_ENGINE_SHADER_SOURCE_H |
|
55 |
#define QGL_ENGINE_SHADER_SOURCE_H |
|
56 |
||
57 |
#include "qglengineshadermanager_p.h" |
|
58 |
||
59 |
QT_BEGIN_HEADER |
|
60 |
||
61 |
QT_BEGIN_NAMESPACE |
|
62 |
||
63 |
QT_MODULE(OpenGL) |
|
64 |
||
65 |
||
66 |
static const char* const qglslMainVertexShader = "\ |
|
67 |
uniform highp float depth;\ |
|
68 |
void setPosition();\ |
|
69 |
void main(void)\ |
|
70 |
{\ |
|
71 |
setPosition();\ |
|
72 |
gl_Position.z = depth * gl_Position.w;\ |
|
73 |
}"; |
|
74 |
||
75 |
static const char* const qglslMainWithTexCoordsVertexShader = "\ |
|
76 |
attribute highp vec2 textureCoordArray; \ |
|
77 |
varying highp vec2 textureCoords; \ |
|
78 |
uniform highp float depth;\ |
|
79 |
void setPosition();\ |
|
80 |
void main(void) \ |
|
81 |
{\ |
|
82 |
setPosition();\ |
|
83 |
gl_Position.z = depth * gl_Position.w;\ |
|
84 |
textureCoords = textureCoordArray; \ |
|
85 |
}"; |
|
86 |
||
87 |
static const char* const qglslMainWithTexCoordsAndOpacityVertexShader = "\ |
|
88 |
attribute highp vec2 textureCoordArray; \ |
|
89 |
attribute lowp float opacityArray; \ |
|
90 |
varying highp vec2 textureCoords; \ |
|
91 |
varying lowp float opacity; \ |
|
92 |
uniform highp float depth; \ |
|
93 |
void setPosition(); \ |
|
94 |
void main(void) \ |
|
95 |
{ \ |
|
96 |
setPosition(); \ |
|
97 |
gl_Position.z = depth * gl_Position.w; \ |
|
98 |
textureCoords = textureCoordArray; \ |
|
99 |
opacity = opacityArray; \ |
|
100 |
}"; |
|
101 |
||
102 |
static const char* const qglslPositionOnlyVertexShader = "\ |
|
103 |
attribute highp vec4 vertexCoordsArray;\ |
|
104 |
uniform highp mat4 pmvMatrix;\ |
|
105 |
void setPosition(void)\ |
|
106 |
{\ |
|
107 |
gl_Position = pmvMatrix * vertexCoordsArray;\ |
|
108 |
}"; |
|
109 |
||
110 |
static const char* const qglslUntransformedPositionVertexShader = "\ |
|
111 |
attribute highp vec4 vertexCoordsArray;\ |
|
112 |
void setPosition(void)\ |
|
113 |
{\ |
|
114 |
gl_Position = vertexCoordsArray;\ |
|
115 |
}"; |
|
116 |
||
117 |
// Pattern Brush - This assumes the texture size is 8x8 and thus, the inverted size is 0.125 |
|
118 |
static const char* const qglslPositionWithPatternBrushVertexShader = "\ |
|
119 |
attribute highp vec4 vertexCoordsArray; \ |
|
120 |
uniform highp mat4 pmvMatrix; \ |
|
121 |
uniform mediump vec2 halfViewportSize; \ |
|
122 |
uniform highp vec2 invertedTextureSize; \ |
|
123 |
uniform highp mat3 brushTransform; \ |
|
124 |
varying highp vec2 patternTexCoords; \ |
|
125 |
void setPosition(void) { \ |
|
126 |
gl_Position = pmvMatrix * vertexCoordsArray;\ |
|
127 |
gl_Position.xy = gl_Position.xy / gl_Position.w; \ |
|
128 |
mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \ |
|
129 |
mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \ |
|
130 |
mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \ |
|
131 |
gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \ |
|
132 |
gl_Position.w = invertedHTexCoordsZ; \ |
|
133 |
patternTexCoords.xy = (hTexCoords.xy * 0.125) * invertedHTexCoordsZ; \ |
|
134 |
}"; |
|
135 |
||
136 |
static const char* const qglslAffinePositionWithPatternBrushVertexShader |
|
137 |
= qglslPositionWithPatternBrushVertexShader; |
|
138 |
||
139 |
static const char* const qglslPatternBrushSrcFragmentShader = "\ |
|
140 |
uniform lowp sampler2D brushTexture;\ |
|
141 |
uniform lowp vec4 patternColor; \ |
|
142 |
varying highp vec2 patternTexCoords;\ |
|
143 |
lowp vec4 srcPixel() { \ |
|
144 |
return patternColor * (1.0 - texture2D(brushTexture, patternTexCoords).r); \ |
|
145 |
}\n"; |
|
146 |
||
147 |
||
148 |
// Linear Gradient Brush |
|
149 |
static const char* const qglslPositionWithLinearGradientBrushVertexShader = "\ |
|
150 |
attribute highp vec4 vertexCoordsArray; \ |
|
151 |
uniform highp mat4 pmvMatrix; \ |
|
152 |
uniform mediump vec2 halfViewportSize; \ |
|
153 |
uniform highp vec3 linearData; \ |
|
154 |
uniform highp mat3 brushTransform; \ |
|
155 |
varying mediump float index; \ |
|
156 |
void setPosition() { \ |
|
157 |
gl_Position = pmvMatrix * vertexCoordsArray;\ |
|
158 |
gl_Position.xy = gl_Position.xy / gl_Position.w; \ |
|
159 |
mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \ |
|
160 |
mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \ |
|
161 |
mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \ |
|
162 |
gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \ |
|
163 |
gl_Position.w = invertedHTexCoordsZ; \ |
|
164 |
index = (dot(linearData.xy, hTexCoords.xy) * linearData.z) * invertedHTexCoordsZ; \ |
|
165 |
}"; |
|
166 |
||
167 |
static const char* const qglslAffinePositionWithLinearGradientBrushVertexShader |
|
168 |
= qglslPositionWithLinearGradientBrushVertexShader; |
|
169 |
||
170 |
static const char* const qglslLinearGradientBrushSrcFragmentShader = "\ |
|
171 |
uniform lowp sampler2D brushTexture; \ |
|
172 |
varying mediump float index; \ |
|
173 |
lowp vec4 srcPixel() { \ |
|
174 |
mediump vec2 val = vec2(index, 0.5); \ |
|
175 |
return texture2D(brushTexture, val); \ |
|
176 |
}\n"; |
|
177 |
||
178 |
||
179 |
// Conical Gradient Brush |
|
180 |
static const char* const qglslPositionWithConicalGradientBrushVertexShader = "\ |
|
181 |
attribute highp vec4 vertexCoordsArray;\ |
|
182 |
uniform highp mat4 pmvMatrix;\ |
|
183 |
uniform mediump vec2 halfViewportSize; \ |
|
184 |
uniform highp mat3 brushTransform; \ |
|
185 |
varying highp vec2 A; \ |
|
186 |
void setPosition(void)\ |
|
187 |
{\ |
|
188 |
gl_Position = pmvMatrix * vertexCoordsArray;\ |
|
189 |
gl_Position.xy = gl_Position.xy / gl_Position.w; \ |
|
190 |
mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \ |
|
191 |
mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \ |
|
192 |
mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \ |
|
193 |
gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \ |
|
194 |
gl_Position.w = invertedHTexCoordsZ; \ |
|
195 |
A = hTexCoords.xy * invertedHTexCoordsZ; \ |
|
196 |
}"; |
|
197 |
||
198 |
static const char* const qglslAffinePositionWithConicalGradientBrushVertexShader |
|
199 |
= qglslPositionWithConicalGradientBrushVertexShader; |
|
200 |
||
201 |
static const char* const qglslConicalGradientBrushSrcFragmentShader = "\n\ |
|
202 |
#define INVERSE_2PI 0.1591549430918953358 \n\ |
|
203 |
uniform lowp sampler2D brushTexture; \n\ |
|
204 |
uniform mediump float angle; \ |
|
205 |
varying highp vec2 A; \ |
|
206 |
lowp vec4 srcPixel() { \ |
|
207 |
highp float t; \ |
|
208 |
if (abs(A.y) == abs(A.x)) \ |
|
209 |
t = (atan(-A.y + 0.002, A.x) + angle) * INVERSE_2PI; \ |
|
210 |
else \ |
|
211 |
t = (atan(-A.y, A.x) + angle) * INVERSE_2PI; \ |
|
212 |
return texture2D(brushTexture, vec2(t - floor(t), 0.5)); \ |
|
213 |
}"; |
|
214 |
||
215 |
||
216 |
// Radial Gradient Brush |
|
217 |
static const char* const qglslPositionWithRadialGradientBrushVertexShader = "\ |
|
218 |
attribute highp vec4 vertexCoordsArray;\ |
|
219 |
uniform highp mat4 pmvMatrix;\ |
|
220 |
uniform mediump vec2 halfViewportSize; \ |
|
221 |
uniform highp mat3 brushTransform; \ |
|
222 |
uniform highp vec2 fmp; \ |
|
223 |
varying highp float b; \ |
|
224 |
varying highp vec2 A; \ |
|
225 |
void setPosition(void) \ |
|
226 |
{\ |
|
227 |
gl_Position = pmvMatrix * vertexCoordsArray;\ |
|
228 |
gl_Position.xy = gl_Position.xy / gl_Position.w; \ |
|
229 |
mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \ |
|
230 |
mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \ |
|
231 |
mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \ |
|
232 |
gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \ |
|
233 |
gl_Position.w = invertedHTexCoordsZ; \ |
|
234 |
A = hTexCoords.xy * invertedHTexCoordsZ; \ |
|
235 |
b = 2.0 * dot(A, fmp); \ |
|
236 |
}"; |
|
237 |
||
238 |
static const char* const qglslAffinePositionWithRadialGradientBrushVertexShader |
|
239 |
= qglslPositionWithRadialGradientBrushVertexShader; |
|
240 |
||
241 |
static const char* const qglslRadialGradientBrushSrcFragmentShader = "\ |
|
242 |
uniform lowp sampler2D brushTexture; \ |
|
243 |
uniform highp float fmp2_m_radius2; \ |
|
244 |
uniform highp float inverse_2_fmp2_m_radius2; \ |
|
245 |
varying highp float b; \ |
|
246 |
varying highp vec2 A; \ |
|
247 |
lowp vec4 srcPixel() { \ |
|
248 |
highp float c = -dot(A, A); \ |
|
249 |
highp vec2 val = vec2((-b + sqrt(b*b - 4.0*fmp2_m_radius2*c)) * inverse_2_fmp2_m_radius2, 0.5); \ |
|
250 |
return texture2D(brushTexture, val); \ |
|
251 |
}"; |
|
252 |
||
253 |
||
254 |
// Texture Brush |
|
255 |
static const char* const qglslPositionWithTextureBrushVertexShader = "\ |
|
256 |
attribute highp vec4 vertexCoordsArray; \ |
|
257 |
uniform highp mat4 pmvMatrix; \ |
|
258 |
uniform mediump vec2 halfViewportSize; \ |
|
259 |
uniform highp vec2 invertedTextureSize; \ |
|
260 |
uniform highp mat3 brushTransform; \ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
261 |
varying highp vec2 textureCoords; \ |
0 | 262 |
void setPosition(void) { \ |
263 |
gl_Position = pmvMatrix * vertexCoordsArray;\ |
|
264 |
gl_Position.xy = gl_Position.xy / gl_Position.w; \ |
|
265 |
mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \ |
|
266 |
mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \ |
|
267 |
mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \ |
|
268 |
gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \ |
|
269 |
gl_Position.w = invertedHTexCoordsZ; \ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
270 |
textureCoords.xy = (hTexCoords.xy * invertedTextureSize) * gl_Position.w; \ |
0 | 271 |
}"; |
272 |
||
273 |
static const char* const qglslAffinePositionWithTextureBrushVertexShader |
|
274 |
= qglslPositionWithTextureBrushVertexShader; |
|
275 |
||
276 |
#if defined(QT_OPENGL_ES_2) |
|
277 |
// OpenGL ES does not support GL_REPEAT wrap modes for NPOT textures. So instead, |
|
278 |
// we emulate GL_REPEAT by only taking the fractional part of the texture coords. |
|
279 |
// TODO: Special case POT textures which don't need this emulation |
|
280 |
static const char* const qglslTextureBrushSrcFragmentShader = "\ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
281 |
varying highp vec2 textureCoords; \ |
0 | 282 |
uniform lowp sampler2D brushTexture; \ |
283 |
lowp vec4 srcPixel() { \ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
284 |
return texture2D(brushTexture, fract(textureCoords)); \ |
0 | 285 |
}"; |
286 |
#else |
|
287 |
static const char* const qglslTextureBrushSrcFragmentShader = "\ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
288 |
varying highp vec2 textureCoords; \ |
0 | 289 |
uniform lowp sampler2D brushTexture; \ |
290 |
lowp vec4 srcPixel() { \ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
291 |
return texture2D(brushTexture, textureCoords); \ |
0 | 292 |
}"; |
293 |
#endif |
|
294 |
||
295 |
static const char* const qglslTextureBrushSrcWithPatternFragmentShader = "\ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
296 |
varying highp vec2 textureCoords; \ |
0 | 297 |
uniform lowp vec4 patternColor; \ |
298 |
uniform lowp sampler2D brushTexture; \ |
|
299 |
lowp vec4 srcPixel() { \ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
300 |
return patternColor * (1.0 - texture2D(brushTexture, textureCoords).r); \ |
0 | 301 |
}"; |
302 |
||
303 |
// Solid Fill Brush |
|
304 |
static const char* const qglslSolidBrushSrcFragmentShader = "\ |
|
305 |
uniform lowp vec4 fragmentColor; \ |
|
306 |
lowp vec4 srcPixel() { \ |
|
307 |
return fragmentColor; \ |
|
308 |
}"; |
|
309 |
||
310 |
static const char* const qglslImageSrcFragmentShader = "\ |
|
311 |
varying highp vec2 textureCoords; \ |
|
312 |
uniform lowp sampler2D imageTexture; \ |
|
313 |
lowp vec4 srcPixel() { \ |
|
314 |
return texture2D(imageTexture, textureCoords); \ |
|
315 |
}"; |
|
316 |
||
317 |
static const char* const qglslCustomSrcFragmentShader = "\ |
|
318 |
varying highp vec2 textureCoords; \ |
|
319 |
uniform lowp sampler2D imageTexture; \ |
|
320 |
lowp vec4 customShader(lowp sampler2D texture, highp vec2 coords); \ |
|
321 |
lowp vec4 srcPixel() { \ |
|
322 |
return customShader(imageTexture, textureCoords); \ |
|
323 |
}"; |
|
324 |
||
325 |
static const char* const qglslImageSrcWithPatternFragmentShader = "\ |
|
326 |
varying highp vec2 textureCoords; \ |
|
327 |
uniform lowp vec4 patternColor; \ |
|
328 |
uniform lowp sampler2D imageTexture; \ |
|
329 |
lowp vec4 srcPixel() { \ |
|
330 |
return patternColor * (1.0 - texture2D(imageTexture, textureCoords).r); \ |
|
331 |
}\n"; |
|
332 |
||
333 |
static const char* const qglslNonPremultipliedImageSrcFragmentShader = "\ |
|
334 |
varying highp vec2 textureCoords; \ |
|
335 |
uniform lowp sampler2D imageTexture; \ |
|
336 |
lowp vec4 srcPixel() { \ |
|
337 |
lowp vec4 sample = texture2D(imageTexture, textureCoords); \ |
|
338 |
sample.rgb = sample.rgb * sample.a; \ |
|
339 |
return sample; \ |
|
340 |
}"; |
|
341 |
||
342 |
static const char* const qglslShockingPinkSrcFragmentShader = "\ |
|
343 |
lowp vec4 srcPixel() { \ |
|
344 |
return vec4(0.98, 0.06, 0.75, 1.0); \ |
|
345 |
}"; |
|
346 |
||
347 |
static const char* const qglslMainFragmentShader_ImageArrays = "\ |
|
348 |
varying lowp float opacity; \ |
|
349 |
lowp vec4 srcPixel(); \ |
|
350 |
void main() { \ |
|
351 |
gl_FragColor = srcPixel() * opacity; \ |
|
352 |
}"; |
|
353 |
||
354 |
static const char* const qglslMainFragmentShader_CMO = "\ |
|
355 |
uniform lowp float globalOpacity; \ |
|
356 |
lowp vec4 srcPixel(); \ |
|
357 |
lowp vec4 applyMask(lowp vec4); \ |
|
358 |
lowp vec4 compose(lowp vec4); \ |
|
359 |
void main() { \ |
|
360 |
gl_FragColor = applyMask(compose(srcPixel()*globalOpacity))); \ |
|
361 |
}"; |
|
362 |
||
363 |
static const char* const qglslMainFragmentShader_CM = "\ |
|
364 |
lowp vec4 srcPixel(); \ |
|
365 |
lowp vec4 applyMask(lowp vec4); \ |
|
366 |
lowp vec4 compose(lowp vec4); \ |
|
367 |
void main() { \ |
|
368 |
gl_FragColor = applyMask(compose(srcPixel())); \ |
|
369 |
}"; |
|
370 |
||
371 |
static const char* const qglslMainFragmentShader_MO = "\ |
|
372 |
uniform lowp float globalOpacity; \ |
|
373 |
lowp vec4 srcPixel(); \ |
|
374 |
lowp vec4 applyMask(lowp vec4); \ |
|
375 |
void main() { \ |
|
376 |
gl_FragColor = applyMask(srcPixel()*globalOpacity); \ |
|
377 |
}"; |
|
378 |
||
379 |
static const char* const qglslMainFragmentShader_M = "\ |
|
380 |
lowp vec4 srcPixel(); \ |
|
381 |
lowp vec4 applyMask(lowp vec4); \ |
|
382 |
void main() { \ |
|
383 |
gl_FragColor = applyMask(srcPixel()); \ |
|
384 |
}"; |
|
385 |
||
386 |
static const char* const qglslMainFragmentShader_CO = "\ |
|
387 |
uniform lowp float globalOpacity; \ |
|
388 |
lowp vec4 srcPixel(); \ |
|
389 |
lowp vec4 compose(lowp vec4); \ |
|
390 |
void main() { \ |
|
391 |
gl_FragColor = compose(srcPixel()*globalOpacity); \ |
|
392 |
}"; |
|
393 |
||
394 |
static const char* const qglslMainFragmentShader_C = "\ |
|
395 |
lowp vec4 srcPixel(); \ |
|
396 |
lowp vec4 compose(lowp vec4); \ |
|
397 |
void main() { \ |
|
398 |
gl_FragColor = compose(srcPixel()); \ |
|
399 |
}"; |
|
400 |
||
401 |
static const char* const qglslMainFragmentShader_O = "\ |
|
402 |
uniform lowp float globalOpacity; \ |
|
403 |
lowp vec4 srcPixel(); \ |
|
404 |
void main() { \ |
|
405 |
gl_FragColor = srcPixel()*globalOpacity; \ |
|
406 |
}"; |
|
407 |
||
408 |
static const char* const qglslMainFragmentShader = "\ |
|
409 |
lowp vec4 srcPixel(); \ |
|
410 |
void main() { \ |
|
411 |
gl_FragColor = srcPixel(); \ |
|
412 |
}"; |
|
413 |
||
414 |
static const char* const qglslMaskFragmentShader = "\ |
|
415 |
varying highp vec2 textureCoords;\ |
|
416 |
uniform lowp sampler2D maskTexture;\ |
|
417 |
lowp vec4 applyMask(lowp vec4 src) \ |
|
418 |
{\ |
|
419 |
lowp vec4 mask = texture2D(maskTexture, textureCoords); \ |
|
420 |
return src * mask.a; \ |
|
421 |
}"; |
|
422 |
||
423 |
// For source over with subpixel antialiasing, the final color is calculated per component as follows |
|
424 |
// (.a is alpha component, .c is red, green or blue component): |
|
425 |
// alpha = src.a * mask.c * opacity |
|
426 |
// dest.c = dest.c * (1 - alpha) + src.c * alpha |
|
427 |
// |
|
428 |
// In the first pass, calculate: dest.c = dest.c * (1 - alpha) with blend funcs: zero, 1 - source color |
|
429 |
// In the second pass, calculate: dest.c = dest.c + src.c * alpha with blend funcs: one, one |
|
430 |
// |
|
431 |
// If source is a solid color (src is constant), only the first pass is needed, with blend funcs: constant, 1 - source color |
|
432 |
||
433 |
// For source composition with subpixel antialiasing, the final color is calculated per component as follows: |
|
434 |
// alpha = src.a * mask.c * opacity |
|
435 |
// dest.c = dest.c * (1 - mask.c) + src.c * alpha |
|
436 |
// |
|
437 |
||
438 |
static const char* const qglslRgbMaskFragmentShaderPass1 = "\ |
|
439 |
varying highp vec2 textureCoords;\ |
|
440 |
uniform lowp sampler2D maskTexture;\ |
|
441 |
lowp vec4 applyMask(lowp vec4 src) \ |
|
442 |
{\ |
|
443 |
lowp vec4 mask = texture2D(maskTexture, textureCoords); \ |
|
444 |
return src.a * mask; \ |
|
445 |
}"; |
|
446 |
||
447 |
static const char* const qglslRgbMaskFragmentShaderPass2 = "\ |
|
448 |
varying highp vec2 textureCoords;\ |
|
449 |
uniform lowp sampler2D maskTexture;\ |
|
450 |
lowp vec4 applyMask(lowp vec4 src) \ |
|
451 |
{\ |
|
452 |
lowp vec4 mask = texture2D(maskTexture, textureCoords); \ |
|
453 |
return src * mask; \ |
|
454 |
}"; |
|
455 |
||
456 |
/* |
|
457 |
Left to implement: |
|
458 |
RgbMaskFragmentShader, |
|
459 |
RgbMaskWithGammaFragmentShader, |
|
460 |
||
461 |
MultiplyCompositionModeFragmentShader, |
|
462 |
ScreenCompositionModeFragmentShader, |
|
463 |
OverlayCompositionModeFragmentShader, |
|
464 |
DarkenCompositionModeFragmentShader, |
|
465 |
LightenCompositionModeFragmentShader, |
|
466 |
ColorDodgeCompositionModeFragmentShader, |
|
467 |
ColorBurnCompositionModeFragmentShader, |
|
468 |
HardLightCompositionModeFragmentShader, |
|
469 |
SoftLightCompositionModeFragmentShader, |
|
470 |
DifferenceCompositionModeFragmentShader, |
|
471 |
ExclusionCompositionModeFragmentShader, |
|
472 |
*/ |
|
473 |
||
474 |
QT_END_NAMESPACE |
|
475 |
||
476 |
QT_END_HEADER |
|
477 |
||
478 |
#endif // GLGC_SHADER_SOURCE_H |