1.代码如下
#define PI 3.1415926
float Box(vec2 uv,vec2 bottomLeft,vec2 topRight,vec2 blur)
{
vec2 c = smoothstep(bottomLeft,bottomLeft + blur,uv);
vec2 co2 = smoothstep(topRight,topRight - blur ,uv);
c *= co2;
return c.x * c.y;
}
float crossShape(vec2 uv)
{
float b1 = Box(uv,vec2(-0.3,-0.03),vec2(0.3,0.03),vec2(0.01,0.01));
float b2 = Box(uv,vec2(-0.03,-0.3),vec2(0.03,0.3),vec2(0.01,0.01));
return b1 + b2;
}
mat2 rotate2d(float angle)
{
mat2 m = mat2(cos(angle),-sin(angle),sin(angle),cos(angle));
return m;
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = (fragCoord.xy - 0.5 * iResolution.xy) / iResolution.y;
float hour = Box(rotate2d(-iTime * PI / 100.0) * uv,vec2(-0.02,-0.02),vec2(0.25,0.02),vec2(0.01,0.01));
float minute = Box(rotate2d(-iTime * PI / 60.0 ) * uv,vec2(-0.02,-0.02),vec2(0.4,0.02),vec2(0.01,0.01));
float sec = Box(rotate2d(-iTime * PI ) * uv,vec2(-0.02,-0.02),vec2(0.6,0.02),vec2(0.01,0.01));
vec3 t = hour * vec3(1.0,0.0,0.0) + minute * vec3(1.0,1.0,0.0) + sec * vec3(0.0,1.0,0.0);
fragColor = vec4(t,1.0);
}
效果: