完整代码查看# AndroidShaderDemo下的FlashWhiteRender
有了之前的缩放特效,闪白就很容易了,闪白的原理就是在原像素rgb分量上加个[0,1]之间的参数。
fragment shader如下:
precision mediump float;
uniform sampler2D u_TextureUnit;
varying vec2 v_TextureCoordinates;
uniform float texelWidthOffset;
uniform float texelHeightOffset;
uniform float uflashParam;
void main()
{
vec4 fragColor = texture2D(u_TextureUnit, v_TextureCoordinates);
gl_FragColor = vec4(fragColor.r + uflashParam,fragColor.g + uflashParam,fragColor.b + uflashParam,fragColor.a);
}
uflashParam就是加的参数,由每帧的index决定,具体代码为:
private void prepareDraw(){
float progress;
if (curFrame <= MiddleFrame) {
progress = curFrame * 1.0f / MiddleFrame;
} else {
progress = 2f - curFrame * 1.0f / MiddleFrame;
}
glUniform1f(flashWhiteProgram.getFlashAttributeLocation(), progress);
curFrame++;
if(curFrame > MaxFrame){
curFrame = 0;
}
}
最后效果如下:
flash_white.gif
网友评论