1

I'm rendering elements in OpenGL ES and they have the same color, but a different alpha. The problem is that when the alpha is .1, the color changes, not just the opacity. For example, the color will change from black to purple when the alpha component is set to a value of 0.1. When the alpha value is not .1, or some other tenth values, it works fine.

I'm setting this blending prior to drawing:

glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

Drawing:

// if the element has any data, then draw it
if(vertexBuffer){
    glVertexPointer(2, GL_FLOAT, sizeof(struct Vertex), &vertexBuffer[0].Position[0]);
    glColorPointer(4, GL_FLOAT, sizeof(struct Vertex), &vertexBuffer[0].Color[0]);
    glTexCoordPointer(2, GL_FLOAT, sizeof(struct Vertex), &vertexBuffer[0].Texture[0]);
    glDrawArrays(GL_TRIANGLES, 0, [element numberOfSteps] * [element numberOfVerticesPerStep]);
}
4

1 回答 1

1

这是预乘 alpha 的正常行为(您的混合函数暗示)。使用预乘 alpha 时,必须同时更改颜色和 alpha。

originalColor * alpha因此,无论何时更改 的值,新颜色都应等于alpha。请注意,您应该使用 alpha 的浮点归一化值(例如0.0 - 1.0)而不是定点值(例如0 - 255

考虑您选择的混合功能:

             目标RGB = (源RGB * 1.0) + (目标RGB * (1.0 - 源A ));

传统的阿尔法混合是:

             目标RGB = (源RGB * 源A ) + (目标RGB * (1.0 - 源A ));

注意更传统的混合方程是如何执行 Src RGB * Src A 的?仅当 RGB 分量字面上预先乘以 alpha 分量时,您的特定混合方程才能正常工作。

于 2013-11-14T23:23:17.420 回答