Con*_*tin 9 alpha blending fragment-shader opengl-es-2.0
我无法弄清楚,如何使用OpenGL ES 2.0类似于OpenGL ES 1.1的结果.我想实际使用Sampler2D(将我的纹理与Alpha通道混合到Framebuffer)并设置Color.纹理应该用颜色绘制 - 就像在OpenGL ES 1.1中我的FragmentShader看起来像这样:
varying lowp vec4 colorVarying;
varying mediump vec2 texcoordVarying;
uniform sampler2D texture;
void main(){
gl_FragColor = texture2D(texture, texcoordVarying) + colorVarying;
}
Run Code Online (Sandbox Code Playgroud)
但是"+ colorVarying"部分用黑色破坏了我的alpha通道(因为我还添加了colorVarying,如果AlphaValue为0)并且产生了奇怪的渐变效果......纹理和颜色通道如何在固定功能管道中组合?我对glColor4f的替换是:
void gl2Color4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a){
const GLfloat pointer[] = {r, g, b, a};
glVertexAttribPointer(ATTRIB_COLOR, 2, GL_FLOAT, 0, 0, pointer);
glEnableVertexAttribArray(ATTRIB_COLOR);
}
Run Code Online (Sandbox Code Playgroud)
我正在使用glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); 如果这是某种相关的......
对于颜色1.0,0.0,1.0,1.0这里是我现在得到的:
我想得到:
一些想法来实现这一目标?任何帮助,将不胜感激.
Piv*_*vot 17
要按照OpenGL ES 1.1默认的方式将顶点颜色与纹理组合,您需要片段着色器为:
varying lowp vec4 colorVarying;
varying mediump vec2 texcoordVarying;
uniform sampler2D texture;
void main(){
gl_FragColor = texture2D(texture, texcoordVarying) * colorVarying;
}
Run Code Online (Sandbox Code Playgroud)
请注意,GL_MODULATE
将纹理乘以颜色,而不是添加到颜色.
你看到的梯度,你的形象,因为在OpenGL ES传递的0一大步,顶点数组功能规范(1.1和2.0)不会导致的0,而一大步,OpenGL ES的计算步幅为你,假设您指定的格式/类型的紧密包装元素.结果,您实际上是在读取数组末尾的随机内存.如果要在所有顶点上使用相同的值,则应设置当前属性值并禁用关联的数组:
void gl2Color4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a){
const GLfloat pointer[] = {r, g, b, a};
glVertexAttrib4fv(ATTRIB_COLOR, pointer);
glDisableVertexAttribArray(ATTRIB_COLOR);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13702 次 |
最近记录: |