tab*_*ber 2 iphone opengl-es fragment-shader ios opengl-es-2.0
我是OpenGL ES 2.0的新手,所以请耐心等待...我想将BOOL标志传递到我的片段着色器中,以便在我的应用程序中发生某个触摸事件后,它会以不同的方式呈现gl_FragColor.我尝试使用vec2属性并将"伪造".x值作为我的"BOOL",但看起来OpenGL在着色器获得它之前将值从0.0归一化到1.0.所以即使在我的应用程序中我将它设置为0.0,而着色器正在做它的事情,该值最终将达到1.0.任何建议都将非常感激.
VertexAttrib代码:
// 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);
Run Code Online (Sandbox Code Playgroud)
当前顶点着色器代码:
...
attribute vec2 inputBrushMode;
varying highp float brushMode;
void main()
{
gl_Position = position;
...
brushMode = inputBrushMode.x;
}
Run Code Online (Sandbox Code Playgroud)
当前片段着色器代码:
...
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);
}
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.
将bool创建为glUniform
(1.0或0.0).设置其值glUniform1f(GLint location, GLfloat v0)
.在着色器中,检查其值如下:
if (my_uniform < 0.5) {
// FALSE
} else {
// TRUE
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7405 次 |
最近记录: |