分屏特效中的黑白三屏特效,特效是上下兩層做了黑白處理和縮放處理。中間保留原始紋理??s放倍數(shù)大于1.0。shader如下:
// 仿抖音黑白三屏特效
precision highp float;
uniform sampler2D inputTexture;
varying highp vec2 textureCoordinate;
uniform float scale; // 黑白部分縮放倍數(shù)
void main() {
highp vec2 uv = textureCoordinate;
vec4 color;
if (uv.y < 1.0 / 3.0) {
// 縮放
vec2 center = vec2(0.5, 0.5);
uv -= center;
uv = uv / scale;
uv += center;
color = texture2D(inputTexture, uv);
// 黑白圖片
float gray = 0.3 * color.r + 0.59 * color.g + 0.11 * color.b;
color = vec4(gray, gray, gray, 1.0);
} else if (uv.y > 2.0 / 3.0) {
color = texture2D(inputTexture, uv);
// 縮放
vec2 center = vec2(0.5, 0.5);
uv -= center;
uv = uv / scale;
uv += center;
color = texture2D(inputTexture, uv);
// 黑白圖片
float gray = 0.3 * color.r + 0.59 * color.g + 0.11 * color.b;
color = vec4(gray, gray, gray, 1.0);
} else {
color = texture2D(inputTexture, uv);
}
gl_FragColor = color;
}
效果如下:

黑白三屏特效.png