| 7 |
| uniform vec2 sz; |
| 8 | uniform int step; |
| 9 | uniform float flipy; |
| 10 |
| 11 | uniform float hasVideoMatrix; |
| 12 | uniform mat4 videoMatrix; |
| 13 |
| 14 | uniform vec4 gtop; |
| 15 | uniform vec4 gbottom; |
| 16 |
| 17 | vec4 at(vec2 p) { |
| 18 | if (step != 0) { |
| 19 | return texture2D(tex, p); |
| 20 | } |
| 21 | vec2 uv = (matrix * vec4(clamp(p, 0., 1.), 0., 1.)).xy; |
| 22 | if (uv.x < 0. || uv.y < 0. || uv.x > 1. || uv.y > 1.) { |
| 23 | return mix(gtop, gbottom, p.y); |
| 24 | } |
| 25 | if (hasVideoMatrix > 0.5) { |
| 26 | if (flipy > .5) { |
| 27 | uv.y = 1. - uv.y; |
| 28 | } |
| 29 | return texture2D(tex, (videoMatrix * vec4(uv, 0., 1.)).xy); |
| 30 | } else { |
| 31 | return texture2D(tex, uv); |
| 32 | } |
| 33 | } |
| 34 |
| 35 | #define pow2(x) (x * x) |
| 36 | const float pi = 3.14; |
| 37 |
| 38 | void main() { |
| 39 | float r = 2.; |
| 40 | vec2 d = step == 0 ? 1. / (texSz / sz) : 1. / sz * r; |
| 41 | vec2 st = d / r; |
| 42 | vec4 col = vec4(0.); |
| 43 | float count = 0.; |
| 44 | for (float x = -d.x; x < d.x; x += st.x) |
| 45 | for (float y = -d.y; y < d.y; y += st.y) |
| 46 | { |
| 47 | col += at(uv + vec2(x, y)); |
| 48 | count++; |
| 49 | } |
| 50 | gl_FragColor = vec4((col / count).rgb, 1.); |
| 51 | } |