OpenGLES濾鏡開發(fā)匯總 —— 仿抖音黑白三屏特效

分屏特效中的黑白三屏特效,特效是上下兩層做了黑白處理和縮放處理。中間保留原始紋理??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
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容