0.效果:
1.vertexShader
attribute vec2 aCRSCoords; attribute vec2 aExtrudeCoords; uniform mat4 uTransformMatrix; / uniform vec2 uPixelSize; uniform float uNow; attribute float adm0cap; varying vec2 vExtrudeCoords; varying float vTimeNow ; varying vec2 vCRSCoords; void main(void) { vExtrudeCoords = aExtrudeCoords; vTimeNow = uNow; gl_Position = uTransformMatrix * vec4(aCRSCoords, 1.0, 1.0); // If not, just place a smaller kitten. gl_Position += vec4(aExtrudeCoords * uPixelSize * 100.0, 0.0, 0.0); }
2.fragmentShader
uniform sampler2D uTexture0; precision highp float; varying float vTimeNow ; varying vec2 vExtrudeCoords; const float PI = 3.1415926535898; const float PI_2 = PI/2.0; float arctan2(float y,float x){ if( x > 0.0 ) return atan(y/x); else if( x < 0.0 && y >= 0.0 ) return atan(y/x) + PI; else if( x < 0.0 && y < 0.0 ) return atan(y/x) - PI; else if( x == 0.0 && y > 0.0 ) return PI_2; else if( x == 0.0 && y < 0.0 ) return -PI_2; else return 0.0; } void main(void) { // Our extrude coordinates go from [-1,-1] to [1,1], // but the texture lookup needs coords in the [0,0]-[1,1] // range. vec2 texelCoords; texelCoords.x = (vExtrudeCoords.x + 1.0) / 2.0; texelCoords.y = (1.0 - vExtrudeCoords.y) / 2.0; // Perform a texture lookup vec4 texelColour = texture2D(uTexture0, texelCoords); float angle = arctan2( vExtrudeCoords.y, vExtrudeCoords.x ); angle = mod( -vTimeNow/500.0 + angle, PI * 2.0 ); float alpha = 0.0; if( angle < PI ) angle = 0.0; else alpha = ( angle - PI ) / PI * 1.0; if( mod(gl_FragCoord.s,3.0) < 1.0 || mod(gl_FragCoord.t,3.0) < 1.0 ) alpha = 0.0; // Use the colour from the texture as the colour for this pixel texelColour.a = texelColour.a*alpha; gl_FragColor = texelColour; }