[英]How to fast flip OpenGL ES FBO?
version:Android OpenGL ES 2.0版本:Android OpenGL ES 2.0
I use 5 filters and FBO to render a bitmap, every filter need bitmap texture and bitmap's mask texture, my problem is after every filter render, the next filter get FBO is upside-down, mask and texture orientation are opposite on even-numbered filter,I want to know how to fast flip FBO before next filter use it?我使用5个过滤器和FBO来渲染位图,每个过滤器都需要位图纹理和位图的遮罩纹理,我的问题是在每次过滤器渲染后,下一个过滤器得到的FBO是颠倒的,偶数过滤器上的遮罩和纹理方向相反,我想知道如何在下一个过滤器使用之前快速翻转FBO?
#version 100
precision mediump float;
uniform sampler2D uTexture;
uniform sampler2D uMaskTexture;
varying vec2 vTexCoord;
void main(){
float mask=texture2D(uMaskTexture, vTexCoord);
gl_FragColor=texture2D(uTexture*mask, vTexCoord);
}
To simplify the problem, the 5 filters are similar to the code above.为了简化问题,5 个过滤器类似于上面的代码。 uTexture comes from the FBO of the previous filter and uMaskTexture is a texture without any changes uTexture 来自之前过滤器的FBO,uMaskTexture 是没有任何变化的纹理
It seems that your texture coordinates are wrong.看来你的纹理坐标是错误的。 Correct the texture coordinate attribute.更正纹理坐标属性。 This means that you have to "flip" the y component of the texture coordinate.这意味着您必须“翻转”纹理坐标的 y 分量。 0 becomes 1 and 1 becomes 0: 0 变为 1,1 变为 0:
Of course this also can be done in the fragment shader:当然这也可以在片段着色器中完成:
void main()
{
vec2 uv = vec2(vTexCoord.x, 1.0-vTexCoord.y);
float mask = texture2D(uMaskTexture, uv);
gl_FragColor = texture2D(uTexture, uv) * mask;
}
or in the vertex shader:或在顶点着色器中:
attribute vec2 aTexCoord;
varying vec2 vTexCoord;
void main
{
vTexCoord = vec2(aTexCoord.x, 1.0-aTexCoord.y);
// [...]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.