| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 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 qglslComplexGeometryPositionOnlyVertexShader = "\n\
|
|---|
| 111 | uniform highp mat3 matrix; \n\
|
|---|
| 112 | attribute highp vec2 vertexCoordsArray; \n\
|
|---|
| 113 | void setPosition(void) \n\
|
|---|
| 114 | { \n\
|
|---|
| 115 | gl_Position = vec4(matrix * vec3(vertexCoordsArray, 1), 1);\n\
|
|---|
| 116 | } \n";
|
|---|
| 117 |
|
|---|
| 118 | static const char* const qglslUntransformedPositionVertexShader = "\n\
|
|---|
| 119 | attribute highp vec4 vertexCoordsArray; \n\
|
|---|
| 120 | void setPosition(void) \n\
|
|---|
| 121 | { \n\
|
|---|
| 122 | gl_Position = vertexCoordsArray; \n\
|
|---|
| 123 | }\n";
|
|---|
| 124 |
|
|---|
| 125 | // Pattern Brush - This assumes the texture size is 8x8 and thus, the inverted size is 0.125
|
|---|
| 126 | static const char* const qglslPositionWithPatternBrushVertexShader = "\n\
|
|---|
| 127 | attribute highp vec2 vertexCoordsArray; \n\
|
|---|
| 128 | attribute highp vec3 pmvMatrix1; \n\
|
|---|
| 129 | attribute highp vec3 pmvMatrix2; \n\
|
|---|
| 130 | attribute highp vec3 pmvMatrix3; \n\
|
|---|
| 131 | uniform mediump vec2 halfViewportSize; \n\
|
|---|
| 132 | uniform highp vec2 invertedTextureSize; \n\
|
|---|
| 133 | uniform highp mat3 brushTransform; \n\
|
|---|
| 134 | varying highp vec2 patternTexCoords; \n\
|
|---|
| 135 | void setPosition(void) \n\
|
|---|
| 136 | { \n\
|
|---|
| 137 | highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
|
|---|
| 138 | vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
|
|---|
| 139 | gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
|
|---|
| 140 | mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
|
|---|
| 141 | mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1.0); \n\
|
|---|
| 142 | mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
|
|---|
| 143 | gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
|
|---|
| 144 | patternTexCoords.xy = (hTexCoords.xy * 0.125) * invertedHTexCoordsZ; \n\
|
|---|
| 145 | }\n";
|
|---|
| 146 |
|
|---|
| 147 | static const char* const qglslAffinePositionWithPatternBrushVertexShader
|
|---|
| 148 | = qglslPositionWithPatternBrushVertexShader;
|
|---|
| 149 |
|
|---|
| 150 | static const char* const qglslPatternBrushSrcFragmentShader = "\n\
|
|---|
| 151 | uniform lowp sampler2D brushTexture; \n\
|
|---|
| 152 | uniform lowp vec4 patternColor; \n\
|
|---|
| 153 | varying highp vec2 patternTexCoords;\n\
|
|---|
| 154 | lowp vec4 srcPixel() \n\
|
|---|
| 155 | { \n\
|
|---|
| 156 | return patternColor * (1.0 - texture2D(brushTexture, patternTexCoords).r); \n\
|
|---|
| 157 | }\n";
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 | // Linear Gradient Brush
|
|---|
| 161 | static const char* const qglslPositionWithLinearGradientBrushVertexShader = "\n\
|
|---|
| 162 | attribute highp vec2 vertexCoordsArray; \n\
|
|---|
| 163 | attribute highp vec3 pmvMatrix1; \n\
|
|---|
| 164 | attribute highp vec3 pmvMatrix2; \n\
|
|---|
| 165 | attribute highp vec3 pmvMatrix3; \n\
|
|---|
| 166 | uniform mediump vec2 halfViewportSize; \n\
|
|---|
| 167 | uniform highp vec3 linearData; \n\
|
|---|
| 168 | uniform highp mat3 brushTransform; \n\
|
|---|
| 169 | varying mediump float index; \n\
|
|---|
| 170 | void setPosition() \n\
|
|---|
| 171 | { \n\
|
|---|
| 172 | highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
|
|---|
| 173 | vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
|
|---|
| 174 | gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
|
|---|
| 175 | mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
|
|---|
| 176 | mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \n\
|
|---|
| 177 | mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
|
|---|
| 178 | gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
|
|---|
| 179 | index = (dot(linearData.xy, hTexCoords.xy) * linearData.z) * invertedHTexCoordsZ; \n\
|
|---|
| 180 | }\n";
|
|---|
| 181 |
|
|---|
| 182 | static const char* const qglslAffinePositionWithLinearGradientBrushVertexShader
|
|---|
| 183 | = qglslPositionWithLinearGradientBrushVertexShader;
|
|---|
| 184 |
|
|---|
| 185 | static const char* const qglslLinearGradientBrushSrcFragmentShader = "\n\
|
|---|
| 186 | uniform lowp sampler2D brushTexture; \n\
|
|---|
| 187 | varying mediump float index; \n\
|
|---|
| 188 | lowp vec4 srcPixel() \n\
|
|---|
| 189 | { \n\
|
|---|
| 190 | mediump vec2 val = vec2(index, 0.5); \n\
|
|---|
| 191 | return texture2D(brushTexture, val); \n\
|
|---|
| 192 | }\n";
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 | // Conical Gradient Brush
|
|---|
| 196 | static const char* const qglslPositionWithConicalGradientBrushVertexShader = "\n\
|
|---|
| 197 | attribute highp vec2 vertexCoordsArray; \n\
|
|---|
| 198 | attribute highp vec3 pmvMatrix1; \n\
|
|---|
| 199 | attribute highp vec3 pmvMatrix2; \n\
|
|---|
| 200 | attribute highp vec3 pmvMatrix3; \n\
|
|---|
| 201 | uniform mediump vec2 halfViewportSize; \n\
|
|---|
| 202 | uniform highp mat3 brushTransform; \n\
|
|---|
| 203 | varying highp vec2 A; \n\
|
|---|
| 204 | void setPosition(void) \n\
|
|---|
| 205 | { \n\
|
|---|
| 206 | highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
|
|---|
| 207 | vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
|
|---|
| 208 | gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
|
|---|
| 209 | mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
|
|---|
| 210 | mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \n\
|
|---|
| 211 | mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
|
|---|
| 212 | gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
|
|---|
| 213 | A = hTexCoords.xy * invertedHTexCoordsZ; \n\
|
|---|
| 214 | }\n";
|
|---|
| 215 |
|
|---|
| 216 | static const char* const qglslAffinePositionWithConicalGradientBrushVertexShader
|
|---|
| 217 | = qglslPositionWithConicalGradientBrushVertexShader;
|
|---|
| 218 |
|
|---|
| 219 | static const char* const qglslConicalGradientBrushSrcFragmentShader = "\n\
|
|---|
| 220 | #define INVERSE_2PI 0.1591549430918953358 \n\
|
|---|
| 221 | uniform lowp sampler2D brushTexture; \n\
|
|---|
| 222 | uniform mediump float angle; \n\
|
|---|
| 223 | varying highp vec2 A; \n\
|
|---|
| 224 | lowp vec4 srcPixel() \n\
|
|---|
| 225 | { \n\
|
|---|
| 226 | highp float t; \n\
|
|---|
| 227 | if (abs(A.y) == abs(A.x)) \n\
|
|---|
| 228 | t = (atan(-A.y + 0.002, A.x) + angle) * INVERSE_2PI; \n\
|
|---|
| 229 | else \n\
|
|---|
| 230 | t = (atan(-A.y, A.x) + angle) * INVERSE_2PI; \n\
|
|---|
| 231 | return texture2D(brushTexture, vec2(t - floor(t), 0.5)); \n\
|
|---|
| 232 | }\n";
|
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 | // Radial Gradient Brush
|
|---|
| 236 | static const char* const qglslPositionWithRadialGradientBrushVertexShader = "\n\
|
|---|
| 237 | attribute highp vec2 vertexCoordsArray;\n\
|
|---|
| 238 | attribute highp vec3 pmvMatrix1; \n\
|
|---|
| 239 | attribute highp vec3 pmvMatrix2; \n\
|
|---|
| 240 | attribute highp vec3 pmvMatrix3; \n\
|
|---|
| 241 | uniform mediump vec2 halfViewportSize; \n\
|
|---|
| 242 | uniform highp mat3 brushTransform; \n\
|
|---|
| 243 | uniform highp vec2 fmp; \n\
|
|---|
| 244 | varying highp float b; \n\
|
|---|
| 245 | varying highp vec2 A; \n\
|
|---|
| 246 | void setPosition(void) \n\
|
|---|
| 247 | {\n\
|
|---|
| 248 | highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
|
|---|
| 249 | vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
|
|---|
| 250 | gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
|
|---|
| 251 | mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
|
|---|
| 252 | mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \n\
|
|---|
| 253 | mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
|
|---|
| 254 | gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
|
|---|
| 255 | A = hTexCoords.xy * invertedHTexCoordsZ; \n\
|
|---|
| 256 | b = 2.0 * dot(A, fmp); \n\
|
|---|
| 257 | }\n";
|
|---|
| 258 |
|
|---|
| 259 | static const char* const qglslAffinePositionWithRadialGradientBrushVertexShader
|
|---|
| 260 | = qglslPositionWithRadialGradientBrushVertexShader;
|
|---|
| 261 |
|
|---|
| 262 | static const char* const qglslRadialGradientBrushSrcFragmentShader = "\n\
|
|---|
| 263 | uniform lowp sampler2D brushTexture; \n\
|
|---|
| 264 | uniform highp float fmp2_m_radius2; \n\
|
|---|
| 265 | uniform highp float inverse_2_fmp2_m_radius2; \n\
|
|---|
| 266 | varying highp float b; \n\
|
|---|
| 267 | varying highp vec2 A; \n\
|
|---|
| 268 | lowp vec4 srcPixel() \n\
|
|---|
| 269 | { \n\
|
|---|
| 270 | highp float c = -dot(A, A); \n\
|
|---|
| 271 | highp vec2 val = vec2((-b + sqrt(b*b - 4.0*fmp2_m_radius2*c)) * inverse_2_fmp2_m_radius2, 0.5); \n\
|
|---|
| 272 | return texture2D(brushTexture, val); \n\
|
|---|
| 273 | }\n";
|
|---|
| 274 |
|
|---|
| 275 |
|
|---|
| 276 | // Texture Brush
|
|---|
| 277 | static const char* const qglslPositionWithTextureBrushVertexShader = "\n\
|
|---|
| 278 | attribute highp vec2 vertexCoordsArray; \n\
|
|---|
| 279 | attribute highp vec3 pmvMatrix1; \n\
|
|---|
| 280 | attribute highp vec3 pmvMatrix2; \n\
|
|---|
| 281 | attribute highp vec3 pmvMatrix3; \n\
|
|---|
| 282 | uniform mediump vec2 halfViewportSize; \n\
|
|---|
| 283 | uniform highp vec2 invertedTextureSize; \n\
|
|---|
| 284 | uniform highp mat3 brushTransform; \n\
|
|---|
| 285 | varying highp vec2 brushTextureCoords; \n\
|
|---|
| 286 | void setPosition(void) \n\
|
|---|
| 287 | { \n\
|
|---|
| 288 | highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
|
|---|
| 289 | vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
|
|---|
| 290 | gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
|
|---|
| 291 | mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
|
|---|
| 292 | mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \n\
|
|---|
| 293 | mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
|
|---|
| 294 | gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
|
|---|
| 295 | brushTextureCoords.xy = (hTexCoords.xy * invertedTextureSize) * gl_Position.w; \n\
|
|---|
| 296 | }\n";
|
|---|
| 297 |
|
|---|
| 298 | static const char* const qglslAffinePositionWithTextureBrushVertexShader
|
|---|
| 299 | = qglslPositionWithTextureBrushVertexShader;
|
|---|
| 300 |
|
|---|
| 301 | #if defined(QT_OPENGL_ES_2)
|
|---|
| 302 | // OpenGL ES does not support GL_REPEAT wrap modes for NPOT textures. So instead,
|
|---|
| 303 | // we emulate GL_REPEAT by only taking the fractional part of the texture coords.
|
|---|
| 304 | // TODO: Special case POT textures which don't need this emulation
|
|---|
| 305 | static const char* const qglslTextureBrushSrcFragmentShader = "\n\
|
|---|
| 306 | varying highp vec2 brushTextureCoords; \n\
|
|---|
| 307 | uniform lowp sampler2D brushTexture; \n\
|
|---|
| 308 | lowp vec4 srcPixel() { \n\
|
|---|
| 309 | return texture2D(brushTexture, fract(brushTextureCoords)); \n\
|
|---|
| 310 | }\n";
|
|---|
| 311 | #else
|
|---|
| 312 | static const char* const qglslTextureBrushSrcFragmentShader = "\n\
|
|---|
| 313 | varying highp vec2 brushTextureCoords; \n\
|
|---|
| 314 | uniform lowp sampler2D brushTexture; \n\
|
|---|
| 315 | lowp vec4 srcPixel() \n\
|
|---|
| 316 | { \n\
|
|---|
| 317 | return texture2D(brushTexture, brushTextureCoords); \n\
|
|---|
| 318 | }\n";
|
|---|
| 319 | #endif
|
|---|
| 320 |
|
|---|
| 321 | static const char* const qglslTextureBrushSrcWithPatternFragmentShader = "\n\
|
|---|
| 322 | varying highp vec2 brushTextureCoords; \n\
|
|---|
| 323 | uniform lowp vec4 patternColor; \n\
|
|---|
| 324 | uniform lowp sampler2D brushTexture; \n\
|
|---|
| 325 | lowp vec4 srcPixel() \n\
|
|---|
| 326 | { \n\
|
|---|
| 327 | return patternColor * (1.0 - texture2D(brushTexture, brushTextureCoords).r); \n\
|
|---|
| 328 | }\n";
|
|---|
| 329 |
|
|---|
| 330 | // Solid Fill Brush
|
|---|
| 331 | static const char* const qglslSolidBrushSrcFragmentShader = "\n\
|
|---|
| 332 | uniform lowp vec4 fragmentColor; \n\
|
|---|
| 333 | lowp vec4 srcPixel() \n\
|
|---|
| 334 | { \n\
|
|---|
| 335 | return fragmentColor; \n\
|
|---|
| 336 | }\n";
|
|---|
| 337 |
|
|---|
| 338 | static const char* const qglslImageSrcFragmentShader = "\n\
|
|---|
| 339 | varying highp vec2 textureCoords; \n\
|
|---|
| 340 | uniform lowp sampler2D imageTexture; \n\
|
|---|
| 341 | lowp vec4 srcPixel() \n\
|
|---|
| 342 | { \n"
|
|---|
| 343 | "return texture2D(imageTexture, textureCoords); \n"
|
|---|
| 344 | "}\n";
|
|---|
| 345 |
|
|---|
| 346 | static const char* const qglslCustomSrcFragmentShader = "\n\
|
|---|
| 347 | varying highp vec2 textureCoords; \n\
|
|---|
| 348 | uniform lowp sampler2D imageTexture; \n\
|
|---|
| 349 | lowp vec4 srcPixel() \n\
|
|---|
| 350 | { \n\
|
|---|
| 351 | return customShader(imageTexture, textureCoords); \n\
|
|---|
| 352 | }\n";
|
|---|
| 353 |
|
|---|
| 354 | static const char* const qglslImageSrcWithPatternFragmentShader = "\n\
|
|---|
| 355 | varying highp vec2 textureCoords; \n\
|
|---|
| 356 | uniform lowp vec4 patternColor; \n\
|
|---|
| 357 | uniform lowp sampler2D imageTexture; \n\
|
|---|
| 358 | lowp vec4 srcPixel() \n\
|
|---|
| 359 | { \n\
|
|---|
| 360 | return patternColor * (1.0 - texture2D(imageTexture, textureCoords).r); \n\
|
|---|
| 361 | }\n";
|
|---|
| 362 |
|
|---|
| 363 | static const char* const qglslNonPremultipliedImageSrcFragmentShader = "\n\
|
|---|
| 364 | varying highp vec2 textureCoords; \n\
|
|---|
| 365 | uniform lowp sampler2D imageTexture; \n\
|
|---|
| 366 | lowp vec4 srcPixel() \n\
|
|---|
| 367 | { \n\
|
|---|
| 368 | lowp vec4 sample = texture2D(imageTexture, textureCoords); \n\
|
|---|
| 369 | sample.rgb = sample.rgb * sample.a; \n\
|
|---|
| 370 | return sample; \n\
|
|---|
| 371 | }\n";
|
|---|
| 372 |
|
|---|
| 373 | static const char* const qglslShockingPinkSrcFragmentShader = "\n\
|
|---|
| 374 | lowp vec4 srcPixel() \n\
|
|---|
| 375 | { \n\
|
|---|
| 376 | return vec4(0.98, 0.06, 0.75, 1.0); \n\
|
|---|
| 377 | }\n";
|
|---|
| 378 |
|
|---|
| 379 | static const char* const qglslMainFragmentShader_ImageArrays = "\n\
|
|---|
| 380 | varying lowp float opacity; \n\
|
|---|
| 381 | lowp vec4 srcPixel(); \n\
|
|---|
| 382 | void main() \n\
|
|---|
| 383 | { \n\
|
|---|
| 384 | gl_FragColor = srcPixel() * opacity; \n\
|
|---|
| 385 | }\n";
|
|---|
| 386 |
|
|---|
| 387 | static const char* const qglslMainFragmentShader_CMO = "\n\
|
|---|
| 388 | uniform lowp float globalOpacity; \n\
|
|---|
| 389 | lowp vec4 srcPixel(); \n\
|
|---|
| 390 | lowp vec4 applyMask(lowp vec4); \n\
|
|---|
| 391 | lowp vec4 compose(lowp vec4); \n\
|
|---|
| 392 | void main() \n\
|
|---|
| 393 | { \n\
|
|---|
| 394 | gl_FragColor = applyMask(compose(srcPixel()*globalOpacity))); \n\
|
|---|
| 395 | }\n";
|
|---|
| 396 |
|
|---|
| 397 | static const char* const qglslMainFragmentShader_CM = "\n\
|
|---|
| 398 | lowp vec4 srcPixel(); \n\
|
|---|
| 399 | lowp vec4 applyMask(lowp vec4); \n\
|
|---|
| 400 | lowp vec4 compose(lowp vec4); \n\
|
|---|
| 401 | void main() \n\
|
|---|
| 402 | { \n\
|
|---|
| 403 | gl_FragColor = applyMask(compose(srcPixel())); \n\
|
|---|
| 404 | }\n";
|
|---|
| 405 |
|
|---|
| 406 | static const char* const qglslMainFragmentShader_MO = "\n\
|
|---|
| 407 | uniform lowp float globalOpacity; \n\
|
|---|
| 408 | lowp vec4 srcPixel(); \n\
|
|---|
| 409 | lowp vec4 applyMask(lowp vec4); \n\
|
|---|
| 410 | void main() \n\
|
|---|
| 411 | { \n\
|
|---|
| 412 | gl_FragColor = applyMask(srcPixel()*globalOpacity); \n\
|
|---|
| 413 | }\n";
|
|---|
| 414 |
|
|---|
| 415 | static const char* const qglslMainFragmentShader_M = "\n\
|
|---|
| 416 | lowp vec4 srcPixel(); \n\
|
|---|
| 417 | lowp vec4 applyMask(lowp vec4); \n\
|
|---|
| 418 | void main() \n\
|
|---|
| 419 | { \n\
|
|---|
| 420 | gl_FragColor = applyMask(srcPixel()); \n\
|
|---|
| 421 | }\n";
|
|---|
| 422 |
|
|---|
| 423 | static const char* const qglslMainFragmentShader_CO = "\n\
|
|---|
| 424 | uniform lowp float globalOpacity; \n\
|
|---|
| 425 | lowp vec4 srcPixel(); \n\
|
|---|
| 426 | lowp vec4 compose(lowp vec4); \n\
|
|---|
| 427 | void main() \n\
|
|---|
| 428 | { \n\
|
|---|
| 429 | gl_FragColor = compose(srcPixel()*globalOpacity); \n\
|
|---|
| 430 | }\n";
|
|---|
| 431 |
|
|---|
| 432 | static const char* const qglslMainFragmentShader_C = "\n\
|
|---|
| 433 | lowp vec4 srcPixel(); \n\
|
|---|
| 434 | lowp vec4 compose(lowp vec4); \n\
|
|---|
| 435 | void main() \n\
|
|---|
| 436 | { \n\
|
|---|
| 437 | gl_FragColor = compose(srcPixel()); \n\
|
|---|
| 438 | }\n";
|
|---|
| 439 |
|
|---|
| 440 | static const char* const qglslMainFragmentShader_O = "\n\
|
|---|
| 441 | uniform lowp float globalOpacity; \n\
|
|---|
| 442 | lowp vec4 srcPixel(); \n\
|
|---|
| 443 | void main() \n\
|
|---|
| 444 | { \n\
|
|---|
| 445 | gl_FragColor = srcPixel()*globalOpacity; \n\
|
|---|
| 446 | }\n";
|
|---|
| 447 |
|
|---|
| 448 | static const char* const qglslMainFragmentShader = "\n\
|
|---|
| 449 | lowp vec4 srcPixel(); \n\
|
|---|
| 450 | void main() \n\
|
|---|
| 451 | { \n\
|
|---|
| 452 | gl_FragColor = srcPixel(); \n\
|
|---|
| 453 | }\n";
|
|---|
| 454 |
|
|---|
| 455 | static const char* const qglslMaskFragmentShader = "\n\
|
|---|
| 456 | varying highp vec2 textureCoords;\n\
|
|---|
| 457 | uniform lowp sampler2D maskTexture;\n\
|
|---|
| 458 | lowp vec4 applyMask(lowp vec4 src) \n\
|
|---|
| 459 | {\n\
|
|---|
| 460 | lowp vec4 mask = texture2D(maskTexture, textureCoords); \n\
|
|---|
| 461 | return src * mask.a; \n\
|
|---|
| 462 | }\n";
|
|---|
| 463 |
|
|---|
| 464 | // For source over with subpixel antialiasing, the final color is calculated per component as follows
|
|---|
| 465 | // (.a is alpha component, .c is red, green or blue component):
|
|---|
| 466 | // alpha = src.a * mask.c * opacity
|
|---|
| 467 | // dest.c = dest.c * (1 - alpha) + src.c * alpha
|
|---|
| 468 | //
|
|---|
| 469 | // In the first pass, calculate: dest.c = dest.c * (1 - alpha) with blend funcs: zero, 1 - source color
|
|---|
| 470 | // In the second pass, calculate: dest.c = dest.c + src.c * alpha with blend funcs: one, one
|
|---|
| 471 | //
|
|---|
| 472 | // If source is a solid color (src is constant), only the first pass is needed, with blend funcs: constant, 1 - source color
|
|---|
| 473 |
|
|---|
| 474 | // For source composition with subpixel antialiasing, the final color is calculated per component as follows:
|
|---|
| 475 | // alpha = src.a * mask.c * opacity
|
|---|
| 476 | // dest.c = dest.c * (1 - mask.c) + src.c * alpha
|
|---|
| 477 | //
|
|---|
| 478 |
|
|---|
| 479 | static const char* const qglslRgbMaskFragmentShaderPass1 = "\n\
|
|---|
| 480 | varying highp vec2 textureCoords;\n\
|
|---|
| 481 | uniform lowp sampler2D maskTexture;\n\
|
|---|
| 482 | lowp vec4 applyMask(lowp vec4 src) \n\
|
|---|
| 483 | { \n\
|
|---|
| 484 | lowp vec4 mask = texture2D(maskTexture, textureCoords); \n\
|
|---|
| 485 | return src.a * mask; \n\
|
|---|
| 486 | }\n";
|
|---|
| 487 |
|
|---|
| 488 | static const char* const qglslRgbMaskFragmentShaderPass2 = "\n\
|
|---|
| 489 | varying highp vec2 textureCoords;\n\
|
|---|
| 490 | uniform lowp sampler2D maskTexture;\n\
|
|---|
| 491 | lowp vec4 applyMask(lowp vec4 src) \n\
|
|---|
| 492 | { \n\
|
|---|
| 493 | lowp vec4 mask = texture2D(maskTexture, textureCoords); \n\
|
|---|
| 494 | return src * mask; \n\
|
|---|
| 495 | }\n";
|
|---|
| 496 |
|
|---|
| 497 | /*
|
|---|
| 498 | Left to implement:
|
|---|
| 499 | RgbMaskFragmentShader,
|
|---|
| 500 | RgbMaskWithGammaFragmentShader,
|
|---|
| 501 |
|
|---|
| 502 | MultiplyCompositionModeFragmentShader,
|
|---|
| 503 | ScreenCompositionModeFragmentShader,
|
|---|
| 504 | OverlayCompositionModeFragmentShader,
|
|---|
| 505 | DarkenCompositionModeFragmentShader,
|
|---|
| 506 | LightenCompositionModeFragmentShader,
|
|---|
| 507 | ColorDodgeCompositionModeFragmentShader,
|
|---|
| 508 | ColorBurnCompositionModeFragmentShader,
|
|---|
| 509 | HardLightCompositionModeFragmentShader,
|
|---|
| 510 | SoftLightCompositionModeFragmentShader,
|
|---|
| 511 | DifferenceCompositionModeFragmentShader,
|
|---|
| 512 | ExclusionCompositionModeFragmentShader,
|
|---|
| 513 | */
|
|---|
| 514 |
|
|---|
| 515 | QT_END_NAMESPACE
|
|---|
| 516 |
|
|---|
| 517 | QT_END_HEADER
|
|---|
| 518 |
|
|---|
| 519 | #endif // GLGC_SHADER_SOURCE_H
|
|---|