1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtOpenGL module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
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 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
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 = "\n\
|
---|
67 | void setPosition(); \n\
|
---|
68 | void main(void) \n\
|
---|
69 | { \n\
|
---|
70 | setPosition(); \n\
|
---|
71 | }\n";
|
---|
72 |
|
---|
73 | static const char* const qglslMainWithTexCoordsVertexShader = "\n\
|
---|
74 | attribute highp vec2 textureCoordArray; \n\
|
---|
75 | varying highp vec2 textureCoords; \n\
|
---|
76 | void setPosition(); \n\
|
---|
77 | void main(void) \n\
|
---|
78 | { \n\
|
---|
79 | setPosition(); \n\
|
---|
80 | textureCoords = textureCoordArray; \n\
|
---|
81 | }\n";
|
---|
82 |
|
---|
83 | static const char* const qglslMainWithTexCoordsAndOpacityVertexShader = "\n\
|
---|
84 | attribute highp vec2 textureCoordArray; \n\
|
---|
85 | attribute lowp float opacityArray; \n\
|
---|
86 | varying highp vec2 textureCoords; \n\
|
---|
87 | varying lowp float opacity; \n\
|
---|
88 | void setPosition(); \n\
|
---|
89 | void main(void) \n\
|
---|
90 | { \n\
|
---|
91 | setPosition(); \n\
|
---|
92 | textureCoords = textureCoordArray; \n\
|
---|
93 | opacity = opacityArray; \n\
|
---|
94 | }\n";
|
---|
95 |
|
---|
96 | // NOTE: We let GL do the perspective correction so texture lookups in the fragment
|
---|
97 | // shader are also perspective corrected.
|
---|
98 | static const char* const qglslPositionOnlyVertexShader = "\n\
|
---|
99 | attribute highp vec2 vertexCoordsArray; \n\
|
---|
100 | attribute highp vec3 pmvMatrix1; \n\
|
---|
101 | attribute highp vec3 pmvMatrix2; \n\
|
---|
102 | attribute highp vec3 pmvMatrix3; \n\
|
---|
103 | void setPosition(void) \n\
|
---|
104 | { \n\
|
---|
105 | highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
|
---|
106 | vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
|
---|
107 | gl_Position = vec4(transformedPos.xy, 0.0, transformedPos.z); \n\
|
---|
108 | }\n";
|
---|
109 |
|
---|
110 | static const char* const qglslUntransformedPositionVertexShader = "\n\
|
---|
111 | attribute highp vec4 vertexCoordsArray; \n\
|
---|
112 | void setPosition(void) \n\
|
---|
113 | { \n\
|
---|
114 | gl_Position = vertexCoordsArray; \n\
|
---|
115 | }\n";
|
---|
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 = "\n\
|
---|
119 | attribute highp vec2 vertexCoordsArray; \n\
|
---|
120 | attribute highp vec3 pmvMatrix1; \n\
|
---|
121 | attribute highp vec3 pmvMatrix2; \n\
|
---|
122 | attribute highp vec3 pmvMatrix3; \n\
|
---|
123 | uniform mediump vec2 halfViewportSize; \n\
|
---|
124 | uniform highp vec2 invertedTextureSize; \n\
|
---|
125 | uniform highp mat3 brushTransform; \n\
|
---|
126 | varying highp vec2 patternTexCoords; \n\
|
---|
127 | void setPosition(void) \n\
|
---|
128 | { \n\
|
---|
129 | highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
|
---|
130 | vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
|
---|
131 | gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
|
---|
132 | mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
|
---|
133 | mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1.0); \n\
|
---|
134 | mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
|
---|
135 | gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
|
---|
136 | patternTexCoords.xy = (hTexCoords.xy * 0.125) * invertedHTexCoordsZ; \n\
|
---|
137 | }\n";
|
---|
138 |
|
---|
139 | static const char* const qglslAffinePositionWithPatternBrushVertexShader
|
---|
140 | = qglslPositionWithPatternBrushVertexShader;
|
---|
141 |
|
---|
142 | static const char* const qglslPatternBrushSrcFragmentShader = "\n\
|
---|
143 | uniform lowp sampler2D brushTexture; \n\
|
---|
144 | uniform lowp vec4 patternColor; \n\
|
---|
145 | varying highp vec2 patternTexCoords;\n\
|
---|
146 | lowp vec4 srcPixel() \n\
|
---|
147 | { \n\
|
---|
148 | return patternColor * (1.0 - texture2D(brushTexture, patternTexCoords).r); \n\
|
---|
149 | }\n";
|
---|
150 |
|
---|
151 |
|
---|
152 | // Linear Gradient Brush
|
---|
153 | static const char* const qglslPositionWithLinearGradientBrushVertexShader = "\n\
|
---|
154 | attribute highp vec2 vertexCoordsArray; \n\
|
---|
155 | attribute highp vec3 pmvMatrix1; \n\
|
---|
156 | attribute highp vec3 pmvMatrix2; \n\
|
---|
157 | attribute highp vec3 pmvMatrix3; \n\
|
---|
158 | uniform mediump vec2 halfViewportSize; \n\
|
---|
159 | uniform highp vec3 linearData; \n\
|
---|
160 | uniform highp mat3 brushTransform; \n\
|
---|
161 | varying mediump float index; \n\
|
---|
162 | void setPosition() \n\
|
---|
163 | { \n\
|
---|
164 | highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
|
---|
165 | vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
|
---|
166 | gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
|
---|
167 | mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
|
---|
168 | mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \n\
|
---|
169 | mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
|
---|
170 | gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
|
---|
171 | index = (dot(linearData.xy, hTexCoords.xy) * linearData.z) * invertedHTexCoordsZ; \n\
|
---|
172 | }\n";
|
---|
173 |
|
---|
174 | static const char* const qglslAffinePositionWithLinearGradientBrushVertexShader
|
---|
175 | = qglslPositionWithLinearGradientBrushVertexShader;
|
---|
176 |
|
---|
177 | static const char* const qglslLinearGradientBrushSrcFragmentShader = "\n\
|
---|
178 | uniform lowp sampler2D brushTexture; \n\
|
---|
179 | varying mediump float index; \n\
|
---|
180 | lowp vec4 srcPixel() \n\
|
---|
181 | { \n\
|
---|
182 | mediump vec2 val = vec2(index, 0.5); \n\
|
---|
183 | return texture2D(brushTexture, val); \n\
|
---|
184 | }\n";
|
---|
185 |
|
---|
186 |
|
---|
187 | // Conical Gradient Brush
|
---|
188 | static const char* const qglslPositionWithConicalGradientBrushVertexShader = "\n\
|
---|
189 | attribute highp vec2 vertexCoordsArray; \n\
|
---|
190 | attribute highp vec3 pmvMatrix1; \n\
|
---|
191 | attribute highp vec3 pmvMatrix2; \n\
|
---|
192 | attribute highp vec3 pmvMatrix3; \n\
|
---|
193 | uniform mediump vec2 halfViewportSize; \n\
|
---|
194 | uniform highp mat3 brushTransform; \n\
|
---|
195 | varying highp vec2 A; \n\
|
---|
196 | void setPosition(void) \n\
|
---|
197 | { \n\
|
---|
198 | highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
|
---|
199 | vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
|
---|
200 | gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
|
---|
201 | mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
|
---|
202 | mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \n\
|
---|
203 | mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
|
---|
204 | gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
|
---|
205 | A = hTexCoords.xy * invertedHTexCoordsZ; \n\
|
---|
206 | }\n";
|
---|
207 |
|
---|
208 | static const char* const qglslAffinePositionWithConicalGradientBrushVertexShader
|
---|
209 | = qglslPositionWithConicalGradientBrushVertexShader;
|
---|
210 |
|
---|
211 | static const char* const qglslConicalGradientBrushSrcFragmentShader = "\n\
|
---|
212 | #define INVERSE_2PI 0.1591549430918953358 \n\
|
---|
213 | uniform lowp sampler2D brushTexture; \n\
|
---|
214 | uniform mediump float angle; \n\
|
---|
215 | varying highp vec2 A; \n\
|
---|
216 | lowp vec4 srcPixel() \n\
|
---|
217 | { \n\
|
---|
218 | highp float t; \n\
|
---|
219 | if (abs(A.y) == abs(A.x)) \n\
|
---|
220 | t = (atan(-A.y + 0.002, A.x) + angle) * INVERSE_2PI; \n\
|
---|
221 | else \n\
|
---|
222 | t = (atan(-A.y, A.x) + angle) * INVERSE_2PI; \n\
|
---|
223 | return texture2D(brushTexture, vec2(t - floor(t), 0.5)); \n\
|
---|
224 | }\n";
|
---|
225 |
|
---|
226 |
|
---|
227 | // Radial Gradient Brush
|
---|
228 | static const char* const qglslPositionWithRadialGradientBrushVertexShader = "\n\
|
---|
229 | attribute highp vec2 vertexCoordsArray;\n\
|
---|
230 | attribute highp vec3 pmvMatrix1; \n\
|
---|
231 | attribute highp vec3 pmvMatrix2; \n\
|
---|
232 | attribute highp vec3 pmvMatrix3; \n\
|
---|
233 | uniform mediump vec2 halfViewportSize; \n\
|
---|
234 | uniform highp mat3 brushTransform; \n\
|
---|
235 | uniform highp vec2 fmp; \n\
|
---|
236 | varying highp float b; \n\
|
---|
237 | varying highp vec2 A; \n\
|
---|
238 | void setPosition(void) \n\
|
---|
239 | {\n\
|
---|
240 | highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
|
---|
241 | vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
|
---|
242 | gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
|
---|
243 | mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
|
---|
244 | mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \n\
|
---|
245 | mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
|
---|
246 | gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
|
---|
247 | A = hTexCoords.xy * invertedHTexCoordsZ; \n\
|
---|
248 | b = 2.0 * dot(A, fmp); \n\
|
---|
249 | }\n";
|
---|
250 |
|
---|
251 | static const char* const qglslAffinePositionWithRadialGradientBrushVertexShader
|
---|
252 | = qglslPositionWithRadialGradientBrushVertexShader;
|
---|
253 |
|
---|
254 | static const char* const qglslRadialGradientBrushSrcFragmentShader = "\n\
|
---|
255 | uniform lowp sampler2D brushTexture; \n\
|
---|
256 | uniform highp float fmp2_m_radius2; \n\
|
---|
257 | uniform highp float inverse_2_fmp2_m_radius2; \n\
|
---|
258 | varying highp float b; \n\
|
---|
259 | varying highp vec2 A; \n\
|
---|
260 | lowp vec4 srcPixel() \n\
|
---|
261 | { \n\
|
---|
262 | highp float c = -dot(A, A); \n\
|
---|
263 | highp vec2 val = vec2((-b + sqrt(b*b - 4.0*fmp2_m_radius2*c)) * inverse_2_fmp2_m_radius2, 0.5); \n\
|
---|
264 | return texture2D(brushTexture, val); \n\
|
---|
265 | }\n";
|
---|
266 |
|
---|
267 |
|
---|
268 | // Texture Brush
|
---|
269 | static const char* const qglslPositionWithTextureBrushVertexShader = "\n\
|
---|
270 | attribute highp vec2 vertexCoordsArray; \n\
|
---|
271 | attribute highp vec3 pmvMatrix1; \n\
|
---|
272 | attribute highp vec3 pmvMatrix2; \n\
|
---|
273 | attribute highp vec3 pmvMatrix3; \n\
|
---|
274 | uniform mediump vec2 halfViewportSize; \n\
|
---|
275 | uniform highp vec2 invertedTextureSize; \n\
|
---|
276 | uniform highp mat3 brushTransform; \n\
|
---|
277 | varying highp vec2 textureCoords; \n\
|
---|
278 | void setPosition(void) \n\
|
---|
279 | { \n\
|
---|
280 | highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
|
---|
281 | vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
|
---|
282 | gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
|
---|
283 | mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
|
---|
284 | mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \n\
|
---|
285 | mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
|
---|
286 | gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
|
---|
287 | textureCoords.xy = (hTexCoords.xy * invertedTextureSize) * gl_Position.w; \n\
|
---|
288 | }\n";
|
---|
289 |
|
---|
290 | static const char* const qglslAffinePositionWithTextureBrushVertexShader
|
---|
291 | = qglslPositionWithTextureBrushVertexShader;
|
---|
292 |
|
---|
293 | #if defined(QT_OPENGL_ES_2)
|
---|
294 | // OpenGL ES does not support GL_REPEAT wrap modes for NPOT textures. So instead,
|
---|
295 | // we emulate GL_REPEAT by only taking the fractional part of the texture coords.
|
---|
296 | // TODO: Special case POT textures which don't need this emulation
|
---|
297 | static const char* const qglslTextureBrushSrcFragmentShader = "\n\
|
---|
298 | varying highp vec2 textureCoords; \n\
|
---|
299 | uniform lowp sampler2D brushTexture; \n\
|
---|
300 | lowp vec4 srcPixel() { \n\
|
---|
301 | return texture2D(brushTexture, fract(textureCoords)); \n\
|
---|
302 | }\n";
|
---|
303 | #else
|
---|
304 | static const char* const qglslTextureBrushSrcFragmentShader = "\n\
|
---|
305 | varying highp vec2 textureCoords; \n\
|
---|
306 | uniform lowp sampler2D brushTexture; \n\
|
---|
307 | lowp vec4 srcPixel() \n\
|
---|
308 | { \n\
|
---|
309 | return texture2D(brushTexture, textureCoords); \n\
|
---|
310 | }\n";
|
---|
311 | #endif
|
---|
312 |
|
---|
313 | static const char* const qglslTextureBrushSrcWithPatternFragmentShader = "\n\
|
---|
314 | varying highp vec2 textureCoords; \n\
|
---|
315 | uniform lowp vec4 patternColor; \n\
|
---|
316 | uniform lowp sampler2D brushTexture; \n\
|
---|
317 | lowp vec4 srcPixel() \n\
|
---|
318 | { \n\
|
---|
319 | return patternColor * (1.0 - texture2D(brushTexture, textureCoords).r); \n\
|
---|
320 | }\n";
|
---|
321 |
|
---|
322 | // Solid Fill Brush
|
---|
323 | static const char* const qglslSolidBrushSrcFragmentShader = "\n\
|
---|
324 | uniform lowp vec4 fragmentColor; \n\
|
---|
325 | lowp vec4 srcPixel() \n\
|
---|
326 | { \n\
|
---|
327 | return fragmentColor; \n\
|
---|
328 | }\n";
|
---|
329 |
|
---|
330 | static const char* const qglslImageSrcFragmentShader = "\n\
|
---|
331 | varying highp vec2 textureCoords; \n\
|
---|
332 | uniform lowp sampler2D imageTexture; \n\
|
---|
333 | lowp vec4 srcPixel() \n\
|
---|
334 | { \n\
|
---|
335 | return texture2D(imageTexture, textureCoords); \n\
|
---|
336 | }\n";
|
---|
337 |
|
---|
338 | static const char* const qglslCustomSrcFragmentShader = "\n\
|
---|
339 | varying highp vec2 textureCoords; \n\
|
---|
340 | uniform lowp sampler2D imageTexture; \n\
|
---|
341 | lowp vec4 customShader(lowp sampler2D texture, highp vec2 coords); \n\
|
---|
342 | lowp vec4 srcPixel() \n\
|
---|
343 | { \n\
|
---|
344 | return customShader(imageTexture, textureCoords); \n\
|
---|
345 | }\n";
|
---|
346 |
|
---|
347 | static const char* const qglslImageSrcWithPatternFragmentShader = "\n\
|
---|
348 | varying highp vec2 textureCoords; \n\
|
---|
349 | uniform lowp vec4 patternColor; \n\
|
---|
350 | uniform lowp sampler2D imageTexture; \n\
|
---|
351 | lowp vec4 srcPixel() \n\
|
---|
352 | { \n\
|
---|
353 | return patternColor * (1.0 - texture2D(imageTexture, textureCoords).r); \n\
|
---|
354 | }\n";
|
---|
355 |
|
---|
356 | static const char* const qglslNonPremultipliedImageSrcFragmentShader = "\n\
|
---|
357 | varying highp vec2 textureCoords; \n\
|
---|
358 | uniform lowp sampler2D imageTexture; \n\
|
---|
359 | lowp vec4 srcPixel() \n\
|
---|
360 | { \n\
|
---|
361 | lowp vec4 sample = texture2D(imageTexture, textureCoords); \n\
|
---|
362 | sample.rgb = sample.rgb * sample.a; \n\
|
---|
363 | return sample; \n\
|
---|
364 | }\n";
|
---|
365 |
|
---|
366 | static const char* const qglslShockingPinkSrcFragmentShader = "\n\
|
---|
367 | lowp vec4 srcPixel() \n\
|
---|
368 | { \n\
|
---|
369 | return vec4(0.98, 0.06, 0.75, 1.0); \n\
|
---|
370 | }\n";
|
---|
371 |
|
---|
372 | static const char* const qglslMainFragmentShader_ImageArrays = "\n\
|
---|
373 | varying lowp float opacity; \n\
|
---|
374 | lowp vec4 srcPixel(); \n\
|
---|
375 | void main() \n\
|
---|
376 | { \n\
|
---|
377 | gl_FragColor = srcPixel() * opacity; \n\
|
---|
378 | }\n";
|
---|
379 |
|
---|
380 | static const char* const qglslMainFragmentShader_CMO = "\n\
|
---|
381 | uniform lowp float globalOpacity; \n\
|
---|
382 | lowp vec4 srcPixel(); \n\
|
---|
383 | lowp vec4 applyMask(lowp vec4); \n\
|
---|
384 | lowp vec4 compose(lowp vec4); \n\
|
---|
385 | void main() \n\
|
---|
386 | { \n\
|
---|
387 | gl_FragColor = applyMask(compose(srcPixel()*globalOpacity))); \n\
|
---|
388 | }\n";
|
---|
389 |
|
---|
390 | static const char* const qglslMainFragmentShader_CM = "\n\
|
---|
391 | lowp vec4 srcPixel(); \n\
|
---|
392 | lowp vec4 applyMask(lowp vec4); \n\
|
---|
393 | lowp vec4 compose(lowp vec4); \n\
|
---|
394 | void main() \n\
|
---|
395 | { \n\
|
---|
396 | gl_FragColor = applyMask(compose(srcPixel())); \n\
|
---|
397 | }\n";
|
---|
398 |
|
---|
399 | static const char* const qglslMainFragmentShader_MO = "\n\
|
---|
400 | uniform lowp float globalOpacity; \n\
|
---|
401 | lowp vec4 srcPixel(); \n\
|
---|
402 | lowp vec4 applyMask(lowp vec4); \n\
|
---|
403 | void main() \n\
|
---|
404 | { \n\
|
---|
405 | gl_FragColor = applyMask(srcPixel()*globalOpacity); \n\
|
---|
406 | }\n";
|
---|
407 |
|
---|
408 | static const char* const qglslMainFragmentShader_M = "\n\
|
---|
409 | lowp vec4 srcPixel(); \n\
|
---|
410 | lowp vec4 applyMask(lowp vec4); \n\
|
---|
411 | void main() \n\
|
---|
412 | { \n\
|
---|
413 | gl_FragColor = applyMask(srcPixel()); \n\
|
---|
414 | }\n";
|
---|
415 |
|
---|
416 | static const char* const qglslMainFragmentShader_CO = "\n\
|
---|
417 | uniform lowp float globalOpacity; \n\
|
---|
418 | lowp vec4 srcPixel(); \n\
|
---|
419 | lowp vec4 compose(lowp vec4); \n\
|
---|
420 | void main() \n\
|
---|
421 | { \n\
|
---|
422 | gl_FragColor = compose(srcPixel()*globalOpacity); \n\
|
---|
423 | }\n";
|
---|
424 |
|
---|
425 | static const char* const qglslMainFragmentShader_C = "\n\
|
---|
426 | lowp vec4 srcPixel(); \n\
|
---|
427 | lowp vec4 compose(lowp vec4); \n\
|
---|
428 | void main() \n\
|
---|
429 | { \n\
|
---|
430 | gl_FragColor = compose(srcPixel()); \n\
|
---|
431 | }\n";
|
---|
432 |
|
---|
433 | static const char* const qglslMainFragmentShader_O = "\n\
|
---|
434 | uniform lowp float globalOpacity; \n\
|
---|
435 | lowp vec4 srcPixel(); \n\
|
---|
436 | void main() \n\
|
---|
437 | { \n\
|
---|
438 | gl_FragColor = srcPixel()*globalOpacity; \n\
|
---|
439 | }\n";
|
---|
440 |
|
---|
441 | static const char* const qglslMainFragmentShader = "\n\
|
---|
442 | lowp vec4 srcPixel(); \n\
|
---|
443 | void main() \n\
|
---|
444 | { \n\
|
---|
445 | gl_FragColor = srcPixel(); \n\
|
---|
446 | }\n";
|
---|
447 |
|
---|
448 | static const char* const qglslMaskFragmentShader = "\n\
|
---|
449 | varying highp vec2 textureCoords;\n\
|
---|
450 | uniform lowp sampler2D maskTexture;\n\
|
---|
451 | lowp vec4 applyMask(lowp vec4 src) \n\
|
---|
452 | {\n\
|
---|
453 | lowp vec4 mask = texture2D(maskTexture, textureCoords); \n\
|
---|
454 | return src * mask.a; \n\
|
---|
455 | }\n";
|
---|
456 |
|
---|
457 | // For source over with subpixel antialiasing, the final color is calculated per component as follows
|
---|
458 | // (.a is alpha component, .c is red, green or blue component):
|
---|
459 | // alpha = src.a * mask.c * opacity
|
---|
460 | // dest.c = dest.c * (1 - alpha) + src.c * alpha
|
---|
461 | //
|
---|
462 | // In the first pass, calculate: dest.c = dest.c * (1 - alpha) with blend funcs: zero, 1 - source color
|
---|
463 | // In the second pass, calculate: dest.c = dest.c + src.c * alpha with blend funcs: one, one
|
---|
464 | //
|
---|
465 | // If source is a solid color (src is constant), only the first pass is needed, with blend funcs: constant, 1 - source color
|
---|
466 |
|
---|
467 | // For source composition with subpixel antialiasing, the final color is calculated per component as follows:
|
---|
468 | // alpha = src.a * mask.c * opacity
|
---|
469 | // dest.c = dest.c * (1 - mask.c) + src.c * alpha
|
---|
470 | //
|
---|
471 |
|
---|
472 | static const char* const qglslRgbMaskFragmentShaderPass1 = "\n\
|
---|
473 | varying highp vec2 textureCoords;\n\
|
---|
474 | uniform lowp sampler2D maskTexture;\n\
|
---|
475 | lowp vec4 applyMask(lowp vec4 src) \n\
|
---|
476 | { \n\
|
---|
477 | lowp vec4 mask = texture2D(maskTexture, textureCoords); \n\
|
---|
478 | return src.a * mask; \n\
|
---|
479 | }\n";
|
---|
480 |
|
---|
481 | static const char* const qglslRgbMaskFragmentShaderPass2 = "\n\
|
---|
482 | varying highp vec2 textureCoords;\n\
|
---|
483 | uniform lowp sampler2D maskTexture;\n\
|
---|
484 | lowp vec4 applyMask(lowp vec4 src) \n\
|
---|
485 | { \n\
|
---|
486 | lowp vec4 mask = texture2D(maskTexture, textureCoords); \n\
|
---|
487 | return src * mask; \n\
|
---|
488 | }\n";
|
---|
489 |
|
---|
490 | /*
|
---|
491 | Left to implement:
|
---|
492 | RgbMaskFragmentShader,
|
---|
493 | RgbMaskWithGammaFragmentShader,
|
---|
494 |
|
---|
495 | MultiplyCompositionModeFragmentShader,
|
---|
496 | ScreenCompositionModeFragmentShader,
|
---|
497 | OverlayCompositionModeFragmentShader,
|
---|
498 | DarkenCompositionModeFragmentShader,
|
---|
499 | LightenCompositionModeFragmentShader,
|
---|
500 | ColorDodgeCompositionModeFragmentShader,
|
---|
501 | ColorBurnCompositionModeFragmentShader,
|
---|
502 | HardLightCompositionModeFragmentShader,
|
---|
503 | SoftLightCompositionModeFragmentShader,
|
---|
504 | DifferenceCompositionModeFragmentShader,
|
---|
505 | ExclusionCompositionModeFragmentShader,
|
---|
506 | */
|
---|
507 |
|
---|
508 | QT_END_NAMESPACE
|
---|
509 |
|
---|
510 | QT_END_HEADER
|
---|
511 |
|
---|
512 | #endif // GLGC_SHADER_SOURCE_H
|
---|