Hi all,
I have written a shader for vertex blending and met a nettlesome problem.
I try to use the the following code to send my bone data array into shader, pData is a array of “unsigned char bone[4]” for each vertex.
GLint index = glGetAttribLocationARB(progObj, "bone");
ASSERT(index != -1);
glVertexAttribPointerARB(index, 4, GL_UNSIGNED_BYTE, GL_FALSE, 0, pData);
glEnableVertexAttribArrayARB(index);
And below is the vertex blend shader:
// Vertex Shader Code
attribute vec4 bone;
attribute vec4 weight;
uniform mat4 boneMatrices[30];
const float fw = 1.0 / 255.0;
void main()
{
vec4 blendVertex;
vec4 blendWeight = weight;
vec4 blendBone = bone;
vec4 eclr = gl_Color;
for(int i = 0; i < 4; i++)
{
if(blendWeight.x > 0.0)
{
int b = int(blendBone.x);
if(b > 10)
{
eclr = vec4(1.0, 0.0, 0.0, 1.0);
}
else
{
blendVertex += curweight.x * fw * vec4((boneMatrices[b] * gl_Vertex).xyz, 1.0);
}
blendBone = blendBone.yzwx;
blendWeight = blendWeight.yzwx;
}
else break;
}
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
gl_FrontColor = eclr;
}
The problem is, I found the “blendBone” data in the shader is wrong, because the bone data value should not be greater than 10 according to the pData I sent.Believe me, I check it very carefully.
So is there any error in the code to send the GL_UNSIGNED_BYTE[4] data into vec4 shader variable? or is there any other context settings can affect the data sending/converting?
Env: NVidia Geforce 6200, Driver Version:81.85
Any tip would be appreciated.