I was trying to apply skinning to a mesh and I used a code sample from the GLTF file format overview (cannot insert link) as help to compute the skinning matrix.
There is something that I dont understand : in the following code, why is the float-to-int cast necessary ?
Here are two versions, with and without cast.
When using the first version, with some float-to-int casts, it works. But with the second code version, using the ivec type for the “joint” attribute, the behaviour is different.
Who says that it is necessary? You can index arrays with floats; the system will convert them to integers.
Well, yeah. Your VS attribute is no longer a float, it’s an integer. Any apparent differences is probably due to how you set up your vertex attributes in OpenGL. Which you didn’t show.
Sorry for not showing all the code, I thought it might not be relevant.
I set up the attributes using the information from a GLTF file (and a library called tinygltf).
You need to use glVertexAttribIPointer (note the extra “I”) for integer attributes. If you use glVertexAttribPointer, the GPU will be instructed to perform integer-to-float conversion on the data, but the shader will be interpreting the values as integers.
Oh I see. I thought wheither glVertexAttribPointer performed conversion to float or not depended on the type parameter. I will try using glVertexAttribIPointer and I will report on the result.
Well, it won’t perform conversion if the type parameter is GL_FLOAT. The result is always float (more precisely, a vec4), the type parameter tells it what it’s converting from.