From b6a42391b084b410abc19b91c75e6f250e2b22d9 Mon Sep 17 00:00:00 2001 From: Popov72 Date: Mon, 7 Nov 2022 14:47:31 +0100 Subject: [PATCH] Update performance section --- .../featuresDeepDive/mesh/bonesSkeletons.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/content/features/featuresDeepDive/mesh/bonesSkeletons.md b/content/features/featuresDeepDive/mesh/bonesSkeletons.md index 54c6b9621..2a4457f89 100644 --- a/content/features/featuresDeepDive/mesh/bonesSkeletons.md +++ b/content/features/featuresDeepDive/mesh/bonesSkeletons.md @@ -397,6 +397,19 @@ poleTarget.setEnabled(false); Bones are computed using shaders by default. This allows better performance. But on low end devices, shaders could be limited and not able to process bones. You can in this case ask Babylon.js to compute bones using CPU by setting `mesh.computeBonesUsingShaders = false`. +Note however that when using instances / thin instances, things can be a bit different: +1. When `computeBonesUsingShaders = true`, the vertex shader code is doing 4 texture reads **PER** vertex **PER** instance **PER** frame. +1. When `computeBonesUsingShaders = false`, there's no texture reads anymore but the vertices are transformed according to their bones on the CPU and the final vertex positions are uploaded to the GPU once **PER** frame. + +As 2 is independent from the number of instances and has a fixed cost (depending on the number of vertices), there’s a point where 2 will be faster than 1, and it will be more and more in favor of 2 with increasing number of instances. + +If you are in a situation where 1 is slower than 2, you can try another option: + +* `mesh.computeBonesUsingShaders = true` +* `mesh.skeleton.useTextureToStoreBoneMatrices = false` + +In this configuration, bones will be applied on the GPU but using a static bone array, there's no texture read involved. So it will probably be faster than 1 but note that this latest configuration will set a limit to the total number of bones a skeleton can have (which depends on the number of uniforms a vertex shader can take). + **Warning**: `mesh.computeBonesUsingShaders = false` is incompatible with morph targets! If you have to use morph targets, you must set `mesh.computeBonesUsingShaders` to `true`! ## Debugging @@ -573,4 +586,4 @@ var skinnedMeshes = meshes.filter(function (mesh) { One of these will be the correct mesh to pass to the bone to get absolute transforms. It is up to the user loading the model to decide which is the correct one. -Note that some engines (e.g., Unity3D) and glTF do not support sharing skeletons between skinned meshes with different transforms because the skinned mesh transforms are ignored in these cases. If nothing is modified after loading from a glTF, any of the filtered list of skinned meshes should work as the skinned mesh argument to a bone method for getting absolute transforms. In this case, selecting the first mesh of this filter works for glTF assets. See [this issue](https://github.com/KhronosGroup/glTF/issues/1285) and linked issues for more detailed analysis of shared skeletons in glTF and [glTF Skinning](/features/featuresDeepDive/importers/glTF/glTFSkinning) for more details about glTF skinning in Babylon.js. \ No newline at end of file +Note that some engines (e.g., Unity3D) and glTF do not support sharing skeletons between skinned meshes with different transforms because the skinned mesh transforms are ignored in these cases. If nothing is modified after loading from a glTF, any of the filtered list of skinned meshes should work as the skinned mesh argument to a bone method for getting absolute transforms. In this case, selecting the first mesh of this filter works for glTF assets. See [this issue](https://github.com/KhronosGroup/glTF/issues/1285) and linked issues for more detailed analysis of shared skeletons in glTF and [glTF Skinning](/features/featuresDeepDive/importers/glTF/glTFSkinning) for more details about glTF skinning in Babylon.js.