aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph/shaders/smoothtexture.vert
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2013-10-26 18:48:56 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-31 12:54:28 +0100
commit426f6aa672b94d8324321bc6c6d4f1a358eebedc (patch)
tree8af3e5b0aa2fdcdb7655672669f5ae277151cc3d /src/quick/scenegraph/shaders/smoothtexture.vert
parent34c85bb56c92316a6ce1c79d25f9653fec14791c (diff)
Refactor shaders into seprate GLSL source files
The default implementation of QSGShaderMaterial::vertexShader() and fragmentShader() now loads the GLSL source from a list of source files that can be specified via the setShaderSourceFile() or setShaderSourceFiles() functions. Multiple shader source files for each shader stage are supported. Each source file will be read in the order specified and concatenated together before being compiled. The other places where Qt Quick 2 loads shader source code have been adapted to use the new QSGShaderSourceBuilder, which is also used internally by QSGMaterial. This puts Qt Quick 2 into a better state ready to support OpenGL core profile and to load different shaders based upon OpenGL version, profile, GPU vendor, platform, etc. Change-Id: I1a66213c2ce788413168eb48c7bc5317e61988a2 Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Diffstat (limited to 'src/quick/scenegraph/shaders/smoothtexture.vert')
-rw-r--r--src/quick/scenegraph/shaders/smoothtexture.vert52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/quick/scenegraph/shaders/smoothtexture.vert b/src/quick/scenegraph/shaders/smoothtexture.vert
new file mode 100644
index 0000000000..1ce824a68f
--- /dev/null
+++ b/src/quick/scenegraph/shaders/smoothtexture.vert
@@ -0,0 +1,52 @@
+uniform highp vec2 pixelSize;
+uniform highp mat4 qt_Matrix;
+uniform lowp float opacity;
+
+attribute highp vec4 vertex;
+attribute highp vec2 multiTexCoord;
+attribute highp vec2 vertexOffset;
+attribute highp vec2 texCoordOffset;
+
+varying highp vec2 texCoord;
+varying lowp float vertexOpacity;
+
+void main()
+{
+ highp vec4 pos = qt_Matrix * vertex;
+ gl_Position = pos;
+ texCoord = multiTexCoord;
+
+ if (vertexOffset.x != 0.) {
+ highp vec4 delta = qt_Matrix[0] * vertexOffset.x;
+ highp vec2 dir = delta.xy * pos.w - pos.xy * delta.w;
+ highp vec2 ndir = .5 * pixelSize * normalize(dir / pixelSize);
+ dir -= ndir * delta.w * pos.w;
+ highp float numerator = dot(dir, ndir * pos.w * pos.w);
+ highp float scale = 0.0;
+ if (numerator < 0.0)
+ scale = 1.0;
+ else
+ scale = min(1.0, numerator / dot(dir, dir));
+ gl_Position += scale * delta;
+ texCoord.x += scale * texCoordOffset.x;
+ }
+
+ if (vertexOffset.y != 0.) {
+ highp vec4 delta = qt_Matrix[1] * vertexOffset.y;
+ highp vec2 dir = delta.xy * pos.w - pos.xy * delta.w;
+ highp vec2 ndir = .5 * pixelSize * normalize(dir / pixelSize);
+ dir -= ndir * delta.w * pos.w;
+ highp float numerator = dot(dir, ndir * pos.w * pos.w);
+ highp float scale = 0.0;
+ if (numerator < 0.0)
+ scale = 1.0;
+ else
+ scale = min(1.0, numerator / dot(dir, dir));
+ gl_Position += scale * delta;
+ texCoord.y += scale * texCoordOffset.y;
+ }
+
+ bool onEdge = any(notEqual(vertexOffset, vec2(0.)));
+ bool outerEdge = all(equal(texCoordOffset, vec2(0.)));
+ vertexOpacity = onEdge && outerEdge ? 0. : opacity;
+} \ No newline at end of file