1.fract函数代码
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = fragCoord/iResolution.xy;
uv -= 0.5;
//将uv的x坐标进行放大
uv.x *= iResolution.x / iResolution.y;
float x = uv.x * 2.0;
//将x限制在0-1内
//float m = min(fract(x),fract(1.0 - x));
float m = fract(x);
float c = smoothstep(0.0,0.1,m - uv.y);
fragColor = vec4(vec3(c),1.0);
}
效果:
2.极坐标
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;
vec2 st = vec2(atan(uv.x,uv.y),length(uv));
//将坐标变换到极坐标
uv = st;
float x = uv.x * 5.0;
float m = min(fract(x),fract(1.0 - x));
float c = smoothstep(0.0,0.1,m * 0.3 + 0.2 - uv.y);
fragColor = vec4(vec3(c),1.0);
}
旋转坐标
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;
vec2 st = vec2(atan(uv.x,uv.y),length(uv));
//将坐标变换到极坐标
uv = vec2(st.x / 6.2831 + 0.5 + iTime * 0.2,st.y);
float x = uv.x * 5.0;
float m = min(fract(x),fract(1.0 - x));
float c = smoothstep(0.0,0.1,m * 0.5 + 0.2 - uv.y);
fragColor = vec4(vec3(c),1.0);
}
效果: