1.代码
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;
}
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/iResolution.xy;
uv.x *= iResolution.x / iResolution.y;
uv *= 4.0;
uv = fract(uv);
//先移动到原点
vec2 uv2 = uv - vec2(0.5,0.5);
vec2 uvr = uv2 * rotate2d(iTime * 2.0);
//再恢复回去
vec2 uv3 = uvr + vec2(0.5,0.5);
float c1 = Box(uv3,vec2(0.1,0.1),vec2(0.9,0.9),vec2(0.01,0.01));
fragColor = vec4(c1 * vec3(1.0,1.0,0.0),1.0);
}
效果: