Last active
February 1, 2019 18:38
-
-
Save MarioSo/c5c4cf1ea3796787edd2b9d3ae6ea7e0 to your computer and use it in GitHub Desktop.
VertexShader for bending things
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| varying vec2 vUv; | |
| uniform float bendAngle; | |
| uniform vec2 bounds; | |
| uniform float bendOffset; | |
| uniform float bendAxisAngle; | |
| vec3 bend(vec3 ip, float ba, vec2 b, float o, float a) { | |
| vec3 op = ip; | |
| ip.x = op.x * cos(a) - op.y * sin(a); | |
| ip.y = op.x * sin(a) + op.y * cos(a); | |
| if(ba != 0.0) { | |
| float radius = b.y / ba; | |
| float onp = (ip.x - b.x) / b.y - o; | |
| ip.z = cos(onp * ba) * radius - radius; | |
| ip.x = (b.x + b.y * o) + sin(onp * ba) * radius; | |
| } | |
| op = ip; | |
| ip.x = op.x * cos(-a) - op.y * sin(-a); | |
| ip.y = op.x * sin(-a) + op.y * cos(-a); | |
| return ip; | |
| } | |
| void main(void) { | |
| vUv = uv; | |
| vec3 p = bend(position, bendAngle, bounds, bendOffset, bendAxisAngle); | |
| gl_Position = projectionMatrix * modelViewMatrix * vec4(p,1.0); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment