1.差集,即减法
下面是白色部分(即true的部分,在mask中的1部分)的差集
两个部分的白色相减后的图形。
1 - 0 = 1;
1 - 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;
float c = smoothstep(-0.3,0.0,uv.x);
float d = smoothstep(-0.1,0.2,uv.x);
c = c - d;
fragColor = vec4(vec3(c),1.0);
}
效果:
2.并集,即加法
1 + 1 = 2 > 1(大于1视为1)
1 + 0 = 1
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;
float c = smoothstep(0.4,0.5,uv.x);
float d = smoothstep(-0.3,-0.5,uv.x);
c = c + d;
fragColor = vec4(vec3(c),1.0);
}
效果:
3.交集,即乘法
1 * 0 = 0;
1 * 1 = 1;
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;
float c = smoothstep(-0.2,0.1,uv.x);
float d = smoothstep(0.3,-0.1,uv.x);
c = c * d;
fragColor = vec4(vec3(c),1.0);
}
效果: