【问题标题】:Problems with using vertex attribute value in opengl es 2.0在opengl es 2.0中使用顶点属性值的问题
【发布时间】: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


【解决方案1】:

我们一直在 if 语句中使用Attributes,并且代码在大多数 OpenGL ES 2.0 设备上运行良好。所以使用属性不是问题。这是我们如何完成的工作代码。

int jointId = int(optionalData1.x);
if(jointId > 0)
    finalMatrix = jointTransforms[jointId - 1] * optionalData2.x;

此代码在所有 iOS 和 Android 设备上运行良好。 optionalData1 是属性,我们甚至使用此值从统一数组中获取矩阵以用于骨骼变换矩阵。

【讨论】:

  • 感谢您的回答,但我尝试过没有成功...我还在多个设备(三​​星、HTC)和多个 android 版本 4.4、5.1、6.0 上进行了测试...没有成功跨度>
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-05-27
  • 1970-01-01
  • 1970-01-01
  • 2016-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多