void main(){ vec2 st = gl_FragCoord.xy/u_resolution.xy; vec3 color = vec3(0.0);
// move space from the center to the vec2(0.0) // st从0~1变成-0.5~0.5 st -= vec2(0.5); // rotate the space,左乘,传入角度 st = rotate2d( sin(u_time)*1.*PI ) * st; // move it back to the original place st += vec2(0.5);
// Show the coordinates of the space on the background color = vec3(st.x,st.y,0.0);
// Add the shape on the foreground color += vec3(cross(st,0.4));
gl_FragColor = vec4(color,1.0); }
组合
......
void main(){ vec2 st = gl_FragCoord.xy/u_resolution.xy; vec3 color = vec3(0.0);
// To move the cross we move the space vec2 translate = vec2(cos(u_time),sin(u_time)); st += translate*0.35; st-=vec2(0.5); st = rotate2d(u_time*PI)* st; st+=vec2(0.5);
// Show the coordinates of the space on the background color = vec3(st.x,st.y,0.0);
// Add the shape on the foreground color += vec3(cross(st,0.25));
gl_FragColor = vec4(color,1.0); }
缩放
void main(){ vec2 st = gl_FragCoord.xy/u_resolution.xy; vec3 color = vec3(0.0);
st -= vec2(0.5); st = scale( vec2(sin(u_time)+1.704) ) * st; st += vec2(0.5);
// Show the coordinates of the space on the background color = vec3(st.x,st.y,0.0);
// Add the shape on the foreground color += vec3(cross(st,0.2));
void main(){ vec2 st = gl_FragCoord.xy/u_resolution; vec3 color = vec3(0.0);
// UV values goes from -1 to 1 // So we need to remap st (0.0 to 1.0) st -= 0.5; // becomes -0.5 to 0.5 st *= 2.0; // becomes -1.0 to 1.0
// we pass st as the y & z values of // a three dimensional vector to be // properly multiply by a 3x3 matrix color = yuv2rgb * vec3(0., st.x, st.y); //color = rgb2yuv * vec3(0., st.x, st.y); gl_FragColor = vec4(color,1.0); }