Opengl es OpenGL ES 1.x根据内存中的位图混合两种纹理

Opengl es OpenGL ES 1.x根据内存中的位图混合两种纹理,opengl-es,textures,blend,Opengl Es,Textures,Blend,我有两个纹理(1024x1024,完全MipMapped,都是PVRTC-4bitsPerPixel压缩的)。纹理将应用于三维网格 在CPU上,我正在更新一个512x512布尔数组 现在,我想针对这个布尔数组将纹理2与纹理1混合(true表示纹理1的相应4个像素可见,false表示其他纹理在此位置可见) 我的硬件有两个可用的纹理单元 我如何才能做到这一点?您可以使用特定的着色器。如果您有tex1、tex2和texbool: # set your textures glActiveTexture(

我有两个纹理(1024x1024,完全MipMapped,都是PVRTC-4bitsPerPixel压缩的)。纹理将应用于三维网格

在CPU上,我正在更新一个512x512布尔数组

现在,我想针对这个布尔数组将纹理2与纹理1混合(true表示纹理1的相应4个像素可见,false表示其他纹理在此位置可见)

我的硬件有两个可用的纹理单元


我如何才能做到这一点?

您可以使用特定的着色器。如果您有tex1、tex2和texbool:

# set your textures
glActiveTexture(GL_TEXTURE0)
glBindTexture(GL_TEXTURE_2D, tex1)
glActiveTexture(GL_TEXTURE0+1)
glBindTexture(GL_TEXTURE_2D, tex2)
glActiveTexture(GL_TEXTURE0+2)
glBindTexture(GL_TEXTURE_2D, texbool)

# when you're starting your shader (id is 1 for eg)
glUseProgram(1)
glUniformi(glGetUniformLocation(1, "tex1"), 0)
glUniformi(glGetUniformLocation(1, "tex2"), 1)
glUniformi(glGetUniformLocation(1, "texbool"), 2)

# and now, draw your model as you wish
片段着色器可以类似于:

// i assume that you'll pass tex coords too. Since the tex1 and tex2
// look the same size, i'll assume that for now.
varying vec2 tex1_coords;

// get the binded texture
uniform sample2D tex1;
uniform sample2D tex2;
uniform sample2D texbool;

// draw !
void main(void) {
  vec4 c1 = texture2D(tex1, tex1_coords);
  vec4 c2 = texture2D(tex2, tex1_coords);
  vec4 cbool = texture2D(texbool, tex1_coords / 2.);
  // this will mix c1 to c2, according to cbool.
  // if cbool is 0, c1 will be used, otherwise, it will be c2
  glFragColor = mix(c1, c2, cbool);
}
我没有测试您的示例,但这就是我开始找到解决方案的方式:)