1/**************************************************************************** 2** 3** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). 4** Contact: http://www.qt.io/licensing/ 5** 6** This file is part of the Qt Mobility Components. 7** 8** $QT_BEGIN_LICENSE:LGPL21$ 9** Commercial License Usage 10** Licensees holding valid commercial Qt licenses may use this file in 11** accordance with the commercial license agreement provided with the 12** Software or, alternatively, in accordance with the terms contained in 13** a written agreement between you and The Qt Company. For licensing terms 14** and conditions see http://www.qt.io/terms-conditions. For further 15** information use the contact form at http://www.qt.io/contact-us. 16** 17** GNU Lesser General Public License Usage 18** Alternatively, this file may be used under the terms of the GNU Lesser 19** General Public License version 2.1 or version 3 as published by the Free 20** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22** following information to ensure the GNU Lesser General Public License 23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25** 26** As a special exception, The Qt Company gives you certain additional 27** rights. These rights are described in The Qt Company LGPL Exception 28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29** 30** $QT_END_LICENSE$ 31** 32****************************************************************************/ 33 34// Based on http://www.geeks3d.com/20101029/shader-library-pixelation-post-processing-effect-glsl/ 35 36uniform float dividerValue; 37uniform float threshold; 38uniform float resS; 39uniform float resT; 40uniform float magTol; 41uniform float quantize; 42 43uniform sampler2D source; 44uniform lowp float qt_Opacity; 45varying vec2 qt_TexCoord0; 46 47void main() 48{ 49 vec4 color = vec4(1.0, 0.0, 0.0, 1.1); 50 vec2 uv = qt_TexCoord0.xy; 51 if (uv.x < dividerValue) { 52 vec2 st = qt_TexCoord0.st; 53 vec3 rgb = texture2D(source, st).rgb; 54 vec2 stp0 = vec2(1.0/resS, 0.0); 55 vec2 st0p = vec2(0.0 , 1.0/resT); 56 vec2 stpp = vec2(1.0/resS, 1.0/resT); 57 vec2 stpm = vec2(1.0/resS, -1.0/resT); 58 float i00 = dot( texture2D(source, st).rgb, vec3(0.2125,0.7154,0.0721)); 59 float im1m1 = dot( texture2D(source, st-stpp).rgb, vec3(0.2125,0.7154,0.0721)); 60 float ip1p1 = dot( texture2D(source, st+stpp).rgb, vec3(0.2125,0.7154,0.0721)); 61 float im1p1 = dot( texture2D(source, st-stpm).rgb, vec3(0.2125,0.7154,0.0721)); 62 float ip1m1 = dot( texture2D(source, st+stpm).rgb, vec3(0.2125,0.7154,0.0721)); 63 float im10 = dot( texture2D(source, st-stp0).rgb, vec3(0.2125,0.7154,0.0721)); 64 float ip10 = dot( texture2D(source, st+stp0).rgb, vec3(0.2125,0.7154,0.0721)); 65 float i0m1 = dot( texture2D(source, st-st0p).rgb, vec3(0.2125,0.7154,0.0721)); 66 float i0p1 = dot( texture2D(source, st+st0p).rgb, vec3(0.2125,0.7154,0.0721)); 67 float h = -1.*im1p1 - 2.*i0p1 - 1.*ip1p1 + 1.*im1m1 + 2.*i0m1 + 1.*ip1m1; 68 float v = -1.*im1m1 - 2.*im10 - 1.*im1p1 + 1.*ip1m1 + 2.*ip10 + 1.*ip1p1; 69 float mag = sqrt(h*h + v*v); 70 if (mag > magTol) { 71 color = vec4(0.0, 0.0, 0.0, 1.0); 72 } 73 else { 74 rgb.rgb *= quantize; 75 rgb.rgb += vec3(0.5, 0.5, 0.5); 76 ivec3 irgb = ivec3(rgb.rgb); 77 rgb.rgb = vec3(irgb) / quantize; 78 color = vec4(rgb, 1.0); 79 } 80 } else { 81 color = texture2D(source, uv); 82 } 83 gl_FragColor = qt_Opacity * color; 84} 85