GLSL片段着色器不处理alpha通道

时间:2018-05-02 00:14:30

标签: opengl glsl gradient fragment-shader alphablending

我正在尝试为程序制作一些简单的渐变片段着色器。没有什么花哨只是指定一个开始和停止颜色并在两者之间进行插值。除了alpha通道外,一切似乎都能正常工作。看起来除非颜色是清晰的黑色(黑色,alpha为0),否则alpha通道会被忽略或设置为1。

Input colors

What I expect to see

What I actually see

片段着色器:

uniform mediump vec4 TopColor;
uniform mediump vec4 BottomColor;
uniform mediump float ViewHeight;
uniform mediump vec4 kzViewport;

void main()
{
    precision mediump float;

    float centerY = ViewHeight / 2.0;
    float r = abs(gl_FragCoord.y - centerY) / centerY;

    gl_FragColor = mix(TopColor, BottomColor, r);
}

顶点着色器:

attribute vec3 kzPosition;
uniform highp mat4 kzProjectionCameraWorldMatrix;
void main()
{
    precision mediump float;
    gl_Position = kzProjectionCameraWorldMatrix * vec4(kzPosition.xyz, 1.0);
}

0 个答案:

没有答案