1.shadertoy代码
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;
uv = abs(uv);
float c = dot(uv,vec2(1,1));
vec3 col = vec3(0.0);
col += step(c,0.5);
fragColor = vec4(vec3(c),1.0);
}
越靠近中点,点积越接近0
2 四边形
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;
uv = abs(uv);
float c = dot(uv,vec2(1,1));
vec3 col = vec3(0.0);
col += step(c,0.5);
fragColor = vec4(col,1.0);
}