GLSL多纹理图像

时间:2012-06-05 06:06:22

标签: opengl-es glsl

我写了这段代码:

"    vec3 col1 = texture2D(uDiffuseTexture, vec2(vTextureCoord.x, vTextureCoord.y + time)).rgb;\n" +
"    float a1=1.0;\n"+  
"    vec3 col2 = texture2D(uNormalTexture, vec2(vTextureCoord.x + time, vTextureCoord.y)).rgb;\n" +
"    float a2=uAlpha;\n"+  
顺便说一下:

with:gl_FragColor = vec4(col1+col2, a1+a2);

alpha不工作......为什么?总是一样的,为什么?

我的uAlpha变量是uniform,从0.1更改为1.0

1 个答案:

答案 0 :(得分:2)

  

我想用100%绘制image1,用0-100%绘制image2

目前,您正在使用添加剂混合(col1 + col2)混合两个图像,而不考虑uAlpha制服来混合两个图像。

我认为你想要达到的目的是将image2混合到image1上,使用uAlpha作为不透明度。

vec3 col1 = texture2D(uDiffuseTexture, vec2(vTextureCoord.x, vTextureCoord.y + time)).rgb;
vec3 col2 = texture2D(uNormalTexture, vec2(vTextureCoord.x + time, vTextureCoord.y)).rgb;
float a2=uAlpha;
vec3 result = mix(col1, col2, a2);   // this combines the two texture colors
gl_FragColor = vec4(result, 1.0);
相关问题