将alpha值发送到片段着色器

时间:2013-12-09 10:05:22

标签: android opengl-es

我有一个片段着色器:

precision mediump float;

uniform vec4 vColor;
uniform sampler2D u_Texture;    // The input texture.

varying vec2 v_TexCoordinate;   // Interpolated texture coordinate per fragment.
varying vec4 vAlpha;
void main() {
 gl_FragColor = vec4(texture2D(u_Texture, v_TexCoordinate).xyz, texture2D(u_Texture, v_TexCoordinate).w * vAlpha[3]);

}

顶点着色器:

attribute vec3 vPosition;
attribute vec2 aTextureCoord; // Per-vertex texture coordinate information we will pass in.
attribute vec4 aAlpha;
varying vec2 v_TexCoordinate;
varying vec4 vAlpha;
void main() {
     v_TexCoordinate = aTextureCoord;
     vAlpha = aAlpha;
     gl_Position = uMVPMatrix * vec4(vPosition,1.0);
}

并尝试从我的程序中将alpha值设置为纹理。

private final int mAlphaHandle;
private float[] color = {0.5f};

设置:

mAlphaHandle = GLES20.glGetAttribLocation(mProgram,"aAlpha");

使用:

    GLES20.glEnableVertexAttribArray(mAlphaHandle);
    GLES20.glVertexAttribPointer(mAlphaHandle, 1,GLES20.GL_FLOAT, false,4, alphaBuffer);

启用混合。

    GLES20.glEnable(GLES20.GL_BLEND);
    GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);

但我对屏幕没有任何影响。所以一个问题是为什么我对屏幕没有影响?实际上想要在未来动态地改变alpha值。

0 个答案:

没有答案