·  阅读 306

「这是我参与2022首次更文挑战的第2天，活动详情查看：2022首次更文挑战

## 实现

### 二分镜

x轴二分镜效果。判断uv的x大小，若x大于0.5则减去0.5。

``````void main() {
vec2 uv = gl_FragCoord.xy / iResolution.xy;
if(uv.x >= 0.5){
uv.x -=0.5;
}
gl_FragColor = texture(iChannel2,uv);
}

y轴二分镜效果。判断uv的y大小，若y大于0.5则减去0.5。

``````void main() {
vec2 uv = gl_FragCoord.xy / iResolution.xy;
if(uv.y >= 0.5){
uv.y -=0.5;
}
gl_FragColor = texture(iChannel2,uv);
}

### 三分镜

``````void main() {
vec2 uv = gl_FragCoord.xy / iResolution.xy;

float three = 1.0 / 3.0;
if(uv.y <= three){
uv.y = (uv.y + three);
}else if(uv.y >= three * 2.0){
uv.y -= three;
}
gl_FragColor = texture(iChannel2,uv);
}

``````void main() {
vec2 uv = gl_FragCoord.xy / iResolution.xy;

float three = 1.0 / 3.0;
if(uv.y <= three){
uv.y = (uv.y + three) / 2.0 + 0.25;
uv.x =  uv.x / 2.0;
}else if(uv.y >= three * 2.0){
uv.y -= three;
}else{
uv.x = uv.x / 1.5 + 0.3;
uv.y = uv.y / 1.5 + 0.2;
}
gl_FragColor = texture(iChannel2,uv);
}

### 分割线

``````void main() {
vec2 uv = gl_FragCoord.xy / iResolution.xy;
float three = 1.0 / 3.0;
float line = 0.0;
float lineSize = 0.005;
if(uv.y >= three - lineSize && uv.y <= three + lineSize){
//在1/3处绘制分割线 混合透明度为1.0
line = 1.0;
}else if(uv.y >= (three * 2.0 - lineSize) && uv.y <= (three * 2.0 + lineSize)){
//在2/3处绘制分割线 混合透明度为1.0
line = 1.0;
}
if(uv.y <= three){
uv.y += three;
}else if(uv.y >= three * 2.0){
uv.y -= three;
}
gl_FragColor = mix(texture(iChannel2,uv),vec4(0.0,0.0,0.0,1.0),line);
}

Android

Android