Enable CPU/GPU animation switching on a CustomShader

This is kinda a extension of a prior conversation where @Evgeni_Popov helped me enable the ability to toggle this on Meshs using the Standard and PBR material. Seems like when the mesh uses a custom material though the fallback does not exists.

it looks like there is a “addCPUSkinningFallback” but Im not sure how to initiate fallback on a ShaderMat.

It does work in my testings: maybe you can provide a PG so that we can have a look?

This functionality is orthogonal to materials, so it should work on the CPU/GPU whatever the material you use (with a shader material, you need to use the right #includes in the vertex shader to support skinned meshes).

https://playground.babylonjs.com/#BCU1XR#1532

Then go into the inspector and toggle the the Mixaorig:skin image

I get what you are saying now.
Because the defines say Bone Influences 0 it skips the attributes I need. gotcha. took a second to sink in.

You should not add '#define NUM_BONE_INFLUENCERS 4', to the list of defines of the shader material, it will be automatically added as '#define NUM_BONE_INFLUENCERS 4' or '#define NUM_BONE_INFLUENCERS 0' depending on the computeBonesUsingShaders value.

What if I need to trick it?

How so? I don’t understand what you want to achieve.

To make your sample work in both CPU and GPU mode, you simply need to remove the '#define NUM_BONE_INFLUENCERS 4' line:

https://playground.babylonjs.com/#BCU1XR#1536

1 Like

Hmmmm… Im a goober I guess… my bad.