source: trunk/src/opengl/gl2paintengineex/glgc_shader_source.h@ 353

Last change on this file since 353 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 10.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtOpenGL module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** 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 are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef GLGC_SHADER_SOURCE_H
43#define GLGC_SHADER_SOURCE_H
44
45QT_BEGIN_HEADER
46
47QT_BEGIN_NAMESPACE
48
49QT_MODULE(OpenGL)
50
51static const char* qglslImageVertexShader = "\
52 attribute highp vec4 inputVertex; \
53 attribute lowp vec2 textureCoord; \
54 uniform highp mat4 pmvMatrix; \
55 varying lowp vec2 fragTextureCoord; \
56 void main(void) \
57 {\
58 gl_Position = pmvMatrix * inputVertex;\
59 fragTextureCoord = textureCoord; \
60 }";
61
62static const char* qglslImageFragmentShader = "\
63 varying lowp vec2 fragTextureCoord;\
64 uniform sampler2D textureSampler;\
65 uniform lowp float opacity; \
66 void main(void) \
67 {\
68 gl_FragColor = texture2D(textureSampler, fragTextureCoord) * opacity; \
69 }";
70
71static const char* qglslTextFragmentShader = "\
72 varying lowp vec2 fragTextureCoord;\
73 uniform mediump vec4 fragmentColor;\
74 uniform sampler2D textureSampler;\
75 void main(void) \
76 {\
77 highp vec4 tex = texture2D(textureSampler, fragTextureCoord); \
78 tex = fragmentColor * tex.r; \
79 gl_FragColor = tex; \
80 }";
81
82static const char* qglslDefaultVertexShader = "\
83 attribute highp vec4 inputVertex;\
84 uniform highp mat4 pmvMatrix;\
85 void main(void)\
86 {\
87 gl_Position = pmvMatrix * inputVertex;\
88 }";
89
90static const char* qglslSimpleFragmentShader = "\
91 void main (void)\
92 {\
93 gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);\
94 }";
95
96
97/**** FRAGMENT SHADER MAIN FUNCTIONS ****/
98// NOTE: Currently, the engine assumes brushes return colors already in pre-multiplied
99// format. However, this may change if we add support for non-premultiplied
100
101static const char* qglslNoOpacityFragmentShaderMain = "\n\
102 mediump vec4 brush();\
103 void main (void)\
104 {\
105 gl_FragColor = brush();\
106 }\n";
107
108static const char* qglslFragmentShaderMain = "\n\
109 mediump vec4 brush();\
110 uniform lowp float opacity; \
111 void main (void)\
112 {\
113 gl_FragColor = brush() * opacity;\
114 }\n";
115
116
117
118/**** BRUSH SHADERS ****/
119
120// This should never actually be used
121static const char* qglslNoBrushFragmentShader = "\n\
122 mediump vec4 brush() { \
123 discard; \
124 return vec4(1.0, 0.8, 0.8, 1.0);\
125 }\n";
126
127// Solid Fill Brush
128static const char* qglslSolidBrushFragmentShader = "\n\
129 uniform mediump vec4 fragmentColor; \
130 mediump vec4 brush() { \
131 return fragmentColor;\
132 }\n";
133
134// Texture Brush
135static const char* qglslTextureBrushVertexShader = "\
136 attribute highp vec4 inputVertex; \
137 uniform highp mat4 pmvMatrix; \
138 uniform mediump vec2 halfViewportSize; \
139 uniform mediump vec2 invertedTextureSize; \
140 uniform mediump mat3 brushTransform; \
141 varying mediump vec2 texCoords; \
142 void main(void) { \
143 gl_Position = pmvMatrix * inputVertex;\
144 gl_Position.xy = gl_Position.xy / gl_Position.w; \
145 mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
146 mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
147 mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
148 gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \
149 gl_Position.w = invertedHTexCoordsZ; \
150 texCoords.xy = (hTexCoords.xy * invertedTextureSize) * gl_Position.w; \
151 texCoords.y = -texCoords.y; \
152 }";
153
154static const char* qglslTextureBrushFragmentShader = "\n\
155 varying mediump vec2 texCoords;\
156 uniform sampler2D brushTexture;\
157 mediump vec4 brush() { \
158 return texture2D(brushTexture, texCoords); \
159 }\n";
160
161
162// Pattern Brush - This assumes the texture size is 8x8 and thus, the inverted size is 0.125
163static const char* qglslPatternBrushVertexShader = "\
164 attribute highp vec4 inputVertex; \
165 uniform highp mat4 pmvMatrix; \
166 uniform mediump vec2 halfViewportSize; \
167 uniform mediump vec2 invertedTextureSize; \
168 uniform mediump mat3 brushTransform; \
169 varying mediump vec2 texCoords; \
170 void main(void) { \
171 gl_Position = pmvMatrix * inputVertex;\
172 gl_Position.xy = gl_Position.xy / gl_Position.w; \
173 mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
174 mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
175 mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
176 gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \
177 gl_Position.w = invertedHTexCoordsZ; \
178 texCoords.xy = (hTexCoords.xy * 0.125) * invertedHTexCoordsZ; \
179 texCoords.y = -texCoords.y; \
180 }";
181
182static const char* qglslPatternBrushFragmentShader = "\n\
183 uniform sampler2D brushTexture;\
184 uniform lowp vec4 patternColor; \
185 varying mediump vec2 texCoords;\
186 mediump vec4 brush() { \
187 return patternColor * texture2D(brushTexture, texCoords).r; \
188 }\n";
189
190
191// Linear Gradient Brush
192static const char* qglslLinearGradientBrushVertexShader = "\
193 attribute highp vec4 inputVertex; \
194 uniform highp mat4 pmvMatrix; \
195 uniform mediump vec2 halfViewportSize; \
196 uniform highp vec3 linearData; \
197 uniform mediump mat3 brushTransform; \
198 varying mediump float index ; \
199 void main() { \
200 gl_Position = pmvMatrix * inputVertex;\
201 gl_Position.xy = gl_Position.xy / gl_Position.w; \
202 mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
203 mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
204 mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
205 gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \
206 gl_Position.w = invertedHTexCoordsZ; \
207 index = (dot(linearData.xy, hTexCoords.xy) * linearData.z) * invertedHTexCoordsZ; \
208 }";
209
210static const char* qglslLinearGradientBrushFragmentShader = "\n\
211 uniform sampler2D brushTexture; \
212 varying mediump float index; \
213 mediump vec4 brush() { \
214 mediump vec2 val = vec2(index, 0.5); \
215 return texture2D(brushTexture, val); \
216 }\n";
217
218
219static const char* qglslRadialGradientBrushVertexShader = "\
220 attribute highp vec4 inputVertex;\
221 uniform highp mat4 pmvMatrix;\
222 uniform mediump vec2 halfViewportSize; \
223 uniform highp mat3 brushTransform; \
224 uniform highp vec2 fmp; \
225 varying highp float b; \
226 varying highp vec2 A; \
227 void main(void) \
228 {\
229 gl_Position = pmvMatrix * inputVertex;\
230 gl_Position.xy = gl_Position.xy / gl_Position.w; \
231 mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
232 mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
233 mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
234 gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \
235 gl_Position.w = invertedHTexCoordsZ; \
236 A = hTexCoords.xy * invertedHTexCoordsZ; \
237 b = 2.0 * fmp * (A.x + A.y); \
238\
239 }";
240
241static const char* qglslRadialGradientBrushFragmentShader = "\n\
242 uniform 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\
248 mediump vec4 brush() { \
249 highp float c = -dot(A, A); \
250 highp vec2 val = vec2((-b + sqrt(b*b - 4.0*fmp2_m_radius2*c)) * inverse_2_fmp2_m_radius2, 0.5); \
251 return texture2D(brushTexture, val); \
252 }\n";
253
254static const char* qglslConicalGradientBrushVertexShader = "\
255 attribute highp vec4 inputVertex;\
256 uniform highp mat4 pmvMatrix;\
257 uniform mediump vec2 halfViewportSize; \
258 uniform highp mat3 brushTransform; \
259 varying highp vec2 A; \
260 void main(void)\
261 {\
262 gl_Position = pmvMatrix * inputVertex;\
263 gl_Position.xy = gl_Position.xy / gl_Position.w; \
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; \
267 gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \
268 gl_Position.w = invertedHTexCoordsZ; \
269 A = hTexCoords.xy * invertedHTexCoordsZ; \
270 }";
271
272static const char* qglslConicalGradientBrushFragmentShader = "\n\
273 #define INVERSE_2PI 0.1591549430918953358 \n\
274 uniform sampler2D brushTexture; \
275 uniform mediump float angle; \
276 varying highp vec2 A; \
277 mediump vec4 brush() { \
278 if (abs(A.y) == abs(A.x)) \
279 A.y += 0.002; \
280 highp float t = (atan2(-A.y, A.x) + angle) * INVERSE_2PI; \
281 return texture2D(brushTexture, vec2(t - floor(t), 0.5)); \
282 }\n";
283
284
285QT_END_NAMESPACE
286
287QT_END_HEADER
288
289#endif // GLGC_SHADER_SOURCE_H
Note: See TracBrowser for help on using the repository browser.