0

我已经创建了一个着色器,它能够将图像旋转大约 180° 并用黑色渐变覆盖它,但现在我想创建真正的透明度而不是使用黑色作为我的背景颜色。

这是我到目前为止得到的:

// Vertex Shader
uniform highp mat4 u_modelViewMatrix;
uniform highp mat4 u_projectionMatrix;
attribute highp vec4 a_position;
attribute lowp vec4 a_color;
attribute highp vec2 a_texcoord;
varying lowp vec4 v_color;
varying highp vec2 v_texCoord;
uniform int offset;
uniform int space;
uniform int vph;
void main()
{\
highp float h = float(offset)/float(vph);
highp float s = float(space)/1000.0;
highp vec4 pos = a_position;
pos.y = pos.y - (h + s);
gl_Position = (u_projectionMatrix * u_modelViewMatrix) * pos;
    v_color = a_color;
v_texCoord = vec2(a_texcoord.x, 1.0 - a_texcoord.y);
}

// Fragment Shader
varying highp vec2 v_texCoord;
uniform sampler2D u_texture0;
uniform int gradient;
void main()
{
  lowp vec3 w = vec3(1.0,1.0,1.0);
  lowp vec3 b = vec3(0.0,0.0,0.0);
  lowp vec3 mix = mix(b, w, (v_texCoord.y-(float(gradient)/10.0)));
  gl_FragColor = texture2D(u_texture0,v_texCoord) * vec4(mix, 1.0);
}
4

1 回答 1

1

在片段着色器中用半透明颜色替换黑色:

void main()
{
  lowp vec4 w = vec3(1.0,1.0,1.0,1.0);
  lowp vec4 b = vec3(0.0,0.0,0.0,0.0);
  lowp vec4 mix = mix(b, w, (v_texCoord.y-(float(gradient)/10.0)));
  gl_FragColor = texture2D(u_texture0,v_texCoord) * mix;
}
于 2012-04-17T14:05:44.133 回答