1.并集
float Circle(vec2 uv,vec2 center,float radius)
{
float d = length(uv - center);
return step(d,radius);
}
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 c = Circle(uv,vec2(-0.3,-0.2),0.1);
float d = Circle(uv,vec2(0.2,0),0.2);
c = c + d;
fragColor = vec4(vec3(c),1.0);
}
效果:
2.差集
float Circle(vec2 uv,vec2 center,float radius)
{
float d = length(uv - center);
return step(d,radius);
}
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 c = Circle(uv,vec2(0.2,-0.2),0.1);
float d = Circle(uv,vec2(0.2,0),0.2);
c = d - c;
fragColor = vec4(vec3(c),1.0);
}
效果:
3.交集
float Circle(vec2 uv,vec2 center,float radius)
{
float d = length(uv - center);
return step(d,radius);
}
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 c = Circle(uv,vec2(0.2,-0.2),0.1);
float d = Circle(uv,vec2(0.2,0),0.2);
c = d * c;
fragColor = vec4(vec3(c),1.0);
}
效果: