From 5e97ccf7e08864ece4ca964a137eb1ad0f431cab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B6glund?= Date: Thu, 10 Feb 2011 20:15:23 +0100 Subject: [PATCH] kwin: Normalize the texcoords in the vertex shader --- effects/cube/data/cylinder.frag | 9 +-------- effects/cube/data/cylinder.vert | 4 +++- effects/explosion/data/explosion.frag | 3 ++- effects/invert/data/invert.frag | 8 +------- scene-fragment.glsl | 10 +--------- scene-generic-vertex.glsl | 5 ++++- scene-vertex.glsl | 5 ++++- 7 files changed, 16 insertions(+), 28 deletions(-) diff --git a/effects/cube/data/cylinder.frag b/effects/cube/data/cylinder.frag index 1f60f36428..2b4c876bf9 100644 --- a/effects/cube/data/cylinder.frag +++ b/effects/cube/data/cylinder.frag @@ -1,20 +1,13 @@ uniform sampler2D sample; -uniform float textureWidth; -uniform float textureHeight; uniform float opacity; uniform float brightness; uniform float saturation; varying vec2 varyingTexCoords; -vec2 pix2tex(vec2 pix) -{ - return vec2(pix.x / textureWidth, pix.y / textureHeight); -} - void main() { - vec4 tex = texture2D(sample, pix2tex(varyingTexCoords)); + vec4 tex = texture2D(sample, varyingTexCoords); if( saturation != 1.0 ) { vec3 desaturated = tex.rgb * vec3( 0.30, 0.59, 0.11 ); diff --git a/effects/cube/data/cylinder.vert b/effects/cube/data/cylinder.vert index de540c5773..5d685d368a 100644 --- a/effects/cube/data/cylinder.vert +++ b/effects/cube/data/cylinder.vert @@ -25,6 +25,8 @@ uniform float width; uniform float cubeAngle; uniform float xCoord; uniform float timeLine; +uniform float textureWidth; +uniform float textureHeight; attribute vec4 vertex; attribute vec2 texCoord; @@ -33,7 +35,7 @@ varying vec2 varyingTexCoords; void main() { - varyingTexCoords = texCoord; + varyingTexCoords = texCoord / vec2(textureWidth, textureHeight); vec4 transformedVertex = vec4(vertex.x - ( width - xCoord ), vertex.yzw); float radian = radians(cubeAngle); float radius = (width)*tan(radian); diff --git a/effects/explosion/data/explosion.frag b/effects/explosion/data/explosion.frag index f58caefb8d..eb017b40b5 100644 --- a/effects/explosion/data/explosion.frag +++ b/effects/explosion/data/explosion.frag @@ -23,7 +23,8 @@ vec2 pix2tex( vec2 pix ) void main() { // Original (unscaled) position in pixels - vec2 origpos = varyingTexCoords; + // ### FIXME: Use a custom vertex shader that outputs the untransformed texcoords + vec2 origpos = varyingTexCoords * vec2(textureWidth, textureHeight); // Position in pixels on the scaled window vec2 pos = origpos * scale; // Start/end position of current region diff --git a/effects/invert/data/invert.frag b/effects/invert/data/invert.frag index 2276a918c1..5429465e27 100644 --- a/effects/invert/data/invert.frag +++ b/effects/invert/data/invert.frag @@ -8,15 +8,9 @@ uniform int u_forceAlpha; varying vec2 varyingTexCoords; -// Converts pixel coordinates to texture coordinates -vec2 pix2tex( vec2 pix ) -{ - return vec2( pix.s / textureWidth, pix.t / textureHeight ); -} - void main() { - vec4 tex = texture2D( sample, pix2tex( varyingTexCoords )); + vec4 tex = texture2D(sample, varyingTexCoords); if( saturation != 1.0 ) { vec3 desaturated = tex.rgb * vec3( 0.30, 0.59, 0.11 ); diff --git a/scene-fragment.glsl b/scene-fragment.glsl index ee3884ecaa..fde4ed7455 100644 --- a/scene-fragment.glsl +++ b/scene-fragment.glsl @@ -1,6 +1,4 @@ uniform sampler2D sample; -uniform float textureWidth; -uniform float textureHeight; uniform float opacity; uniform float brightness; uniform float saturation; @@ -11,14 +9,8 @@ varying vec2 varyingTexCoords; //varying vec4 color; -// Converts pixel coordinates to texture coordinates -vec2 pix2tex( vec2 pix ) -{ - return vec2( pix.s / textureWidth, pix.t / textureHeight ); -} - void main() { - vec4 tex = texture2D(sample, pix2tex(varyingTexCoords)); + vec4 tex = texture2D(sample, varyingTexCoords); if( saturation != 1.0 ) { vec3 desaturated = tex.rgb * vec3( 0.30, 0.59, 0.11 ); desaturated = vec3( dot( desaturated, tex.rgb )); diff --git a/scene-generic-vertex.glsl b/scene-generic-vertex.glsl index b40f4d381e..6672dec5a6 100644 --- a/scene-generic-vertex.glsl +++ b/scene-generic-vertex.glsl @@ -3,6 +3,9 @@ uniform mat4 modelview; uniform mat4 screenTransformation; uniform mat4 windowTransformation; +uniform float textureWidth; +uniform float textureHeight; + // passed in vertex - only x and y are used attribute vec4 vertex; // passed in texCoords - to be forwarded @@ -12,6 +15,6 @@ attribute vec2 texCoord; varying vec2 varyingTexCoords; void main() { - varyingTexCoords = texCoord; + varyingTexCoords = texCoord / vec2(textureWidth, textureHeight); gl_Position = vertex*(windowTransformation*screenTransformation*modelview)*projection; } diff --git a/scene-vertex.glsl b/scene-vertex.glsl index d3b1c223cd..5869dcdac6 100644 --- a/scene-vertex.glsl +++ b/scene-vertex.glsl @@ -2,6 +2,9 @@ uniform mat4 projection; // offset of the window/texture to be rendered uniform vec2 offset; +uniform float textureWidth; +uniform float textureHeight; + // passed in vertex - only x and y are used attribute vec4 vertex; // passed in texCoords - to be forwarded @@ -11,6 +14,6 @@ attribute vec2 texCoord; varying vec2 varyingTexCoords; void main() { - varyingTexCoords = texCoord; + varyingTexCoords = texCoord / vec2(textureWidth, textureHeight); gl_Position = vec4(vertex.xy + offset, vertex.zw) * projection; }