【发布时间】:2016-09-28 13:10:16
【问题描述】:
我挣扎了好几天,但我仍然无法弄清楚我做错了什么。 我有一个由单个浮点数组成的顶点属性,我想在 if 语句中将它的值与其他值进行比较,但即使它不是,我也总是得到该语句; 这是我的顶点着色器出现的问题:
attribute vec4 a_Position;
attribute vec3 a_Normal;
attribute vec2 a_TextureCoord;
attribute highp float a_Bone;
uniform mat4 bone_1;
uniform mat4 bone_0;
varying vec2 v_TextureCoord;
void main() {
v_TextureCoord = a_TextureCoord;
vec4 posy;
float a = a_Bone;
if(20.0<a)
posy = bone_0*a_Position;
else
posy = bone_1*a_Position;
gl_Position = posy;
}
如果我将 if 语句中的内容替换为“true”或“false”,所有事情都按预期工作......但是如果我尝试使用该属性值来比较 if 语句,则该语句始终是即使 a_Bone 值为 1.0 或 2.0(明显小于 20.0),也为 true
【问题讨论】:
-
您能否提供更多信息,例如如何传递统一变量和顶点属性代码?
-
是的......所有顶点属性都存储在一个vbo中......
-
GLES20.glEnableVertexAttribArray(a_bone); GLES20.glVertexAttribPointer(a_bone,1, GLES20.GL_FLOAT, false, stride, (position_count +normal_count+texCoord_count)*bytes_per_float);这样我做数据的传递
-
问题不在于传递数据,因为当我删除 if 语句时它成功呈现,我还尝试用 a_Position.x 替换 if 语句中的 a_Bone 和相同的结果
标签: opengl-es-2.0 vertex-shader