alpha不使用glsl着色器更改对象的透明度

时间:2022-05-05 14:56:57

How come when i manually change the alpha value in array, being passed to shader, the result is the same for both 0.0f and 1.0f?

为什么我手动更改数组中的alpha值,传递给着色器,0.0f和1.0f的结果是一样的?

I was expecting the object to be drawn with some level of transparency, depending on alpha value.

我期望根据alpha值绘制具有某种透明度的对象。

I'm not using any textures. I always see my red object against a black background.

我没有使用任何纹理。我总是看到我的红色物体在黑色背景下。

accessing glsl variable from java ..

从java访问glsl变量..

float[] color = {1.0f, 0.0f, 0.0f, 1.0f};

gl2.glGetUniformLocation(shaderProgram, "vColor");
gl2.glUniform4fv(mColorHandle, 1, color, 0);

glsl, fragment shader ..

glsl,片段着色器..

#version 120

uniform vec4 vColor;

void main() {
    gl_FragColor = vColor;
    gl_FragColor.a = 0.0; // does not make object transparent
    // gl_FragColor.a = 1.0; // does not make object transparent
}

1 个解决方案

#1


Needed to enable blending ..

需要启用混合..

gl2.glEnable(GL.GL_BLEND);
gl2.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);

#1


Needed to enable blending ..

需要启用混合..

gl2.glEnable(GL.GL_BLEND);
gl2.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);