• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Windows vertex_ubyte4 not working?

TheSnidr

Heavy metal viking dentist
GMC Elder
I'm making a 3D skeletal animation system that stores four bone indices and four bone weights in each vertex. The bone indices are positive integers, and I'd like to use buffer_ubyte4 for this. But I can't get it to work.

Here's a simple test I made:
Code:
//Initialize vertex format and create a simple shape
vertex_format_begin();
vertex_format_add_position_3d();
vertex_format_add_custom(vertex_type_ubyte4, vertex_usage_colour);
format = vertex_format_end();

vBuff = vertex_create_buffer();
vertex_begin(vBuff, format);
vertex_position_3d(vBuff, 0, 0, 0);
vertex_ubyte4(vBuff, random(256), random(256), random(256), 255);
vertex_position_3d(vBuff, 200, 0, 0);
vertex_ubyte4(vBuff, random(256), random(256), random(256), 255);
vertex_position_3d(vBuff, 0, 200, 0);
vertex_ubyte4(vBuff, random(256), random(256), random(256), 255);
vertex_position_3d(vBuff, 200, 200, 0);
vertex_ubyte4(vBuff, random(256), random(256), random(256), 255);
vertex_end(vBuff);
When drawing this with a custom shader, all indices in in_Colour will be 0. Why is this? Am I doing something wrong or does it just not work? I get it to work if I use buffer_float4 instead, but that is very wasteful...
 
Last edited:
T

T-bond

Guest
Try it with irandom instead of random, maybe there is some bug with the parameter conversion.
 

TheSnidr

Heavy metal viking dentist
GMC Elder
You've got a keen eye, T-bond, but unfortunately that doesn't fix anything!
 

Bart

WiseBart
From my testing, I've also found vertex_type_ubyte4 not to work (after changing type and usage in all kinds of ways).
But the colour (vertex_format_add_color()) is actually already stored as a 4-byte value in the vertex buffer.
(After converting to a buffer, the size using either color or ubyte4 types ended up at 64 bytes, while the size using float4 type ended up at 112)

So you might want to use the colour attribute to store the bone indices to keep a small vertex buffer size. That is, if you can do without the colour in the fragment shader.

Inside the shader, you might need to multiply the received values of in_Colour by 255 and convert them to ints to get the correct array indices, not sure about that part though...

EDIT: it seems like you can add multiple colour attributes using vertex_format_add_color() as a workaround.
Here's an example: https://db.tt/cviAJUW4gV
 
Last edited:

TheSnidr

Heavy metal viking dentist
GMC Elder
Thanks Bart, that's a nice workaround! It'll make do for me, but I'd still like to know whether or not the feature just is non-functional at the moment. If so, it should at the very least be mentioned in the manual, like buffer_f16 is.
 

GMWolf

aka fel666
Thanks Bart, that's a nice workaround! It'll make do for me, but I'd still like to know whether or not the feature just is non-functional at the moment. If so, it should at the very least be mentioned in the manual, like buffer_f16 is.
It should be working, but when I asked Mike about it, he mentioned he mostly used vec4 himself.
I'm not sure if its an issue with GM specifically, but it seems like binding attributes in shaders is a very fiddly thing.
 
M

Multimagyar

Guest
"working" I tried to use it for the same purpose when I worked on my setup I had the same problem. I don't think it works at all. Not with DX9 DX11 or opengl shaders. It kind of annoys me. I just simply used a float4 for it as texcoord. Mostly because I also got the fear of vertex_usage_blendindices not even working when I was building it. I would do like to see an input on this ubyte4 case. (the colour thing sounds nice I might convert my code too to that as well.)
 
Top