Jump to content

  • Log In with Google      Sign In   
  • Create Account

From GL_UNSIGNED_BYTE to uvec4?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Kwizatz   GDNet+   -  Reputation: 1200

Like
0Likes
Like

Posted 05 September 2012 - 12:14 AM

Hello All,

I am writing some GLSL skeletal animation code, and I am passing the weight information onto the vertex shader as unsigned bytes something like this:


glVertexAttribPointer ( weight_indices, 4, GL_UNSIGNED_BYTE, GL_FALSE, 8 , ( ( char * ) NULL + ( 0 ) ) );



glVertexAttribPointer ( weights, 4, GL_UNSIGNED_BYTE, GL_TRUE, 8 , ( ( char * ) NULL + ( 4 ) ) );

On the shader (I am using #version 140) I catch those like so:


in  uvec4 weight_indices;

in  vec4 weights;



The weights come out right, normalization turns them into a float in the range [0,1] and they add up to 1 or whereabouts, however weight_indices is not getting the values I expect, that being a simple cast from uint8_t to uint32_t.

I think there must be something I am missing, if I read the manual page for glVertexAttribPointer, int values are converted to floats, so there may be some sort of casting issue when the float is cast back to int... but I am just assuming here... any ideas?

Thanks!

Sponsor:

#2 Ashaman73   Crossbones+   -  Reputation: 7517

Like
0Likes
Like

Posted 05 September 2012 - 12:35 AM

This seems ok sofar, I use it in a similar way. Maybe your error interpretation is wrong, why do you think, that the weight indicies are wrong ?

#3 Hodgman   Moderators   -  Reputation: 30388

Like
2Likes
Like

Posted 05 September 2012 - 01:03 AM

Does it work if you change weight_indices to a vec4?

#4 Kwizatz   GDNet+   -  Reputation: 1200

Like
0Likes
Like

Posted 05 September 2012 - 08:31 AM

This seems ok sofar, I use it in a similar way. Maybe your error interpretation is wrong, why do you think, that the weight indicies are wrong ?


I checked the matrix palette by filling it with identity matrices, any constant index I use in the range of my model's joint count does work, weights for a single vertex all add up to 1.0, with surpricing accuracy, but the most obvious thing is that if I check for indices over the range, I get at least one over bounds per index set of 4.

I suspected my mesh file format, but the stored indices and the ones at export time do match and are all in range.

Hodgman: I havent tried that, I will and report back.

#5 Kwizatz   GDNet+   -  Reputation: 1200

Like
0Likes
Like

Posted 05 September 2012 - 09:02 AM

Hodgman: I havent tried that, I will and report back.


Ok, I've done that and it seems to work, all values are within range, though I have to cast the floats to int in the shader, no biggie, thats probably how I will have to do it for OpenGL ES 2, but I am still wondering what's the problem with the uvec4... just changing the varying type back to uvec4 brings back the issue but the exact same values are being passed.

#6 Hodgman   Moderators   -  Reputation: 30388

Like
0Likes
Like

Posted 06 September 2012 - 03:59 AM

Yeah I don't understand... I usually just blame OpenGL for being vague, quirky and/or undefined and move on ;P

I just opened up an old version of the GLSL spec that I had saved and it contains the text: The attribute qualifier can be used only with float, floating-point vectors, and matrices.
...which means that the input-assembler stage of the GPU always decodes the vertex attribute streams to floating point before passing them to the vertex shader.
I'm not sure if this restriction has been relaxed in newer versions of the spec.

#7 Kwizatz   GDNet+   -  Reputation: 1200

Like
0Likes
Like

Posted 06 September 2012 - 09:23 AM

You'd think that with version 130 introducing full integer support, bit shitfting and bitwise operators, this behaviuor would be modified or covered, I guess they just overlooked it which caused it to be undefined at least for 130 and 140.

Anyway, Thanks Hod!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS