OpenGL动效滤镜

OpenGL动效滤镜,其最主要的因素,是将时间因素传递进去再做一系列的滤镜变化处理。

首先我们来看时间因素怎么传递进去,其代码:

//使用program

    glUseProgram(self.program);

    //绑定buffer

    glBindBuffer(GL_ARRAY_BUFFER, self.vertexBuffer);

    // 传入时间

    CGFloat currentTime = self.displayLink.timestamp - self.startTimeInterval;

    GLuint time = glGetUniformLocation(self.program, "Time");

    glUniform1f(time, currentTime);

这样就可以将外部时间传递给片元着色器进去计算处理,根据时间作出相应的改变

其主要滤镜表达有,缩放,灵魂出窍,抖动,闪白,毛刺,幻觉

灵魂出窍动画效果:


灵魂出窍效果

灵魂出窍代码实现:

    floatduration =0.7;

    floatmaxAlpha =0.4;

    floatmaxScale =1.8;

    floatprogress =mod(Time, duration) / duration;// 0~1

    floatalpha = maxAlpha * (1.0- progress);

    floatscale =1.0+ (maxScale -1.0) * progress;

    floatweakX =0.5+ (TextureCoordsVarying.x -0.5) / scale;

    floatweakY =0.5+ (TextureCoordsVarying.y -0.5) / scale;

    vec2weakTextureCoords =vec2(weakX, weakY);

    vec4weakMask =texture2D(Texture, weakTextureCoords);

    vec4mask =texture2D(Texture, TextureCoordsVarying);

    gl_FragColor= mask * (1.0- alpha) + weakMask * alpha;

你可能感兴趣的:(OpenGL动效滤镜)