我是OpenGL ES 2.0的新手,所以请耐心等待...我想将 BOOL 标志传递到我的片段着色器中,以便在我的应用中发生某个触摸事件后,它以不同的方式呈现gl_FragColor。我尝试为此使用 vec2 属性,只是将 .x 值"伪造"为我的"BOOL",但看起来 OpenGL 在着色器掌握它之前将值从 0.0 规范化为 1.0。因此,即使在我的应用程序中我已将其设置为 0.0,当着色器正在执行其操作时,该值最终也会达到 1.0。任何建议将不胜感激。
VertexAttrib Code:
// set up context, shaders, use program etc.
[filterProgram addAttribute:@"inputBrushMode"];
inputBrushModeAttribute = [filterProgram attributeIndex:@"inputBrushMode"];
bMode[0] = 0.0;
bMode[1] = 0.0;
glVertexAttribPointer(inputBrushModeAttribute, 2, GL_FLOAT, 0, 0, bMode);
当前顶点着色器代码:
...
attribute vec2 inputBrushMode;
varying highp float brushMode;
void main()
{
gl_Position = position;
...
brushMode = inputBrushMode.x;
}
当前片段着色器代码:
...
varying highp float brushMode;
void main()
{
if(brushMode < 0.5) {
// render the texture
gl_FragColor = texture2D(inputImageTexture, textureCoordinate);
} else {
// cover things in yellow funk
gl_FragColor = vec4(1,1,0,1);
}
}
提前谢谢。
将布尔值创建为glUniform
(1.0 或 0.0)。使用 glUniform1f(GLint location, GLfloat v0)
设置其值。在着色器中,像这样检查其值:
if (my_uniform < 0.5) {
// FALSE
} else {
// TRUE
}