我无法让不透明的多边形变得透明。我正在使用本网站的公式:
Weighted Order Independent Transparency
这是我的代码:
int programShader = 0;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
[self changeFrustumX:0 y:0 w:512 h:512];
// Opaque stuff goes here?
// Make everything transparent
glEnable(GL_BLEND);
for (int i = 0; i < 2; i++)
{
glBindFramebuffer(GL_FRAMEBUFFER, framebufferID[i]);
if (i == 0)
{
// The transparency colors
glClearColor(0.0, 0.0, 0.0, 1.0);
glBlendFunc(GL_ONE, GL_ONE);
glClear(GL_COLOR_BUFFER_BIT);
programShader = colorPassShader;
}
else if (i == 1)
{
// The transparency mask
glClearColor(1.0, 1.0, 1.0, 1.0);
glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
glClear(GL_COLOR_BUFFER_BIT);
programShader = maskPassShader;
}
glUseProgram(programShader);
// Yellow is supposed to be opaque
[self setProgram:programShader
modelView:modelViewArray2
projection:frustumArray
vertices:yellowVertices
colors:yellowColors
textures:NULL];
// Blue not opaque
[self setProgram:programShader
modelView:modelViewArray2
projection:frustumArray
vertices:blueVertices
colors:blueColors
textures:NULL];
// Red not opaque
[self setProgram:programShader
modelView:modelViewArray2
projection:frustumArray
vertices:redVertices
colors:redColors
textures:NULL];
}
// get back to the default framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, 0);
// Transparent objects rendering
glClearColor(0.75, 0.75, 0.75, 1.0);
// Original blend
glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);
glClear(GL_COLOR_BUFFER_BIT);
[self changeOrthoX:0 y:0 w:512 h:512];
glUseProgram(combineShader);
glActiveTexture(GL_TEXTURE1);
// Display the color from the framebuffer
glBindTexture(GL_TEXTURE_2D, renderTextureID[0]);
// Colors
glUniform1i(glGetUniformLocation(combineShader, "sAccumulation"), 1);
glActiveTexture(GL_TEXTURE2);
// Display the color from the framebuffer
glBindTexture(GL_TEXTURE_2D, renderTextureID[1]);
// Mask
glUniform1i(glGetUniformLocation(combineShader, "sReveal"), 2);
[self setProgram:combineShader
modelView:modelViewArray3
projection:orthogonalArray
vertices:combineVertices
colors:NULL
textures:combineTextures];
// Opaque objects rendering
glDisable(GL_BLEND);
我无法使用多个glFragData [n],据我所知,OpenGL ES不支持多个。黄色多边形应该是完全不透明的,但在图片中则不是。我如何让它不透明,其他一切都透明?另外,我如何创建半透明半透明多边形?
这是我生成的图片: