From 50a80cd08330886e380f1ea5801acaca8c31fd00 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Wed, 8 Feb 2012 15:51:32 +0000 Subject: Fixed 'magnify' shader in qmlvideofx example Previous shader caused untransformed pixels (those outside of the lens) radius to be offset slightly from their original positions. Change-Id: I4df847fdc40073a55da8777981c3fdd373937658 Reviewed-by: Michael Goddard --- examples/video/qmlvideofx/shaders/magnify.fsh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/video/qmlvideofx/shaders/magnify.fsh b/examples/video/qmlvideofx/shaders/magnify.fsh index c4c25d9e0..076db1799 100644 --- a/examples/video/qmlvideofx/shaders/magnify.fsh +++ b/examples/video/qmlvideofx/shaders/magnify.fsh @@ -53,13 +53,16 @@ uniform float posY; void main() { - float h = diffractionIndex * 0.5 * radius; - vec2 targetSize = vec2(targetWidth, targetHeight); + vec2 tc = qt_TexCoord0; vec2 center = vec2(posX, posY); vec2 xy = gl_FragCoord.xy - center.xy; float r = sqrt(xy.x * xy.x + xy.y * xy.y); - vec2 new_xy = r < radius ? xy * (radius - h) / sqrt(radius * radius - r * r) : xy; - vec2 tc = (new_xy + center) / targetSize; - tc.y = 1.0 - tc.y; + if (r < radius) { + float h = diffractionIndex * 0.5 * radius; + vec2 new_xy = r < radius ? xy * (radius - h) / sqrt(radius * radius - r * r) : xy; + vec2 targetSize = vec2(targetWidth, targetHeight); + tc = (new_xy + center) / targetSize; + tc.y = 1.0 - tc.y; + } gl_FragColor = qt_Opacity * texture2D(source, tc); } -- cgit v1.2.3