Rigging questions

Hello everyone,

First of all, thanks to babylonJS team and contributors for their awesome work !

I have some questions, essentially about rigging limitation for complex rig in BJS. We are currently developing a web-app, and want to use of BABJS.
Our scene will be quite simple, only one character, simple ground, simple environment, simple shaders, not lot of textures, decent amount of vertex. When it comes to BJS for this project it’s about bones/rigging where i have the most trouble to find information.

1/ Number of bones limitation.
a)I read it’s 50, but not quite sure. Is it 50 far all scene ? Is there a per mesh limitation ?
Our web-app must work on most used navigator (chrome, safari, FF, IE). Depending on the use of morph-target or helper bones, i need to know this maximum limitation.

It’s also quite hard for us to understand how much it will impact performance.
b) Did rig performance varies depending on vertex count ? The more vertex, the more calculation for the rig ? Or is heavy rig (assuming max number is 50 bones) will perform the same on very low mesh and medium mesh ?
c) Quite the same question for textures and materials ?

I assume calculation of bone deformation only induce calculation of geometric deformation. Am i right ?

2/ The use of morph-target (blend shapes in maya). We need to make a complex rig, with deformations. The question is “How much we will relay on morph-target”. It clearly depends on performance and we will try to mostly use helper bones (bones that help in the deformation of the model on some positions) but for some extreme poses it won’t be sufficient and morph target must be the way to do it.
So i have some questions about morph-target:
a) Did morph-target could be used on rigged model ? Could rig exported from maya (or blender) with drivers of morph target (ex : for the rotation of this joint apply this morph) is available in BJS thanks to export. (i assume yes but i’m not sure about it)

b) How many morph target per model ? I read that each object is limited to 16 attributes per vertex, on the doc : Use Morph targets - Babylon.js Documentation
“Please be aware that most of the browsers are limited to 16 attributes per mesh. Adding a single morph target to a mesh add up to 4 new attributes (position + normal + tangents + uvs). This could quickly go beyond the max attributes limitation.”

Is a morph target always applied to normal / tangents / uvs when you only want physical deformation ? What happens if you only apply it to vertex position ? Will texture “not be deformed” ? It’s a noob question for sure.

So is it only 4 morph-target per model (if position + normal + tangents + uvs are modified too) ?
I saw some poeple here making facial rigs with more than 4 morph-target. How is it possible ? Will this be supported by most of browsers ?

Thank you for your help.

Hello and welcome! (and thanks for choosing bjs :wink:

  1. There is no absolute limitation. 50 is just to make sure you are not killing the CPU on low end devices. In your case you can have more if your scene is simple. It is more about finding a right balance
    a. Bones are rendered on GPU but they are animated on CPU so this is why you should be cautious not to have 1000 animates bones per scene
    b. Not that much as bones rendering is done on the GPU.
    c. Same. This is independent

Yes. And it is done by vertex shaders

a. Yes. Let me ask @Drigax to confirm
b. You can decide to only morph position (or position+normal) so it will save attributes. If you do not deform uv then texture will be wrong. If you do not deform normals then lighting will be wrong

1 Like

Hello Deltakosh,

For us bjs is the easiest and stronger choice : great community, use of JS, frendly user, open source, fast and light. It’s awesome :slight_smile:

Thank you for you replies.

  1. Ok for the number of bones, great to know, this won’t be a problem for us.

a. Ok thank you, just to be more precise, on maya we use Pose Space Deformation, it links a bone deformation (for exemple rotation) to the use of a morph-target.

Hate to play bad guy, but the 50 only implies that you are not using iOS. I know you did not state that you need iOS, but before you think “let’s run it from there too!”, the max is much lower & the penalties much harder. For Android 50 should not be a problem.

Technically, you could have 50, but you are likely to fall back to CPU skinning. iOS only supports the minimum of vertex shader uniforms, 32 * 4. Each bone world matrix takes 1 * 4. Uniforms are also used for other things too, so you cannot max out at 32 bones.

I go with a Kinect-2 skeleton with the 4 finger bones amputated to get to 21 bones.

Hi @Thibaut, welcome to the forum :grin:

Regarding your rigging questions:
2a) Yes, you can combine morph targets + bone deformation. See: Babylon.js Playground for an example of such a scene.

