author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 3 | 41300fa6a67c |
child 5 | d3bac044e0f0 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
102 |
// NOTE: We let GL do the perspective correction so texture lookups in the fragment |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
103 |
// shader are also perspective corrected. |
0 | 104 |
static const char* const qglslPositionOnlyVertexShader = "\ |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
105 |
attribute highp vec2 vertexCoordsArray;\ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
106 |
uniform highp mat3 pmvMatrix;\ |
0 | 107 |
void setPosition(void)\ |
108 |
{\ |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
109 |
vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
110 |
gl_Position = vec4(transformedPos.xy, 0.0, transformedPos.z); \ |
0 | 111 |
}"; |
112 |
||
113 |
static const char* const qglslUntransformedPositionVertexShader = "\ |
|
114 |
attribute highp vec4 vertexCoordsArray;\ |
|
115 |
void setPosition(void)\ |
|
116 |
{\ |
|
117 |
gl_Position = vertexCoordsArray;\ |
|
118 |
}"; |
|
119 |
||
120 |
// Pattern Brush - This assumes the texture size is 8x8 and thus, the inverted size is 0.125 |
|
121 |
static const char* const qglslPositionWithPatternBrushVertexShader = "\ |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
122 |
attribute highp vec2 vertexCoordsArray; \ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
123 |
uniform highp mat3 pmvMatrix; \ |
0 | 124 |
uniform mediump vec2 halfViewportSize; \ |
125 |
uniform highp vec2 invertedTextureSize; \ |
|
126 |
uniform highp mat3 brushTransform; \ |
|
127 |
varying highp vec2 patternTexCoords; \ |
|
128 |
void setPosition(void) { \ |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
129 |
vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
130 |
gl_Position.xy = transformedPos.xy / transformedPos.z; \ |
0 | 131 |
mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \ |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
132 |
mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1.0); \ |
0 | 133 |
mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \ |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
134 |
gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \ |
0 | 135 |
patternTexCoords.xy = (hTexCoords.xy * 0.125) * invertedHTexCoordsZ; \ |
136 |
}"; |
|
137 |
||
138 |
static const char* const qglslAffinePositionWithPatternBrushVertexShader |
|
139 |
= qglslPositionWithPatternBrushVertexShader; |
|
140 |
||
141 |
static const char* const qglslPatternBrushSrcFragmentShader = "\ |
|
142 |
uniform lowp sampler2D brushTexture;\ |
|
143 |
uniform lowp vec4 patternColor; \ |
|
144 |
varying highp vec2 patternTexCoords;\ |
|
145 |
lowp vec4 srcPixel() { \ |
|
146 |
return patternColor * (1.0 - texture2D(brushTexture, patternTexCoords).r); \ |
|
147 |
}\n"; |
|
148 |
||
149 |
||
150 |
// Linear Gradient Brush |
|
151 |
static const char* const qglslPositionWithLinearGradientBrushVertexShader = "\ |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
152 |
attribute highp vec2 vertexCoordsArray; \ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
153 |
uniform highp mat3 pmvMatrix; \ |
0 | 154 |
uniform mediump vec2 halfViewportSize; \ |
155 |
uniform highp vec3 linearData; \ |
|
156 |
uniform highp mat3 brushTransform; \ |
|
157 |
varying mediump float index; \ |
|
158 |
void setPosition() { \ |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
159 |
vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
160 |
gl_Position.xy = transformedPos.xy / transformedPos.z; \ |
0 | 161 |
mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \ |
162 |
mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \ |
|
163 |
mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \ |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
164 |
gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \ |
0 | 165 |
index = (dot(linearData.xy, hTexCoords.xy) * linearData.z) * invertedHTexCoordsZ; \ |
166 |
}"; |
|
167 |
||
168 |
static const char* const qglslAffinePositionWithLinearGradientBrushVertexShader |
|
169 |
= qglslPositionWithLinearGradientBrushVertexShader; |
|
170 |
||
171 |
static const char* const qglslLinearGradientBrushSrcFragmentShader = "\ |
|
172 |
uniform lowp sampler2D brushTexture; \ |
|
173 |
varying mediump float index; \ |
|
174 |
lowp vec4 srcPixel() { \ |
|
175 |
mediump vec2 val = vec2(index, 0.5); \ |
|
176 |
return texture2D(brushTexture, val); \ |
|
177 |
}\n"; |
|
178 |
||
179 |
||
180 |
// Conical Gradient Brush |
|
181 |
static const char* const qglslPositionWithConicalGradientBrushVertexShader = "\ |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
182 |
attribute highp vec2 vertexCoordsArray;\ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
183 |
uniform highp mat3 pmvMatrix;\ |
0 | 184 |
uniform mediump vec2 halfViewportSize; \ |
185 |
uniform highp mat3 brushTransform; \ |
|
186 |
varying highp vec2 A; \ |
|
187 |
void setPosition(void)\ |
|
188 |
{\ |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
189 |
vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
190 |
gl_Position.xy = transformedPos.xy / transformedPos.z; \ |
0 | 191 |
mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \ |
192 |
mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \ |
|
193 |
mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \ |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
194 |
gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \ |
0 | 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 = "\ |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
218 |
attribute highp vec2 vertexCoordsArray;\ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
219 |
uniform highp mat3 pmvMatrix;\ |
0 | 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 |
{\ |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
227 |
vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
228 |
gl_Position.xy = transformedPos.xy / transformedPos.z; \ |
0 | 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; \ |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
232 |
gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \ |
0 | 233 |
A = hTexCoords.xy * invertedHTexCoordsZ; \ |
234 |
b = 2.0 * dot(A, fmp); \ |
|
235 |
}"; |
|
236 |
||
237 |
static const char* const qglslAffinePositionWithRadialGradientBrushVertexShader |
|
238 |
= qglslPositionWithRadialGradientBrushVertexShader; |
|
239 |
||
240 |
static const char* const qglslRadialGradientBrushSrcFragmentShader = "\ |
|
241 |
uniform lowp sampler2D brushTexture; \ |
|
242 |
uniform highp float fmp2_m_radius2; \ |
|
243 |
uniform highp float inverse_2_fmp2_m_radius2; \ |
|
244 |
varying highp float b; \ |
|
245 |
varying highp vec2 A; \ |
|
246 |
lowp vec4 srcPixel() { \ |
|
247 |
highp float c = -dot(A, A); \ |
|
248 |
highp vec2 val = vec2((-b + sqrt(b*b - 4.0*fmp2_m_radius2*c)) * inverse_2_fmp2_m_radius2, 0.5); \ |
|
249 |
return texture2D(brushTexture, val); \ |
|
250 |
}"; |
|
251 |
||
252 |
||
253 |
// Texture Brush |
|
254 |
static const char* const qglslPositionWithTextureBrushVertexShader = "\ |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
255 |
attribute highp vec2 vertexCoordsArray; \ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
256 |
uniform highp mat3 pmvMatrix; \ |
0 | 257 |
uniform mediump vec2 halfViewportSize; \ |
258 |
uniform highp vec2 invertedTextureSize; \ |
|
259 |
uniform highp mat3 brushTransform; \ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
260 |
varying highp vec2 textureCoords; \ |
0 | 261 |
void setPosition(void) { \ |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
262 |
vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
263 |
gl_Position.xy = transformedPos.xy / transformedPos.z; \ |
0 | 264 |
mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \ |
265 |
mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \ |
|
266 |
mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \ |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
267 |
gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \ |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
268 |
textureCoords.xy = (hTexCoords.xy * invertedTextureSize) * gl_Position.w; \ |
0 | 269 |
}"; |
270 |
||
271 |
static const char* const qglslAffinePositionWithTextureBrushVertexShader |
|
272 |
= qglslPositionWithTextureBrushVertexShader; |
|
273 |
||
274 |
#if defined(QT_OPENGL_ES_2) |
|
275 |
// OpenGL ES does not support GL_REPEAT wrap modes for NPOT textures. So instead, |
|
276 |
// we emulate GL_REPEAT by only taking the fractional part of the texture coords. |
|
277 |
// TODO: Special case POT textures which don't need this emulation |
|
278 |
static const char* const qglslTextureBrushSrcFragmentShader = "\ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
279 |
varying highp vec2 textureCoords; \ |
0 | 280 |
uniform lowp sampler2D brushTexture; \ |
281 |
lowp vec4 srcPixel() { \ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
282 |
return texture2D(brushTexture, fract(textureCoords)); \ |
0 | 283 |
}"; |
284 |
#else |
|
285 |
static const char* const qglslTextureBrushSrcFragmentShader = "\ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
286 |
varying highp vec2 textureCoords; \ |
0 | 287 |
uniform lowp sampler2D brushTexture; \ |
288 |
lowp vec4 srcPixel() { \ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
289 |
return texture2D(brushTexture, textureCoords); \ |
0 | 290 |
}"; |
291 |
#endif |
|
292 |
||
293 |
static const char* const qglslTextureBrushSrcWithPatternFragmentShader = "\ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
294 |
varying highp vec2 textureCoords; \ |
0 | 295 |
uniform lowp vec4 patternColor; \ |
296 |
uniform lowp sampler2D brushTexture; \ |
|
297 |
lowp vec4 srcPixel() { \ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
298 |
return patternColor * (1.0 - texture2D(brushTexture, textureCoords).r); \ |
0 | 299 |
}"; |
300 |
||
301 |
// Solid Fill Brush |
|
302 |
static const char* const qglslSolidBrushSrcFragmentShader = "\ |
|
303 |
uniform lowp vec4 fragmentColor; \ |
|
304 |
lowp vec4 srcPixel() { \ |
|
305 |
return fragmentColor; \ |
|
306 |
}"; |
|
307 |
||
308 |
static const char* const qglslImageSrcFragmentShader = "\ |
|
309 |
varying highp vec2 textureCoords; \ |
|
310 |
uniform lowp sampler2D imageTexture; \ |
|
311 |
lowp vec4 srcPixel() { \ |
|
312 |
return texture2D(imageTexture, textureCoords); \ |
|
313 |
}"; |
|
314 |
||
315 |
static const char* const qglslCustomSrcFragmentShader = "\ |
|
316 |
varying highp vec2 textureCoords; \ |
|
317 |
uniform lowp sampler2D imageTexture; \ |
|
318 |
lowp vec4 customShader(lowp sampler2D texture, highp vec2 coords); \ |
|
319 |
lowp vec4 srcPixel() { \ |
|
320 |
return customShader(imageTexture, textureCoords); \ |
|
321 |
}"; |
|
322 |
||
323 |
static const char* const qglslImageSrcWithPatternFragmentShader = "\ |
|
324 |
varying highp vec2 textureCoords; \ |
|
325 |
uniform lowp vec4 patternColor; \ |
|
326 |
uniform lowp sampler2D imageTexture; \ |
|
327 |
lowp vec4 srcPixel() { \ |
|
328 |
return patternColor * (1.0 - texture2D(imageTexture, textureCoords).r); \ |
|
329 |
}\n"; |
|
330 |
||
331 |
static const char* const qglslNonPremultipliedImageSrcFragmentShader = "\ |
|
332 |
varying highp vec2 textureCoords; \ |
|
333 |
uniform lowp sampler2D imageTexture; \ |
|
334 |
lowp vec4 srcPixel() { \ |
|
335 |
lowp vec4 sample = texture2D(imageTexture, textureCoords); \ |
|
336 |
sample.rgb = sample.rgb * sample.a; \ |
|
337 |
return sample; \ |
|
338 |
}"; |
|
339 |
||
340 |
static const char* const qglslShockingPinkSrcFragmentShader = "\ |
|
341 |
lowp vec4 srcPixel() { \ |
|
342 |
return vec4(0.98, 0.06, 0.75, 1.0); \ |
|
343 |
}"; |
|
344 |
||
345 |
static const char* const qglslMainFragmentShader_ImageArrays = "\ |
|
346 |
varying lowp float opacity; \ |
|
347 |
lowp vec4 srcPixel(); \ |
|
348 |
void main() { \ |
|
349 |
gl_FragColor = srcPixel() * opacity; \ |
|
350 |
}"; |
|
351 |
||
352 |
static const char* const qglslMainFragmentShader_CMO = "\ |
|
353 |
uniform lowp float globalOpacity; \ |
|
354 |
lowp vec4 srcPixel(); \ |
|
355 |
lowp vec4 applyMask(lowp vec4); \ |
|
356 |
lowp vec4 compose(lowp vec4); \ |
|
357 |
void main() { \ |
|
358 |
gl_FragColor = applyMask(compose(srcPixel()*globalOpacity))); \ |
|
359 |
}"; |
|
360 |
||
361 |
static const char* const qglslMainFragmentShader_CM = "\ |
|
362 |
lowp vec4 srcPixel(); \ |
|
363 |
lowp vec4 applyMask(lowp vec4); \ |
|
364 |
lowp vec4 compose(lowp vec4); \ |
|
365 |
void main() { \ |
|
366 |
gl_FragColor = applyMask(compose(srcPixel())); \ |
|
367 |
}"; |
|
368 |
||
369 |
static const char* const qglslMainFragmentShader_MO = "\ |
|
370 |
uniform lowp float globalOpacity; \ |
|
371 |
lowp vec4 srcPixel(); \ |
|
372 |
lowp vec4 applyMask(lowp vec4); \ |
|
373 |
void main() { \ |
|
374 |
gl_FragColor = applyMask(srcPixel()*globalOpacity); \ |
|
375 |
}"; |
|
376 |
||
377 |
static const char* const qglslMainFragmentShader_M = "\ |
|
378 |
lowp vec4 srcPixel(); \ |
|
379 |
lowp vec4 applyMask(lowp vec4); \ |
|
380 |
void main() { \ |
|
381 |
gl_FragColor = applyMask(srcPixel()); \ |
|
382 |
}"; |
|
383 |
||
384 |
static const char* const qglslMainFragmentShader_CO = "\ |
|
385 |
uniform lowp float globalOpacity; \ |
|
386 |
lowp vec4 srcPixel(); \ |
|
387 |
lowp vec4 compose(lowp vec4); \ |
|
388 |
void main() { \ |
|
389 |
gl_FragColor = compose(srcPixel()*globalOpacity); \ |
|
390 |
}"; |
|
391 |
||
392 |
static const char* const qglslMainFragmentShader_C = "\ |
|
393 |
lowp vec4 srcPixel(); \ |
|
394 |
lowp vec4 compose(lowp vec4); \ |
|
395 |
void main() { \ |
|
396 |
gl_FragColor = compose(srcPixel()); \ |
|
397 |
}"; |
|
398 |
||
399 |
static const char* const qglslMainFragmentShader_O = "\ |
|
400 |
uniform lowp float globalOpacity; \ |
|
401 |
lowp vec4 srcPixel(); \ |
|
402 |
void main() { \ |
|
403 |
gl_FragColor = srcPixel()*globalOpacity; \ |
|
404 |
}"; |
|
405 |
||
406 |
static const char* const qglslMainFragmentShader = "\ |
|
407 |
lowp vec4 srcPixel(); \ |
|
408 |
void main() { \ |
|
409 |
gl_FragColor = srcPixel(); \ |
|
410 |
}"; |
|
411 |
||
412 |
static const char* const qglslMaskFragmentShader = "\ |
|
413 |
varying highp vec2 textureCoords;\ |
|
414 |
uniform lowp sampler2D maskTexture;\ |
|
415 |
lowp vec4 applyMask(lowp vec4 src) \ |
|
416 |
{\ |
|
417 |
lowp vec4 mask = texture2D(maskTexture, textureCoords); \ |
|
418 |
return src * mask.a; \ |
|
419 |
}"; |
|
420 |
||
421 |
// For source over with subpixel antialiasing, the final color is calculated per component as follows |
|
422 |
// (.a is alpha component, .c is red, green or blue component): |
|
423 |
// alpha = src.a * mask.c * opacity |
|
424 |
// dest.c = dest.c * (1 - alpha) + src.c * alpha |
|
425 |
// |
|
426 |
// In the first pass, calculate: dest.c = dest.c * (1 - alpha) with blend funcs: zero, 1 - source color |
|
427 |
// In the second pass, calculate: dest.c = dest.c + src.c * alpha with blend funcs: one, one |
|
428 |
// |
|
429 |
// If source is a solid color (src is constant), only the first pass is needed, with blend funcs: constant, 1 - source color |
|
430 |
||
431 |
// For source composition with subpixel antialiasing, the final color is calculated per component as follows: |
|
432 |
// alpha = src.a * mask.c * opacity |
|
433 |
// dest.c = dest.c * (1 - mask.c) + src.c * alpha |
|
434 |
// |
|
435 |
||
436 |
static const char* const qglslRgbMaskFragmentShaderPass1 = "\ |
|
437 |
varying highp vec2 textureCoords;\ |
|
438 |
uniform lowp sampler2D maskTexture;\ |
|
439 |
lowp vec4 applyMask(lowp vec4 src) \ |
|
440 |
{\ |
|
441 |
lowp vec4 mask = texture2D(maskTexture, textureCoords); \ |
|
442 |
return src.a * mask; \ |
|
443 |
}"; |
|
444 |
||
445 |
static const char* const qglslRgbMaskFragmentShaderPass2 = "\ |
|
446 |
varying highp vec2 textureCoords;\ |
|
447 |
uniform lowp sampler2D maskTexture;\ |
|
448 |
lowp vec4 applyMask(lowp vec4 src) \ |
|
449 |
{\ |
|
450 |
lowp vec4 mask = texture2D(maskTexture, textureCoords); \ |
|
451 |
return src * mask; \ |
|
452 |
}"; |
|
453 |
||
454 |
/* |
|
455 |
Left to implement: |
|
456 |
RgbMaskFragmentShader, |
|
457 |
RgbMaskWithGammaFragmentShader, |
|
458 |
||
459 |
MultiplyCompositionModeFragmentShader, |
|
460 |
ScreenCompositionModeFragmentShader, |
|
461 |
OverlayCompositionModeFragmentShader, |
|
462 |
DarkenCompositionModeFragmentShader, |
|
463 |
LightenCompositionModeFragmentShader, |
|
464 |
ColorDodgeCompositionModeFragmentShader, |
|
465 |
ColorBurnCompositionModeFragmentShader, |
|
466 |
HardLightCompositionModeFragmentShader, |
|
467 |
SoftLightCompositionModeFragmentShader, |
|
468 |
DifferenceCompositionModeFragmentShader, |
|
469 |
ExclusionCompositionModeFragmentShader, |
|
470 |
*/ |
|
471 |
||
472 |
QT_END_NAMESPACE |
|
473 |
||
474 |
QT_END_HEADER |
|
475 |
||
476 |
#endif // GLGC_SHADER_SOURCE_H |