Vert attributes

trying to make a skinning shader in GLSL, now with my bone index’s are turning out to be a problem.

i cant have int as an attribute.
eg. attribute int boneIdx[4];

so if i send them up as floats
attribute vec4 boneIdx; this works okay.
then the problem become not being able to convert a float to an int!

is there a simple solution to this problem?

Originally posted by supagu:
is there a simple solution to this problem?
ivec4(boneIdx)

or attribute ivec4 boneIdx;

You can’t declare integer typed attributes. From the spec:

The attribute qualifier can be used only with the data types float, vec2, vec3, vec4, mat2, mat3, and mat4.
Attribute variables cannot be declared as arrays or structures.
But…you actually can with the NVIDIA compiler. It allows integer attributes, obviously because it is allowed (?) in Cg. Unfortunately, it doesn’t work anywhere else. And most unfortunately, the low-level code generated when having float attributes and using casts, is considerabely worse than when you just use integer ones. Strange, but may be fixed in the future.

Can’t you just do the conversion (which is almost certainly a no-op on most hardware) when you index the array?

cant cast from float to int in GLSL :-/

so an ivec4 is a vector of ints im assuming :smiley:

okay just tried ivec4

“attribute ivec4 bone;”

and the error:

ERROR: 0:5: ‘attribute’ : cannot be bool or int

:’(

Originally posted by supagu:
cant cast from float to int in GLSL :-/
Of course you can. Just do the cast when indexing the bones array:

bones[int(boneIdx.x)];

Or create a new ivec4 by casting the vec4 and then use the ivec4’s components immediately:

ivec4 indices = ivec4(boneIdx);
bones[indices.x];

Originally posted by supagu:
ERROR: 0:5: ‘attribute’ : cannot be bool or int
It’s an error, as it is not allowed by the spec (see previous post).

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.