当两个纹理覆盖相同的矩形时,我可以在片段着色器中使用不同的混合模式混合两个纹理。但是现在我的问题是,一个纹理是没有旋转的普通矩形,而另一个纹理是旋转/缩放和平移的另一个矩形。我该如何按照想要的方式合并这些纹理?(如下图所示)
我知道如何做到这一点...
但不确定如何做到这一点...
为了混合第一张图片中的纹理,我使用了以下代码...
Objective C 代码...
- (void) display {
[EAGLContext setCurrentContext:context];
glBindFramebuffer(GL_FRAMEBUFFER, targetFBO);
glUseProgram(program);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, textureTop);
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, textureBot);
glUniform1i(inputTextureTop, 2);
glUniform1i(inputTextureBot, 3);
glUniform1f(alphaTop, alpha);
glEnable (GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glVertexAttribPointer(position, 2, GL_FLOAT, 0, 0, imageVertices);
glVertexAttribPointer(inputTextureCoordinate, 2, GL_FLOAT, 0, 0, textureCoordinates);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER];
}
Vertex shader...
attribute vec4 position;
attribute vec4 inputTextureCoordinate;
varying vec2 textureCoordinate;
void main()
{
gl_Position = position;
textureCoordinate = inputTextureCoordinate.xy;
}
Fragment shader...
varying highp vec2 textureCoordinate;
uniform sampler2D inputTextureTop;
uniform sampler2D inputTextureBot;
uniform highp float alphaTop;
void main()
{
lowp vec4 pixelTop = texture2D(inputTextureTop, textureCoordinate);
lowp vec4 pixelBot = texture2D(inputTextureBot, textureCoordinate);
gl_FragColor = someBlendOperation(pixelTop, pixelBot);
}