Skip to content

Instantly share code, notes, and snippets.

@MarioSo
Last active February 1, 2019 18:38
Show Gist options
  • Select an option

  • Save MarioSo/c5c4cf1ea3796787edd2b9d3ae6ea7e0 to your computer and use it in GitHub Desktop.

Select an option

Save MarioSo/c5c4cf1ea3796787edd2b9d3ae6ea7e0 to your computer and use it in GitHub Desktop.
VertexShader for bending things
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