Created
March 8, 2018 17:07
-
-
Save redblobgames/519ee5f658f560e32bc33bdced6710ec to your computer and use it in GitHub Desktop.
Unfurling vertex shader from https://www.redblobgames.com/x/1810-polar-cartesian-animation/
This file contains 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
#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