2b) As DK said, you are limited to an overall of 16 attributes per mesh, this is driven by hardware and WebGL limitations. I’m pretty sure most modern GPUs are limited to 16 attributes per vertex, but I’m not sure how much this limitation has changed in recent years, or with more modern APIs. Unfortunately you’ll have to do some CPU preprocessing/swapping of meshes if you have more shapes than attributes supported: WebGL Report
NVIDIA GeForce RTX 2080 Ti Rev. A performance in GFXBench - unified graphics benchmark based on DXBenchmark (DirectX) and GLBenchmark (OpenGL ES) (search for gl_max_vertex_attribs)

@JCPalmer:
Thank you very much for your answer.
I’m sorry, i did not make myself clear enough.
Our web-app must be used on different platforms such as Android / IOS and non mobile device (which must not be a problem). I wonder why ios do not support webGL2.

So if we plan to be safe on iphone devices 32 bones must be our maximum. For a complete character it’s quite low assuming riging all the fingers together on 3 simple bones, you end quickly to 40 or more.
I assume we will have to make a different “simpler” character for ios.

@Drigax

I’m not sure to understand well.
“i’m pretty sure most modern GPUs are limited to 16 attributes per vertex” : is the limitation per vertex or per mesh ?
Assuming it’s per vertex this would say that one vertex could only be implied in 4 morph target.
But that two different vertex could be attribute each one 4 different morph targets. So assuming each morph target do not share any vertex and are not activated at the same time, a mesh could support more than 4 morph target ?

To make myself clearer, on example :
4 morph target on the biceps driven by elbow flexion.
4 morph target on the calf driven by ankle extension.
No vertex in common.
You can’t use simultaneously the 8 morph-targets, but could be use separately as for example animation of biceps flexion will only imply morph target of biceps and morph-target of ankle will be set to 0.

Could this work ?

iOS can’t use bone matrices in a texture? If bones are put in a texture (the default in Babylon, I think), you only have two uniforms in the vertex shader to handle bones:

	#ifdef BONETEXTURE
		uniform sampler2D boneSampler;
		uniform float boneTextureWidth;
	#else
		uniform mat4 mBones[BonesPerMesh];
	#endif	
1 Like

Just to clarify,

This limitation is per mesh. Morph targets are “copies” of the mesh in different configurations. When you use a morph target for a mesh, even if you don’t move some vertices, both whole meshes sent to the GPU to be morphed between.

If the bicep and ankle are all part of the same mesh, then no, this will not work. The bicep and ankle morph targets would still contain the vertices of the whole body.

If the mesh is split into multiple meshes, then you can have multiple morph targets for each mesh, as they would be streamed, calculated and drawn separately.

My mistake,

Should have read as “I’m pretty sure most modern GPUs are limited to 16 vertex attributes per mesh”

@Drigax No worries, it’s ok, and it’s what i understood first was not just sure.

So my only solution is to divide my model, this is not an issue for us. Will need some reflexion.

Thank you very much for your help, and reactivity ! I really appreciate it !

1 Like

I did not know that this was added to BJS. If it worked there, it would get around the problem. Whether it works in iOS would then be down to if you can have samplers in a vertex shader with WebGL 1. I found nothing which says it was added for WebGL 2.

@Thibaut, you might try an export of your original skeleton on iOS. If you added this statement, you could verify that skinning is still occurring on the GPU on one of the meshes using the skeleton.

Alert('using GPU skinning: ' + mesh.computeBonesUsingShaders);

If you get a True, you would be ok with the 50 bone skeleton.

1 Like

@JCPalmer @Evgeni_Popov

Awesome i will test that ASAP.
Thank you very much for your help !

Ok we tried it and it works !
So finally you can use more than 32 bones on iOS as they will be processed by GPU using texture.

3 Likes