iOS 滤镜特效之屏幕分裂 六屏显示

一个类似于抖音分屏特效,将视频分成六屏显示;
基于GPUImageFilter实现功能;

import "GPUImage.h"


#import "GPUImageSixScreenFilter.h"

NSString *const kGPUImageSixScreenFilterFragmentShaderString = SHADER_STRING
(
 precision highp float;
 varying vec2 textureCoordinate;
 uniform sampler2D inputImageTexture;
 
 void main()
 {
     
     highp vec2 uv = textureCoordinate;
     
/**如果是分四屏  对应参数为:
  float center1 = 0.5;
  if (uv.x <= center1) {
         uv.x = uv.x * 2.0;
     } else {
         uv.x = (uv.x - center1) * 2.0;
     } 
**/ 
     float center1 = 0.333333;
     float center2 = 0.666666;
     
     if (uv.x <= center1) {
         uv.x = uv.x * 3.0;
     } else if (uv.x <= center2) {
         uv.x = (uv.x - center1) * 3.0;
     } else {
         uv.x = (uv.x - center2) * 3.0;
     }
     
     if (uv.y <= center1) {
         uv.y = uv.y * 3.0;
     } else if (uv.y <= center2) {
         uv.y = (uv.y - center1) * 3.0;
     } else {
         uv.y = (uv.y - center2) * 3.0;
     }
     
     gl_FragColor = texture2D(inputImageTexture, uv);
 }
 );

@implementation GPUImageSixScreenFilter

- (instancetype)init
{
    self = [super initWithFragmentShaderFromString:kGPUImageSixScreenFilterFragmentShaderString];
    if (self) {
        
    }
    return self;
}

你可能感兴趣的:(iOS 滤镜特效之屏幕分裂 六屏显示)