3

我是 OpenGL ES 2.0 的新手,所以请多多包涵……我想将一个 BOOL 标志传递到我的片段着色器中,以便在我的应用程序中发生某个触摸事件后,它会以不同的方式呈现 gl_FragColor。我尝试为此使用 vec2 属性,只是将 .x 值“伪造”为我的“BOOL”,但看起来 OpenGL 在着色器获取它之前将值从 0.0 标准化为 1.0。因此,即使在我的应用程序中我已将其设置为 0.0,当着色器执行其操作时,该值最终也会达到 1.0。任何建议将不胜感激。

顶点属性代码:

// 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);
    }
}

提前致谢。

4

1 回答 1

9

而是将布尔值创建为glUniform(1.0 或 0.0)。用 设置它的值glUniform1f(GLint location, GLfloat v0)。在着色器中,像这样检查它的值:

if (my_uniform < 0.5) {
    // FALSE
} else {
    // TRUE
}
于 2012-08-11T05:42:25.773 回答