1.移动矩阵代码
float Circle(vec2 uv,vec2 center,float r,float blur)
{
float dist = length(uv - center);
float c = smoothstep(r + blur,r,dist);
return c;
}
mat3 translate(vec2 to)
{
mat3 m = mat3(1, 0, to.x,
0, 1, to.y,
0, 0, 1);
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;
vec3 uv2 = vec3(uv,1);
//坐标系往左移,则物体往右移
uv2 = uv2 * translate(vec2(-0.1,0.0) * iTime);
uv = uv2.xy;
uv *= 3.0;
uv = fract(uv);
float c1 = Circle(uv,vec2(0.5,0.5),0.3,0.05);
fragColor = vec4(c1 * vec3(1.0,1.0,0.0),1.0);
}
效果:
2.x方向
float Circle(vec2 uv,vec2 center,float r,float blur)
{
float dist = length(uv - center);
float c = smoothstep(r + blur,r,dist);
return c;
}
mat3 translate(vec2 to)
{
mat3 m = mat3(1, 0, to.x,
0, 1, to.y,
0, 0, 1);
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 *= 3.0;
uv.x += fract(iTime);
uv = fract(uv);
float c1 = Circle(uv,vec2(0.5,0.5),0.3,0.05);
fragColor = vec4(c1 * vec3(1.0,1.0,0.0),1.0);
}
效果:
3.分段处理
float Circle(vec2 uv,vec2 center,float r,float blur)
{
float dist = length(uv - center);
float c = smoothstep(r + blur,r,dist);
return c;
}
mat3 translate(vec2 to)
{
mat3 m = mat3(1, 0, to.x,
0, 1, to.y,
0, 0, 1);
return m;
}
vec2 movingTile(vec2 uv){
uv *= 3.0;
if(fract(iTime) > 0.5){
if(fract(uv.y * 0.5) > 0.5){
uv.x += fract(iTime) * 2.0;
}else{
uv.x -= fract(iTime) * 2.0;
}
}else{
if(fract(uv.x * 0.5) > 0.5){
uv.y += fract(iTime) * 2.0;
}else{
uv.y -= fract(iTime) * 2.0;
}
}
return fract(uv);
}
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 = movingTile(uv);
float c1 = Circle(uv,vec2(0.5,0.5),0.3,0.05);
fragColor = vec4(c1 * vec3(1.0,1.0,0.0),1.0);
}
效果: