Skip to content

Instantly share code, notes, and snippets.

@redblobgames
Created March 8, 2018 17:07
Show Gist options
  • Save redblobgames/519ee5f658f560e32bc33bdced6710ec to your computer and use it in GitHub Desktop.
Save redblobgames/519ee5f658f560e32bc33bdced6710ec to your computer and use it in GitHub Desktop.
#define M_TAU (2.0*3.1415926535897932384626433832795)
precision mediump float;
uniform float u_t, u_N, u_width, u_radius;
attribute vec2 a_wh;
varying vec2 v_texcoord;
void main () {
float w = a_wh.x; /* which "wedge" we're on */
float h = a_wh.y; /* will be 0 at center of circle and 1 at rim */
float angle = M_TAU * w / u_N; /* before unfurling */
float angle2 = max(0.0, angle - u_t*M_TAU); /* after unfurling */
vec2 bottom = vec2(min(u_t, w / u_N) * u_width, 0.0);
vec2 top = bottom + min(vec2(999999.0, u_radius),
u_radius * vec2(sin(angle2), cos(angle2)));
vec2 pos = mix(bottom, top, h);
v_texcoord = 0.5 - h * vec2(-sin(angle), cos(angle)) * 0.5;
gl_Position = vec4(pos - vec2(0.6, 0.0), 0, 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment