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;
}
mat2 globalScale(float scale)
{
mat2 m = mat2(scale,0.0,
0.0,scale);
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;
//旋转坐标系
//uv -= vec2(0.1,0.1);
float t = sin(iTime * 2.0) / (2.0 * PI) + 0.5;
t *= 1.8;
uv = globalScale(t) * uv;
float c1 = crossShape(uv);
fragColor = vec4(c1 * vec3(1.0,1.0,0.0),1.0);
}
效果:
2.缩放和旋转结合
#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;
}
mat2 globalScale(float scale)
{
mat2 m = mat2(scale,0.0,
0.0,scale);
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;
//旋转坐标系
//uv -= vec2(0.1,0.1);
float t = sin(iTime * 2.0) / (2.0 * PI) + 0.5;
t *= 2.0;
if(t < 1.0)
{
uv = rotate2d(iTime) * uv;
}else{
uv = globalScale(t) * uv;
}
float c1 = crossShape(uv);
fragColor = vec4(c1 * vec3(1.0,1.0,0.0),1.0);
}
效果: