分屏滤镜篇

分屏滤镜篇

分屏滤镜顶点着色器固定不变

attribute vec4 position;attribute mediump vec4 inputTextureCoordinate;

varying mediump vec2 textureCoordinate;

void main(){gl_Position = position;textureCoordinate = inputTextureCoordinate.xy;}

fragment片段着色器

二分屏:横屏X(对应的顶点着色器)varying mediump vec2 textureCoordinate;precision mediump float;uniform sampler2D videoFrame;void main(){vec2 uv = textureCoordinate.xy;float x;// 0.0~0.5 范围内显示0.25~0.75范围的像素if (uv.x >= 0.0 && uv.x <= 0.5) {x = uv.x + 0.25;}else {// 0.5~1.0范围内显示 0.25~0.75范围的像素x = uv.x - 0.25;}pixelColor = texture2D(videoFrame, vec2(x,uv.y));gl_FragColor = pixelColor;}

二分屏:竖屏Y(对应的顶点着色器)void main(){vec2 uv = textureCoordinate.xy;float y;// 0.0~0.5 范围内显示0.25~0.75范围的像素if (uv.y >= 0.0 && uv.y <= 0.5) {y = uv.y + 0.25;}else {// 0.5~1.0范围内显示 0.25~0.75范围的像素y = uv.y - 0.25;}pixelColor = texture2D(videoFrame, vec2(uv.x,y));gl_FragColor = pixelColor;}

四分屏(对应的顶点着色器)void main(){vec2 uv = textureCoordinate.xy;if (uv.x <= 0.5) {uv.x = uv.x * 2.0;}else {

     uv.x = (uv.x - 0.5) * 2.0;

 }

 

if(uv.y <= 0.5){

 uv.y = uv.y * 2.0;

}else{

 uv.y = (uv.y - 0.5) * 2.0;

}pixelColor = texture2D(videoFrame, uv);gl_FragColor = pixelColor;}

## 九分屏(对应的顶点着色器)void main(){

vec2 uv = textureCoordinate.xy;

if (uv.x <= 1.0 / 3.0) {

    uv.x = uv.x * 3.0;

}else if (uv.x <= 2.0 / 3.0) {

    uv.x = (uv.x - 1.0 / 3.0) * 3.0;

}else {

    uv.x = (uv.x - 2.0 / 3.0) * 3.0;

}

 

if (uv.y <= 1.0 / 3.0) {

    uv.y = uv.y * 3.0;

}else if (uv.y <= 2.0 / 3.0) {

    uv.y = (uv.y - 1.0 / 3.0) * 3.0;

}else {

    uv.y = (uv.y - 2.0 / 3.0) * 3.0;

}

pixelColor = texture2D(videoFrame, uv);gl_FragColor = pixelColor;}

 

上一篇:Matlab-简单的车牌识别并分割(学习笔记)


下一篇:C上写GUI只能用Windows API