├── .gitignore ├── barrel-pincushion.glsl ├── package.json ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store -------------------------------------------------------------------------------- /barrel-pincushion.glsl: -------------------------------------------------------------------------------- 1 | vec2 barrelPincushion(vec2 uv, float strength) { 2 | vec2 st = uv - 0.5; 3 | float radius = 1.0 + strength * dot(st, st); 4 | return 0.5 + radius * st; 5 | } 6 | 7 | #pragma glslify: export(barrelPincushion); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "glsl-barrel-pincushion", 3 | "version": "1.0.3", 4 | "description": "Distort UV using barrel or pincushion", 5 | "main": "barrel-pincushion.glsl", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/ayamflow/glsl-barrel-pincushion.git" 12 | }, 13 | "keywords": [ 14 | "glsl", 15 | "distorstion", 16 | "barrel", 17 | "pincushion", 18 | "fisheye" 19 | ], 20 | "author": "Florian Morel", 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/ayamflow/glsl-barrel-pincushion/issues" 24 | }, 25 | "homepage": "https://github.com/ayamflow/glsl-barrel-pincushion#readme" 26 | } 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Florian Morel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # glsl-barrel-pincushion 2 | 3 | [![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges) 4 | 5 | Distort the UV with barrel or pincushion effect. 6 | Adapted from [this shadertoy](https://www.shadertoy.com/view/lttXD4). 7 | 8 | ![glsl-barrel-pincushion](https://i.imgur.com/XiADOcq.jpg) 9 | 10 | ### Installation :package: 11 | 12 | ```bash 13 | npm i glsl-barrel-pincushion -S 14 | ``` 15 | 16 | ### Usage :book: 17 | 18 | #### barrelPincushion(vec2 st, float strength) 19 | strength > 0 for barrel distortion, strength < 0 for pincushion. 20 | 21 | ### Example :floppy_disk: 22 | 23 | ```glsl 24 | uniform float uTime; 25 | #pragma glslify: barrelPincushion = require(glsl-barrel-pincushion) 26 | #pragma glslify: rectangle = require(glsl-2d-primitives/rectangle) 27 | 28 | attribute vec2 vUv; 29 | 30 | void main() { 31 | vec2 st = barrelPincushion(vUv, sin(uTime)); 32 | float shape = rectangle(st, vec2(0.5)); 33 | gl_FragColor = vec4(color, shape); 34 | } 35 | ``` 36 | 37 | [Demo](http://thebookofshaders.com/edit.php?log=180726191628) 38 | 39 | ### License :pencil: 40 | 41 | MIT. See [LICENSE](http://github.com/ayamflow/glsl-barrel-pincushion/blob/master/LICENSE) for details. --------------------------------------------------------------------------------